##// END OF EJS Templates
add some checkpoint messages to the notification area
MinRK -
Show More
@@ -1,188 +1,213
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2012 The IPython Development Team
2 // Copyright (C) 2012 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Notification widget
9 // Notification widget
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16
16
17 var NotificationArea = function (selector) {
17 var NotificationArea = function (selector) {
18 this.selector = selector;
18 this.selector = selector;
19 if (this.selector !== undefined) {
19 if (this.selector !== undefined) {
20 this.element = $(selector);
20 this.element = $(selector);
21 }
21 }
22 this.widget_dict = {};
22 this.widget_dict = {};
23 };
23 };
24
24
25 NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
25 NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
26 var uuid = utils.uuid();
26 var uuid = utils.uuid();
27 if( css_class == 'danger') {css_class = 'ui-state-error';}
27 if( css_class == 'danger') {css_class = 'ui-state-error';}
28 if( css_class == 'warning') {css_class = 'ui-state-highlight';}
28 if( css_class == 'warning') {css_class = 'ui-state-highlight';}
29 var tdiv = $('<div>')
29 var tdiv = $('<div>')
30 .attr('id',uuid)
30 .attr('id',uuid)
31 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
31 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
32 .addClass('border-box-sizing')
32 .addClass('border-box-sizing')
33 .addClass(css_class)
33 .addClass(css_class)
34 .hide()
34 .hide()
35 .text(msg);
35 .text(msg);
36
36
37 $(this.selector).append(tdiv);
37 $(this.selector).append(tdiv);
38 var tmout = Math.max(1500,(timeout||1500));
38 var tmout = Math.max(1500,(timeout||1500));
39 tdiv.fadeIn(100);
39 tdiv.fadeIn(100);
40
40
41 setTimeout(function () {
41 setTimeout(function () {
42 tdiv.fadeOut(100, function () {tdiv.remove();});
42 tdiv.fadeOut(100, function () {tdiv.remove();});
43 }, tmout);
43 }, tmout);
44 };
44 };
45
45
46 NotificationArea.prototype.widget = function(name) {
46 NotificationArea.prototype.widget = function(name) {
47 if(this.widget_dict[name] == undefined) {
47 if(this.widget_dict[name] == undefined) {
48 return this.new_notification_widget(name);
48 return this.new_notification_widget(name);
49 }
49 }
50 return this.get_widget(name);
50 return this.get_widget(name);
51 };
51 };
52
52
53 NotificationArea.prototype.get_widget = function(name) {
53 NotificationArea.prototype.get_widget = function(name) {
54 if(this.widget_dict[name] == undefined) {
54 if(this.widget_dict[name] == undefined) {
55 throw('no widgets with this name');
55 throw('no widgets with this name');
56 }
56 }
57 return this.widget_dict[name];
57 return this.widget_dict[name];
58 };
58 };
59
59
60 NotificationArea.prototype.new_notification_widget = function(name) {
60 NotificationArea.prototype.new_notification_widget = function(name) {
61 if(this.widget_dict[name] != undefined) {
61 if(this.widget_dict[name] != undefined) {
62 throw('widget with that name already exists ! ');
62 throw('widget with that name already exists ! ');
63 }
63 }
64 var div = $('<div/>').attr('id','notification_'+name);
64 var div = $('<div/>').attr('id','notification_'+name);
65 $(this.selector).append(div);
65 $(this.selector).append(div);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
67 return this.widget_dict[name];
67 return this.widget_dict[name];
68 };
68 };
69
69
70 NotificationArea.prototype.init_notification_widgets = function() {
70 NotificationArea.prototype.init_notification_widgets = function() {
71 var knw = this.new_notification_widget('kernel');
71 var knw = this.new_notification_widget('kernel');
72
72
73 // Kernel events
73 // Kernel events
74 $([IPython.events]).on('status_idle.Kernel',function () {
74 $([IPython.events]).on('status_idle.Kernel',function () {
75 IPython.save_widget.update_document_title();
75 IPython.save_widget.update_document_title();
76 knw.set_message('Kernel Idle',200);
76 knw.set_message('Kernel Idle',200);
77 }
77 }
78 );
78 );
79
79
80 $([IPython.events]).on('status_busy.Kernel',function () {
80 $([IPython.events]).on('status_busy.Kernel',function () {
81 window.document.title='(Busy) '+window.document.title;
81 window.document.title='(Busy) '+window.document.title;
82 knw.set_message("Kernel busy");
82 knw.set_message("Kernel busy");
83 });
83 });
84
84
85 $([IPython.events]).on('status_restarting.Kernel',function () {
85 $([IPython.events]).on('status_restarting.Kernel',function () {
86 IPython.save_widget.update_document_title();
86 IPython.save_widget.update_document_title();
87 knw.set_message("Restarting kernel", 2000);
87 knw.set_message("Restarting kernel", 2000);
88 });
88 });
89
89
90 $([IPython.events]).on('status_interrupting.Kernel',function () {
90 $([IPython.events]).on('status_interrupting.Kernel',function () {
91 knw.set_message("Interrupting kernel");
91 knw.set_message("Interrupting kernel");
92 });
92 });
93
93
94 $([IPython.events]).on('status_dead.Kernel',function () {
94 $([IPython.events]).on('status_dead.Kernel',function () {
95 var dialog = $('<div/>');
95 var dialog = $('<div/>');
96 dialog.html('The kernel has died, and the automatic restart has failed.' +
96 dialog.html('The kernel has died, and the automatic restart has failed.' +
97 ' It is possible the kernel cannot be restarted.' +
97 ' It is possible the kernel cannot be restarted.' +
98 ' If you are not able to restart the kernel, you will still be able to save' +
98 ' If you are not able to restart the kernel, you will still be able to save' +
99 ' the notebook, but running code will no longer work until the notebook' +
99 ' the notebook, but running code will no longer work until the notebook' +
100 ' is reopened.'
100 ' is reopened.'
101 );
101 );
102 $(document).append(dialog);
102 $(document).append(dialog);
103 dialog.dialog({
103 dialog.dialog({
104 resizable: false,
104 resizable: false,
105 modal: true,
105 modal: true,
106 title: "Dead kernel",
106 title: "Dead kernel",
107 close: function(event, ui) {$(this).dialog('destroy').remove();},
107 close: function(event, ui) {$(this).dialog('destroy').remove();},
108 buttons : {
108 buttons : {
109 "Manual Restart": function () {
109 "Manual Restart": function () {
110 $([IPython.events]).trigger('status_restarting.Kernel');
110 $([IPython.events]).trigger('status_restarting.Kernel');
111 IPython.notebook.start_kernel();
111 IPython.notebook.start_kernel();
112 $(this).dialog('close');
112 $(this).dialog('close');
113 },
113 },
114 "Don't restart": function () {
114 "Don't restart": function () {
115 $(this).dialog('close');
115 $(this).dialog('close');
116 }
116 }
117 }
117 }
118 });
118 });
119 });
119 });
120
120
121 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
121 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
122 var kernel = data.kernel;
122 var kernel = data.kernel;
123 var ws_url = data.ws_url;
123 var ws_url = data.ws_url;
124 var early = data.early;
124 var early = data.early;
125 var msg;
125 var msg;
126 if (!early) {
126 if (!early) {
127 knw.set_message('Reconnecting WebSockets', 1000);
127 knw.set_message('Reconnecting WebSockets', 1000);
128 setTimeout(function () {
128 setTimeout(function () {
129 kernel.start_channels();
129 kernel.start_channels();
130 }, 5000);
130 }, 5000);
131 return;
131 return;
132 }
132 }
133 console.log('WebSocket connection failed: ', ws_url)
133 console.log('WebSocket connection failed: ', ws_url)
134 msg = "A WebSocket connection to could not be established." +
134 msg = "A WebSocket connection to could not be established." +
135 " You will NOT be able to run code. Check your" +
135 " You will NOT be able to run code. Check your" +
136 " network connection or notebook server configuration.";
136 " network connection or notebook server configuration.";
137 var dialog = $('<div/>');
137 var dialog = $('<div/>');
138 dialog.html(msg);
138 dialog.html(msg);
139 $(document).append(dialog);
139 $(document).append(dialog);
140 dialog.dialog({
140 dialog.dialog({
141 resizable: false,
141 resizable: false,
142 modal: true,
142 modal: true,
143 title: "WebSocket connection failed",
143 title: "WebSocket connection failed",
144 closeText: "",
144 closeText: "",
145 close: function(event, ui) {$(this).dialog('destroy').remove();},
145 close: function(event, ui) {$(this).dialog('destroy').remove();},
146 buttons : {
146 buttons : {
147 "OK": function () {
147 "OK": function () {
148 $(this).dialog('close');
148 $(this).dialog('close');
149 },
149 },
150 "Reconnect": function () {
150 "Reconnect": function () {
151 knw.set_message('Reconnecting WebSockets', 1000);
151 knw.set_message('Reconnecting WebSockets', 1000);
152 setTimeout(function () {
152 setTimeout(function () {
153 kernel.start_channels();
153 kernel.start_channels();
154 }, 5000);
154 }, 5000);
155 $(this).dialog('close');
155 $(this).dialog('close');
156 }
156 }
157 }
157 }
158 });
158 });
159 });
159 });
160
160
161
161
162 var nnw = this.new_notification_widget('notebook');
162 var nnw = this.new_notification_widget('notebook');
163
163
164 // Notebook events
164 // Notebook events
165 $([IPython.events]).on('notebook_loading.Notebook', function () {
165 $([IPython.events]).on('notebook_loading.Notebook', function () {
166 nnw.set_message("Loading notebook",500);
166 nnw.set_message("Loading notebook",500);
167 });
167 });
168 $([IPython.events]).on('notebook_loaded.Notebook', function () {
168 $([IPython.events]).on('notebook_loaded.Notebook', function () {
169 nnw.set_message("Notebook loaded",500);
169 nnw.set_message("Notebook loaded",500);
170 });
170 });
171 $([IPython.events]).on('notebook_saving.Notebook', function () {
171 $([IPython.events]).on('notebook_saving.Notebook', function () {
172 nnw.set_message("Saving notebook",500);
172 nnw.set_message("Saving notebook",500);
173 });
173 });
174 $([IPython.events]).on('notebook_saved.Notebook', function () {
174 $([IPython.events]).on('notebook_saved.Notebook', function () {
175 nnw.set_message("Notebook saved",2000);
175 nnw.set_message("Notebook saved",2000);
176 });
176 });
177 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
177 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
178 nnw.set_message("Notebook save failed");
178 nnw.set_message("Notebook save failed");
179 });
179 });
180
180
181 // Checkpoint events
182 $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
183 var msg = "Checkpoint created";
184 if (data.last_modified) {
185 var d = new Date(data.last_modified);
186 msg = msg + ": " + d.format("HH:MM:ss");
187 }
188 nnw.set_message(msg, 2000);
189 });
190 $([IPython.events]).on('checkpoint_failed.Notebook', function () {
191 nnw.set_message("Checkpoint failed");
192 });
193 $([IPython.events]).on('checkpoint_deleted.Notebook', function () {
194 nnw.set_message("Checkpoint deleted", 500);
195 });
196 $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
197 nnw.set_message("Checkpoint delete failed");
198 });
199 $([IPython.events]).on('checkpoint_restoring.Notebook', function () {
200 nnw.set_message("Restoring to checkpoint...", 500);
201 });
202 $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
203 nnw.set_message("Checkpoint restore failed");
204 });
205
181 };
206 };
182
207
183 IPython.NotificationArea = NotificationArea;
208 IPython.NotificationArea = NotificationArea;
184
209
185 return IPython;
210 return IPython;
186
211
187 }(IPython));
212 }(IPython));
188
213
General Comments 0
You need to be logged in to leave comments. Login now