Show More
@@ -1,1 +1,1 b'' | |||||
1 | Subproject commit a80ac7a2f6d045e3903d3c9e189a10cc96255b05 |
|
1 | Subproject commit b3909af1b61ca7a412481759fdb441ecdfb3ab66 |
@@ -7,7 +7,8 b' define([' | |||||
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'notebook/js/tour', |
|
8 | 'notebook/js/tour', | |
9 | 'bootstrap', |
|
9 | 'bootstrap', | |
10 | ], function(IPython, $, utils, tour) { |
|
10 | 'moment', | |
|
11 | ], function(IPython, $, utils, tour, bootstrap, moment) { | |||
11 | "use strict"; |
|
12 | "use strict"; | |
12 |
|
13 | |||
13 | var MenuBar = function (selector, options) { |
|
14 | var MenuBar = function (selector, options) { | |
@@ -335,7 +336,7 b' define([' | |||||
335 | $("<li/>").append( |
|
336 | $("<li/>").append( | |
336 | $("<a/>") |
|
337 | $("<a/>") | |
337 | .attr("href", "#") |
|
338 | .attr("href", "#") | |
338 |
.text(d.format(" |
|
339 | .text(moment(d).format("LLLL")) | |
339 | .click(function () { |
|
340 | .click(function () { | |
340 | that.notebook.restore_checkpoint_dialog(checkpoint); |
|
341 | that.notebook.restore_checkpoint_dialog(checkpoint); | |
341 | }) |
|
342 | }) |
@@ -7,7 +7,8 b' define([' | |||||
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'base/js/dialog', |
|
8 | 'base/js/dialog', | |
9 | 'notebook/js/notificationwidget', |
|
9 | 'notebook/js/notificationwidget', | |
10 | ], function(IPython, $, utils, dialog, notificationwidget) { |
|
10 | 'moment' | |
|
11 | ], function(IPython, $, utils, dialog, notificationwidget, moment) { | |||
11 | "use strict"; |
|
12 | "use strict"; | |
12 |
|
13 | |||
13 | var NotificationArea = function (selector, options) { |
|
14 | var NotificationArea = function (selector, options) { | |
@@ -208,7 +209,7 b' define([' | |||||
208 | var msg = "Checkpoint created"; |
|
209 | var msg = "Checkpoint created"; | |
209 | if (data.last_modified) { |
|
210 | if (data.last_modified) { | |
210 | var d = new Date(data.last_modified); |
|
211 | var d = new Date(data.last_modified); | |
211 |
msg = msg + ": " + d.format("HH: |
|
212 | msg = msg + ": " + moment(d).format("HH:mm:ss"); | |
212 | } |
|
213 | } | |
213 | nnw.set_message(msg, 2000); |
|
214 | nnw.set_message(msg, 2000); | |
214 | }); |
|
215 | }); |
@@ -7,8 +7,8 b' define([' | |||||
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'base/js/dialog', |
|
8 | 'base/js/dialog', | |
9 | 'base/js/keyboard', |
|
9 | 'base/js/keyboard', | |
10 |
' |
|
10 | 'moment', | |
11 |
], function(IPython, $, utils, dialog, keyboard, |
|
11 | ], function(IPython, $, utils, dialog, keyboard, moment) { | |
12 | "use strict"; |
|
12 | "use strict"; | |
13 |
|
13 | |||
14 | var SaveWidget = function (selector, options) { |
|
14 | var SaveWidget = function (selector, options) { | |
@@ -16,6 +16,7 b' define([' | |||||
16 | this.notebook = undefined; |
|
16 | this.notebook = undefined; | |
17 | this.selector = selector; |
|
17 | this.selector = selector; | |
18 | this.events = options.events; |
|
18 | this.events = options.events; | |
|
19 | this._checkpoint_date = undefined; | |||
19 | this.keyboard_manager = options.keyboard_manager; |
|
20 | this.keyboard_manager = options.keyboard_manager; | |
20 | if (this.selector !== undefined) { |
|
21 | if (this.selector !== undefined) { | |
21 | this.element = $(selector); |
|
22 | this.element = $(selector); | |
@@ -51,11 +52,11 b' define([' | |||||
51 | that.set_save_status('Autosave Failed!'); |
|
52 | that.set_save_status('Autosave Failed!'); | |
52 | }); |
|
53 | }); | |
53 | this.events.on('checkpoints_listed.Notebook', function (event, data) { |
|
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 | this.events.on('checkpoint_created.Notebook', function (event, data) { |
|
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 | this.events.on('set_dirty.Notebook', function (event, data) { |
|
61 | this.events.on('set_dirty.Notebook', function (event, data) { | |
61 | that.set_autosaved(data.value); |
|
62 | that.set_autosaved(data.value); | |
@@ -123,7 +124,7 b' define([' | |||||
123 | var nbname = this.notebook.get_notebook_name(); |
|
124 | var nbname = this.notebook.get_notebook_name(); | |
124 | document.title = nbname; |
|
125 | document.title = nbname; | |
125 | }; |
|
126 | }; | |
126 |
|
127 | |||
127 | SaveWidget.prototype.update_address_bar = function(){ |
|
128 | SaveWidget.prototype.update_address_bar = function(){ | |
128 | var base_url = this.notebook.base_url; |
|
129 | var base_url = this.notebook.base_url; | |
129 | var nbname = this.notebook.notebook_name; |
|
130 | var nbname = this.notebook.notebook_name; | |
@@ -142,19 +143,87 b' define([' | |||||
142 | this.element.find('span#autosave_status').text(msg); |
|
143 | this.element.find('span#autosave_status').text(msg); | |
143 | }; |
|
144 | }; | |
144 |
|
145 | |||
145 |
SaveWidget.prototype.set_checkpoint_status = function ( |
|
146 | SaveWidget.prototype._set_checkpoint_status = function (human_date, iso_date) { | |
146 |
this.element.find('span#checkpoint_status') |
|
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) { |
|
155 | // compute (roughly) the remaining time in millisecond until the next | |
150 | if (!checkpoint) { |
|
156 | // moment.js relative time update of the string, which by default | |
151 | this.set_checkpoint_status(""); |
|
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 | return; |
|
196 | return; | |
153 | } |
|
197 | } | |
154 |
var d = |
|
198 | var chkd = moment(this._checkpoint_date); | |
155 | this.set_checkpoint_status( |
|
199 | var longdate = chkd.format('llll'); | |
156 | "Last Checkpoint: " + dateformat(d,'mmm dd HH:MM') |
|
200 | ||
157 | ); |
|
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 | SaveWidget.prototype.set_autosaved = function (dirty) { |
|
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 | dateformat: 'dateformat/date.format', |
|
28 | dateformat: 'dateformat/date.format', | |
29 | jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min', |
|
29 | jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min', | |
30 | highlight: 'components/highlight.js/build/highlight.pack', |
|
30 | highlight: 'components/highlight.js/build/highlight.pack', | |
|
31 | moment: "components/moment/moment", | |||
31 | }, |
|
32 | }, | |
32 | shim: { |
|
33 | shim: { | |
33 | underscore: { |
|
34 | underscore: { |
@@ -160,6 +160,8 b' def find_package_data():' | |||||
160 | pjoin(components, "marked", "lib", "marked.js"), |
|
160 | pjoin(components, "marked", "lib", "marked.js"), | |
161 | pjoin(components, "requirejs", "require.js"), |
|
161 | pjoin(components, "requirejs", "require.js"), | |
162 | pjoin(components, "underscore", "underscore-min.js"), |
|
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 | # Ship all of Codemirror's CSS and JS |
|
167 | # Ship all of Codemirror's CSS and JS |
General Comments 0
You need to be logged in to leave comments.
Login now