##// END OF EJS Templates
Increased notification message display time.
Nathan Heijermans -
Show More
@@ -1,325 +1,325 b''
1 define([
1 define([
2 'base/js/namespace',
2 'base/js/namespace',
3 'jquery',
3 'jquery',
4 'base/js/utils',
4 'base/js/utils',
5 'base/js/dialog',
5 'base/js/dialog',
6 'base/js/notificationarea',
6 'base/js/notificationarea',
7 'moment'
7 'moment'
8 ], function(IPython, $, utils, dialog, notificationarea, moment) {
8 ], function(IPython, $, utils, dialog, notificationarea, moment) {
9 "use strict";
9 "use strict";
10 var NotificationArea = notificationarea.NotificationArea;
10 var NotificationArea = notificationarea.NotificationArea;
11
11
12 var NotebookNotificationArea = function(selector, options) {
12 var NotebookNotificationArea = function(selector, options) {
13 NotificationArea.apply(this, [selector, options]);
13 NotificationArea.apply(this, [selector, options]);
14 this.save_widget = options.save_widget;
14 this.save_widget = options.save_widget;
15 this.notebook = options.notebook;
15 this.notebook = options.notebook;
16 this.keyboard_manager = options.keyboard_manager;
16 this.keyboard_manager = options.keyboard_manager;
17 }
17 }
18
18
19 NotebookNotificationArea.prototype = Object.create(NotificationArea.prototype);
19 NotebookNotificationArea.prototype = Object.create(NotificationArea.prototype);
20
20
21 /**
21 /**
22 * Initialize the default set of notification widgets.
22 * Initialize the default set of notification widgets.
23 *
23 *
24 * @method init_notification_widgets
24 * @method init_notification_widgets
25 */
25 */
26 NotebookNotificationArea.prototype.init_notification_widgets = function () {
26 NotebookNotificationArea.prototype.init_notification_widgets = function () {
27 this.init_kernel_notification_widget();
27 this.init_kernel_notification_widget();
28 this.init_notebook_notification_widget();
28 this.init_notebook_notification_widget();
29 };
29 };
30
30
31 /**
31 /**
32 * Initialize the notification widget for kernel status messages.
32 * Initialize the notification widget for kernel status messages.
33 *
33 *
34 * @method init_kernel_notification_widget
34 * @method init_kernel_notification_widget
35 */
35 */
36 NotebookNotificationArea.prototype.init_kernel_notification_widget = function () {
36 NotebookNotificationArea.prototype.init_kernel_notification_widget = function () {
37 var that = this;
37 var that = this;
38 var knw = this.new_notification_widget('kernel');
38 var knw = this.new_notification_widget('kernel');
39 var $kernel_ind_icon = $("#kernel_indicator_icon");
39 var $kernel_ind_icon = $("#kernel_indicator_icon");
40 var $modal_ind_icon = $("#modal_indicator_icon");
40 var $modal_ind_icon = $("#modal_indicator_icon");
41
41
42 // Command/Edit mode
42 // Command/Edit mode
43 this.events.on('edit_mode.Notebook', function () {
43 this.events.on('edit_mode.Notebook', function () {
44 that.save_widget.update_document_title();
44 that.save_widget.update_document_title();
45 $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
45 $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
46 });
46 });
47
47
48 this.events.on('command_mode.Notebook', function () {
48 this.events.on('command_mode.Notebook', function () {
49 that.save_widget.update_document_title();
49 that.save_widget.update_document_title();
50 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
50 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
51 });
51 });
52
52
53 // Implicitly start off in Command mode, switching to Edit mode will trigger event
53 // Implicitly start off in Command mode, switching to Edit mode will trigger event
54 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
54 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
55
55
56 // Kernel events
56 // Kernel events
57
57
58 // this can be either kernel_created.Kernel or kernel_created.Session
58 // this can be either kernel_created.Kernel or kernel_created.Session
59 this.events.on('kernel_created.Kernel kernel_created.Session', function () {
59 this.events.on('kernel_created.Kernel kernel_created.Session', function () {
60 knw.info("Kernel Created", 500);
60 knw.info("Kernel Created", 500);
61 });
61 });
62
62
63 this.events.on('kernel_reconnecting.Kernel', function () {
63 this.events.on('kernel_reconnecting.Kernel', function () {
64 knw.warning("Connecting to kernel");
64 knw.warning("Connecting to kernel");
65 });
65 });
66
66
67 this.events.on('kernel_connection_dead.Kernel', function (evt, info) {
67 this.events.on('kernel_connection_dead.Kernel', function (evt, info) {
68 knw.danger("Not Connected", undefined, function () {
68 knw.danger("Not Connected", undefined, function () {
69 // schedule reconnect a short time in the future, don't reconnect immediately
69 // schedule reconnect a short time in the future, don't reconnect immediately
70 setTimeout($.proxy(info.kernel.reconnect, info.kernel), 500);
70 setTimeout($.proxy(info.kernel.reconnect, info.kernel), 500);
71 }, {title: 'click to reconnect'});
71 }, {title: 'click to reconnect'});
72 });
72 });
73
73
74 this.events.on('kernel_connected.Kernel', function () {
74 this.events.on('kernel_connected.Kernel', function () {
75 knw.info("Connected", 500);
75 knw.info("Connected", 500);
76 });
76 });
77
77
78 this.events.on('kernel_restarting.Kernel', function () {
78 this.events.on('kernel_restarting.Kernel', function () {
79 that.save_widget.update_document_title();
79 that.save_widget.update_document_title();
80 knw.set_message("Restarting kernel", 2000);
80 knw.set_message("Restarting kernel", 2000);
81 });
81 });
82
82
83 this.events.on('kernel_autorestarting.Kernel', function (evt, info) {
83 this.events.on('kernel_autorestarting.Kernel', function (evt, info) {
84 // Only show the dialog on the first restart attempt. This
84 // Only show the dialog on the first restart attempt. This
85 // number gets tracked by the `Kernel` object and passed
85 // number gets tracked by the `Kernel` object and passed
86 // along here, because we don't want to show the user 5
86 // along here, because we don't want to show the user 5
87 // dialogs saying the same thing (which is the number of
87 // dialogs saying the same thing (which is the number of
88 // times it tries restarting).
88 // times it tries restarting).
89 if (info.attempt === 1) {
89 if (info.attempt === 1) {
90
90
91 dialog.kernel_modal({
91 dialog.kernel_modal({
92 notebook: that.notebook,
92 notebook: that.notebook,
93 keyboard_manager: that.keyboard_manager,
93 keyboard_manager: that.keyboard_manager,
94 title: "Kernel Restarting",
94 title: "Kernel Restarting",
95 body: "The kernel appears to have died. It will restart automatically.",
95 body: "The kernel appears to have died. It will restart automatically.",
96 buttons: {
96 buttons: {
97 OK : {
97 OK : {
98 class : "btn-primary"
98 class : "btn-primary"
99 }
99 }
100 }
100 }
101 });
101 });
102 };
102 };
103
103
104 that.save_widget.update_document_title();
104 that.save_widget.update_document_title();
105 knw.danger("Dead kernel");
105 knw.danger("Dead kernel");
106 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
106 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
107 });
107 });
108
108
109 this.events.on('kernel_interrupting.Kernel', function () {
109 this.events.on('kernel_interrupting.Kernel', function () {
110 knw.set_message("Interrupting kernel", 2000);
110 knw.set_message("Interrupting kernel", 2000);
111 });
111 });
112
112
113 this.events.on('kernel_disconnected.Kernel', function () {
113 this.events.on('kernel_disconnected.Kernel', function () {
114 $kernel_ind_icon
114 $kernel_ind_icon
115 .attr('class', 'kernel_disconnected_icon')
115 .attr('class', 'kernel_disconnected_icon')
116 .attr('title', 'No Connection to Kernel');
116 .attr('title', 'No Connection to Kernel');
117 });
117 });
118
118
119 this.events.on('kernel_connection_failed.Kernel', function (evt, info) {
119 this.events.on('kernel_connection_failed.Kernel', function (evt, info) {
120 // only show the dialog if this is the first failed
120 // only show the dialog if this is the first failed
121 // connect attempt, because the kernel will continue
121 // connect attempt, because the kernel will continue
122 // trying to reconnect and we don't want to spam the user
122 // trying to reconnect and we don't want to spam the user
123 // with messages
123 // with messages
124 if (info.attempt === 1) {
124 if (info.attempt === 1) {
125
125
126 var msg = "A connection to the notebook server could not be established." +
126 var msg = "A connection to the notebook server could not be established." +
127 " The notebook will continue trying to reconnect, but" +
127 " The notebook will continue trying to reconnect, but" +
128 " until it does, you will NOT be able to run code. Check your" +
128 " until it does, you will NOT be able to run code. Check your" +
129 " network connection or notebook server configuration.";
129 " network connection or notebook server configuration.";
130
130
131 dialog.kernel_modal({
131 dialog.kernel_modal({
132 title: "Connection failed",
132 title: "Connection failed",
133 body: msg,
133 body: msg,
134 keyboard_manager: that.keyboard_manager,
134 keyboard_manager: that.keyboard_manager,
135 notebook: that.notebook,
135 notebook: that.notebook,
136 buttons : {
136 buttons : {
137 "OK": {}
137 "OK": {}
138 }
138 }
139 });
139 });
140 }
140 }
141 });
141 });
142
142
143 this.events.on('kernel_killed.Kernel kernel_killed.Session', function () {
143 this.events.on('kernel_killed.Kernel kernel_killed.Session', function () {
144 that.save_widget.update_document_title();
144 that.save_widget.update_document_title();
145 knw.danger("Dead kernel");
145 knw.danger("Dead kernel");
146 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
146 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
147 });
147 });
148
148
149 this.events.on('kernel_dead.Kernel', function () {
149 this.events.on('kernel_dead.Kernel', function () {
150
150
151 var showMsg = function () {
151 var showMsg = function () {
152
152
153 var msg = 'The kernel has died, and the automatic restart has failed.' +
153 var msg = 'The kernel has died, and the automatic restart has failed.' +
154 ' It is possible the kernel cannot be restarted.' +
154 ' It is possible the kernel cannot be restarted.' +
155 ' If you are not able to restart the kernel, you will still be able to save' +
155 ' If you are not able to restart the kernel, you will still be able to save' +
156 ' the notebook, but running code will no longer work until the notebook' +
156 ' the notebook, but running code will no longer work until the notebook' +
157 ' is reopened.';
157 ' is reopened.';
158
158
159 dialog.kernel_modal({
159 dialog.kernel_modal({
160 title: "Dead kernel",
160 title: "Dead kernel",
161 body : msg,
161 body : msg,
162 keyboard_manager: that.keyboard_manager,
162 keyboard_manager: that.keyboard_manager,
163 notebook: that.notebook,
163 notebook: that.notebook,
164 buttons : {
164 buttons : {
165 "Manual Restart": {
165 "Manual Restart": {
166 class: "btn-danger",
166 class: "btn-danger",
167 click: function () {
167 click: function () {
168 that.notebook.start_session();
168 that.notebook.start_session();
169 }
169 }
170 },
170 },
171 "Don't restart": {}
171 "Don't restart": {}
172 }
172 }
173 });
173 });
174
174
175 return false;
175 return false;
176 };
176 };
177
177
178 that.save_widget.update_document_title();
178 that.save_widget.update_document_title();
179 knw.danger("Dead kernel", undefined, showMsg);
179 knw.danger("Dead kernel", undefined, showMsg);
180 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
180 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
181
181
182 showMsg();
182 showMsg();
183 });
183 });
184
184
185 this.events.on('kernel_dead.Session', function (evt, info) {
185 this.events.on('kernel_dead.Session', function (evt, info) {
186 var full = info.xhr.responseJSON.message;
186 var full = info.xhr.responseJSON.message;
187 var short = info.xhr.responseJSON.short_message || 'Kernel error';
187 var short = info.xhr.responseJSON.short_message || 'Kernel error';
188 var traceback = info.xhr.responseJSON.traceback;
188 var traceback = info.xhr.responseJSON.traceback;
189
189
190 var showMsg = function () {
190 var showMsg = function () {
191 var msg = $('<div/>').append($('<p/>').text(full));
191 var msg = $('<div/>').append($('<p/>').text(full));
192 var cm, cm_elem, cm_open;
192 var cm, cm_elem, cm_open;
193
193
194 if (traceback) {
194 if (traceback) {
195 cm_elem = $('<div/>')
195 cm_elem = $('<div/>')
196 .css('margin-top', '1em')
196 .css('margin-top', '1em')
197 .css('padding', '1em')
197 .css('padding', '1em')
198 .addClass('output_scroll');
198 .addClass('output_scroll');
199 msg.append(cm_elem);
199 msg.append(cm_elem);
200 cm = CodeMirror(cm_elem.get(0), {
200 cm = CodeMirror(cm_elem.get(0), {
201 mode: "python",
201 mode: "python",
202 readOnly : true
202 readOnly : true
203 });
203 });
204 cm.setValue(traceback);
204 cm.setValue(traceback);
205 cm_open = $.proxy(cm.refresh, cm);
205 cm_open = $.proxy(cm.refresh, cm);
206 }
206 }
207
207
208 dialog.kernel_modal({
208 dialog.kernel_modal({
209 title: "Failed to start the kernel",
209 title: "Failed to start the kernel",
210 body : msg,
210 body : msg,
211 keyboard_manager: that.keyboard_manager,
211 keyboard_manager: that.keyboard_manager,
212 notebook: that.notebook,
212 notebook: that.notebook,
213 open: cm_open,
213 open: cm_open,
214 buttons : {
214 buttons : {
215 "Ok": { class: 'btn-primary' }
215 "Ok": { class: 'btn-primary' }
216 }
216 }
217 });
217 });
218
218
219 return false;
219 return false;
220 };
220 };
221
221
222 that.save_widget.update_document_title();
222 that.save_widget.update_document_title();
223 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
223 $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
224 knw.danger(short, undefined, showMsg);
224 knw.danger(short, undefined, showMsg);
225 });
225 });
226
226
227 this.events.on('kernel_starting.Kernel', function () {
227 this.events.on('kernel_starting.Kernel', function () {
228 window.document.title='(Starting) '+window.document.title;
228 window.document.title='(Starting) '+window.document.title;
229 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
229 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
230 knw.set_message("Kernel starting, please wait...");
230 knw.set_message("Kernel starting, please wait...");
231 });
231 });
232
232
233 this.events.on('kernel_ready.Kernel', function () {
233 this.events.on('kernel_ready.Kernel', function () {
234 that.save_widget.update_document_title();
234 that.save_widget.update_document_title();
235 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
235 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
236 knw.info("Kernel ready", 500);
236 knw.info("Kernel ready", 500);
237 });
237 });
238
238
239 this.events.on('kernel_idle.Kernel', function () {
239 this.events.on('kernel_idle.Kernel', function () {
240 that.save_widget.update_document_title();
240 that.save_widget.update_document_title();
241 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
241 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
242 });
242 });
243
243
244 this.events.on('kernel_busy.Kernel', function () {
244 this.events.on('kernel_busy.Kernel', function () {
245 window.document.title='(Busy) '+window.document.title;
245 window.document.title='(Busy) '+window.document.title;
246 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
246 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
247 });
247 });
248
248
249 // Start the kernel indicator in the busy state, and send a kernel_info request.
249 // Start the kernel indicator in the busy state, and send a kernel_info request.
250 // When the kernel_info reply arrives, the kernel is idle.
250 // When the kernel_info reply arrives, the kernel is idle.
251 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
251 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
252 };
252 };
253
253
254 /**
254 /**
255 * Initialize the notification widget for notebook status messages.
255 * Initialize the notification widget for notebook status messages.
256 *
256 *
257 * @method init_notebook_notification_widget
257 * @method init_notebook_notification_widget
258 */
258 */
259 NotebookNotificationArea.prototype.init_notebook_notification_widget = function () {
259 NotebookNotificationArea.prototype.init_notebook_notification_widget = function () {
260 var nnw = this.new_notification_widget('notebook');
260 var nnw = this.new_notification_widget('notebook');
261
261
262 // Notebook events
262 // Notebook events
263 this.events.on('notebook_loading.Notebook', function () {
263 this.events.on('notebook_loading.Notebook', function () {
264 nnw.set_message("Loading notebook",500);
264 nnw.set_message("Loading notebook",500);
265 });
265 });
266 this.events.on('notebook_loaded.Notebook', function () {
266 this.events.on('notebook_loaded.Notebook', function () {
267 nnw.set_message("Notebook loaded",500);
267 nnw.set_message("Notebook loaded",500);
268 });
268 });
269 this.events.on('notebook_saving.Notebook', function () {
269 this.events.on('notebook_saving.Notebook', function () {
270 nnw.set_message("Saving notebook",500);
270 nnw.set_message("Saving notebook",500);
271 });
271 });
272 this.events.on('notebook_saved.Notebook', function () {
272 this.events.on('notebook_saved.Notebook', function () {
273 nnw.set_message("Notebook saved",2000);
273 nnw.set_message("Notebook saved",2000);
274 });
274 });
275 this.events.on('notebook_save_failed.Notebook', function (evt, error) {
275 this.events.on('notebook_save_failed.Notebook', function (evt, error) {
276 nnw.warning(error.message || "Notebook save failed");
276 nnw.warning(error.message || "Notebook save failed");
277 });
277 });
278 this.events.on('notebook_copy_failed.Notebook', function (evt, error) {
278 this.events.on('notebook_copy_failed.Notebook', function (evt, error) {
279 nnw.warning(error.message || "Notebook copy failed");
279 nnw.warning(error.message || "Notebook copy failed");
280 });
280 });
281
281
282 nnw.set_message(msg, 1000);
283 this.events.on('toggle_other_client_output.Notebook', function(evt, ignored) {
282 this.events.on('toggle_other_client_output.Notebook', function(evt, ignored) {
284 var msg = (ignored? "Ignoring": "Showing") + " output from other clients";
283 var msg = (ignored? "Ignoring": "Showing") + " output from other clients";
284 nnw.set_message(msg, 2000);
285 });
285 });
286
286
287 // Checkpoint events
287 // Checkpoint events
288 this.events.on('checkpoint_created.Notebook', function (evt, data) {
288 this.events.on('checkpoint_created.Notebook', function (evt, data) {
289 var msg = "Checkpoint created";
289 var msg = "Checkpoint created";
290 if (data.last_modified) {
290 if (data.last_modified) {
291 var d = new Date(data.last_modified);
291 var d = new Date(data.last_modified);
292 msg = msg + ": " + moment(d).format("HH:mm:ss");
292 msg = msg + ": " + moment(d).format("HH:mm:ss");
293 }
293 }
294 nnw.set_message(msg, 2000);
294 nnw.set_message(msg, 2000);
295 });
295 });
296 this.events.on('checkpoint_failed.Notebook', function () {
296 this.events.on('checkpoint_failed.Notebook', function () {
297 nnw.warning("Checkpoint failed");
297 nnw.warning("Checkpoint failed");
298 });
298 });
299 this.events.on('checkpoint_deleted.Notebook', function () {
299 this.events.on('checkpoint_deleted.Notebook', function () {
300 nnw.set_message("Checkpoint deleted", 500);
300 nnw.set_message("Checkpoint deleted", 500);
301 });
301 });
302 this.events.on('checkpoint_delete_failed.Notebook', function () {
302 this.events.on('checkpoint_delete_failed.Notebook', function () {
303 nnw.warning("Checkpoint delete failed");
303 nnw.warning("Checkpoint delete failed");
304 });
304 });
305 this.events.on('checkpoint_restoring.Notebook', function () {
305 this.events.on('checkpoint_restoring.Notebook', function () {
306 nnw.set_message("Restoring to checkpoint...", 500);
306 nnw.set_message("Restoring to checkpoint...", 500);
307 });
307 });
308 this.events.on('checkpoint_restore_failed.Notebook', function () {
308 this.events.on('checkpoint_restore_failed.Notebook', function () {
309 nnw.warning("Checkpoint restore failed");
309 nnw.warning("Checkpoint restore failed");
310 });
310 });
311
311
312 // Autosave events
312 // Autosave events
313 this.events.on('autosave_disabled.Notebook', function () {
313 this.events.on('autosave_disabled.Notebook', function () {
314 nnw.set_message("Autosave disabled", 2000);
314 nnw.set_message("Autosave disabled", 2000);
315 });
315 });
316 this.events.on('autosave_enabled.Notebook', function (evt, interval) {
316 this.events.on('autosave_enabled.Notebook', function (evt, interval) {
317 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
317 nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
318 });
318 });
319 };
319 };
320
320
321 // Backwards compatibility.
321 // Backwards compatibility.
322 IPython.NotificationArea = NotebookNotificationArea;
322 IPython.NotificationArea = NotebookNotificationArea;
323
323
324 return {'NotebookNotificationArea': NotebookNotificationArea};
324 return {'NotebookNotificationArea': NotebookNotificationArea};
325 });
325 });
General Comments 0
You need to be logged in to leave comments. Login now