##// END OF EJS Templates
use momentjs for nice dates
Matthias BUSSONNIER -
Show More
@@ -1,1 +1,1 b''
1 Subproject commit a80ac7a2f6d045e3903d3c9e189a10cc96255b05
1 Subproject commit b3909af1b61ca7a412481759fdb441ecdfb3ab66
@@ -7,7 +7,8 b' define(['
7 7 'base/js/utils',
8 8 'notebook/js/tour',
9 9 'bootstrap',
10 ], function(IPython, $, utils, tour) {
10 'moment',
11 ], function(IPython, $, utils, tour, bootstrap, moment) {
11 12 "use strict";
12 13
13 14 var MenuBar = function (selector, options) {
@@ -335,7 +336,7 b' define(['
335 336 $("<li/>").append(
336 337 $("<a/>")
337 338 .attr("href", "#")
338 .text(d.format("mmm dd HH:MM:ss"))
339 .text(moment(d).format("LLLL"))
339 340 .click(function () {
340 341 that.notebook.restore_checkpoint_dialog(checkpoint);
341 342 })
@@ -7,7 +7,8 b' define(['
7 7 'base/js/utils',
8 8 'base/js/dialog',
9 9 'notebook/js/notificationwidget',
10 ], function(IPython, $, utils, dialog, notificationwidget) {
10 'moment'
11 ], function(IPython, $, utils, dialog, notificationwidget, moment) {
11 12 "use strict";
12 13
13 14 var NotificationArea = function (selector, options) {
@@ -208,7 +209,7 b' define(['
208 209 var msg = "Checkpoint created";
209 210 if (data.last_modified) {
210 211 var d = new Date(data.last_modified);
211 msg = msg + ": " + d.format("HH:MM:ss");
212 msg = msg + ": " + moment(d).format("HH:mm:ss");
212 213 }
213 214 nnw.set_message(msg, 2000);
214 215 });
@@ -7,8 +7,8 b' define(['
7 7 'base/js/utils',
8 8 'base/js/dialog',
9 9 'base/js/keyboard',
10 'dateformat',
11 ], function(IPython, $, utils, dialog, keyboard, dateformat) {
10 'moment',
11 ], function(IPython, $, utils, dialog, keyboard, moment) {
12 12 "use strict";
13 13
14 14 var SaveWidget = function (selector, options) {
@@ -16,6 +16,7 b' define(['
16 16 this.notebook = undefined;
17 17 this.selector = selector;
18 18 this.events = options.events;
19 this._checkpoint_date = undefined;
19 20 this.keyboard_manager = options.keyboard_manager;
20 21 if (this.selector !== undefined) {
21 22 this.element = $(selector);
@@ -51,11 +52,11 b' define(['
51 52 that.set_save_status('Autosave Failed!');
52 53 });
53 54 this.events.on('checkpoints_listed.Notebook', function (event, data) {
54 that.set_last_checkpoint(data[0]);
55 that._set_last_checkpoint(data[0]);
55 56 });
56 57
57 58 this.events.on('checkpoint_created.Notebook', function (event, data) {
58 that.set_last_checkpoint(data);
59 that._set_last_checkpoint(data);
59 60 });
60 61 this.events.on('set_dirty.Notebook', function (event, data) {
61 62 that.set_autosaved(data.value);
@@ -123,7 +124,7 b' define(['
123 124 var nbname = this.notebook.get_notebook_name();
124 125 document.title = nbname;
125 126 };
126
127
127 128 SaveWidget.prototype.update_address_bar = function(){
128 129 var base_url = this.notebook.base_url;
129 130 var nbname = this.notebook.notebook_name;
@@ -142,19 +143,87 b' define(['
142 143 this.element.find('span#autosave_status').text(msg);
143 144 };
144 145
145 SaveWidget.prototype.set_checkpoint_status = function (msg) {
146 this.element.find('span#checkpoint_status').text(msg);
146 SaveWidget.prototype._set_checkpoint_status = function (human_date, iso_date) {
147 var el = this.element.find('span#checkpoint_status')
148 if(human_date){
149 el.text("Last Checkpoint: "+human_date).attr('title',iso_date);
150 } else {
151 el.text('').attr('title','no-checkpoint')
152 }
147 153 };
148 154
149 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
150 if (!checkpoint) {
151 this.set_checkpoint_status("");
155 // compute (roughly) the remaining time in millisecond until the next
156 // moment.js relative time update of the string, which by default
157 // happend at
158 // (a few seconds ago)
159 // - 45sec,
160 // (a minute ago)
161 // - 90sec,
162 // ( x minutes ago)
163 // - then every minutes until
164 // - 45 min,
165 // (an hour ago)
166 // - 1h45,
167 // (x hours ago )
168 // - then every hours
169 // - 22 hours ago
170 var _next_timeago_update = function(deltatime_ms){
171 var s = 1000;
172 var m = 60*s;
173 var h = 60*m;
174
175 var mtt = moment.relativeTimeThreshold;
176
177 if(deltatime_ms < mtt.s*s){
178 return mtt.s*s-deltatime_ms;
179 } else if (deltatime_ms < (mtt.s*s+m)) {
180 return (mtt.s*s+m)-deltatime_ms;
181 } else if (deltatime_ms < mtt.m*m){
182 return m;
183 } else if (deltatime_ms < (mtt.m*m+h)){
184 return (mtt.m*m+h)-deltatime_ms;
185 } else {
186 return h;
187 }
188
189
190 }
191
192 SaveWidget.prototype._regularly_update_checkpoint_date = function(){
193 if (!this._checkpoint_date) {
194 this.set_checkpoint_status(null);
195 console.log('no checkpoint done');
152 196 return;
153 197 }
154 var d = new Date(checkpoint.last_modified);
155 this.set_checkpoint_status(
156 "Last Checkpoint: " + dateformat(d,'mmm dd HH:MM')
157 );
198 var chkd = moment(this._checkpoint_date);
199 var longdate = chkd.format('llll');
200
201 var that = this;
202 var recall = function(t){
203 // recall slightly later (1s) as long timeout in js might be imprecise,
204 // and you want to be call **after** the change of formatting should happend.
205 return setTimeout($.proxy(that._regularly_update_checkpoint_date, that),(t+1000))
206 }
207 var tdelta = Math.ceil(new Date()-this._checkpoint_date);
208
209 // update regularly for the first 6hours and show
210 // <x time> ago
211 if(tdelta < tdelta < 6*3600*1000){
212 recall(_next_timeago_update(tdelta));
213 this._set_checkpoint_status( chkd.fromNow(), longdate);
214 // otherwise update every hour and show
215 // <Today | yesterday|...> at hh,mm,ss
216 } else {
217 recall(1*3600*1000)
218 this._set_checkpoint_status( chkd.calendar(), longdate);
219 }
220
221 }
222
223 SaveWidget.prototype._set_last_checkpoint = function (checkpoint) {
224 this._checkpoint_date = new Date(checkpoint.last_modified);
225 this._regularly_update_checkpoint_date();
226
158 227 };
159 228
160 229 SaveWidget.prototype.set_autosaved = function (dirty) {
@@ -31,4 +31,4 b' span#checkpoint_status, span#autosave_status {'
31 31 }
32 32 }
33 33
34 No newline at end of file
34
@@ -28,6 +28,7 b''
28 28 dateformat: 'dateformat/date.format',
29 29 jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min',
30 30 highlight: 'components/highlight.js/build/highlight.pack',
31 moment: "components/moment/moment",
31 32 },
32 33 shim: {
33 34 underscore: {
@@ -160,6 +160,8 b' def find_package_data():'
160 160 pjoin(components, "marked", "lib", "marked.js"),
161 161 pjoin(components, "requirejs", "require.js"),
162 162 pjoin(components, "underscore", "underscore-min.js"),
163 pjoin(components, "moment", "moment.js"),
164 pjoin(components, "moment", "min","moment.min.js"),
163 165 ])
164 166
165 167 # Ship all of Codemirror's CSS and JS
General Comments 0
You need to be logged in to leave comments. Login now