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