kernel halt confirmation dialog

Paul Ivanov 9 years ago
parent f8c41bec1a
commit 95790be956

@ -75,6 +75,20 @@ define(function(require){
env.notebook.show_shortcuts_editor();
}
},
'halt-kernel': {
help: 'Halt the kernel (no confirmation dialog)',
handler: function (env) {
env.notebook.halt_kernel({confirm: false});
}
},
'confirm-halt-kernel':{
icon: 'fa-repeat',
help_index : 'hb',
help: 'Shutdown the kernel (with confirmation dialog)',
handler : function (env) {
env.notebook.halt_kernel();
}
},
'restart-kernel': {
help: 'restart the kernel (no confirmation dialog)',
handler: function (env) {

@ -250,6 +250,7 @@ define([
'#rename_notebook' : 'rename-notebook',
'#find_and_replace' : 'find-and-replace',
'#save_checkpoint': 'save-notebook',
'#halt_kernel': 'confirm-halt-kernel',
'#restart_kernel': 'confirm-restart-kernel',
'#restart_clear_output': 'confirm-restart-kernel-and-clear-output',
'#restart_run_all': 'confirm-restart-kernel-and-run-all-cells',

@ -2262,6 +2262,28 @@ define([
* Prompt the user to restart the kernel.
* if options.confirm === false, no confirmation dialog is shown.
*/
Notebook.prototype.halt_kernel = function (options) {
var that = this;
var halt_options = {};
halt_options.confirm = (options || {}).confirm;
halt_options.dialog = {
title : "Halt kernel?",
body : $("<p/>").text(
'Do you want to halt the current kernel? All variables will be lost.'
),
buttons : {
"Halt" : {
"class" : "btn-danger",
"click" : function () {},
},
}
};
halt_options.kernel_action = function() {
that.session.delete();
};
return this._restart_kernel(halt_options);
};
Notebook.prototype.restart_kernel = function (options) {
var that = this;
var restart_options = {};
@ -2297,11 +2319,14 @@ define([
that.events.one('kernel_ready.Kernel', resolve_promise);
}, reject_promise);
}
if (options.confirm === false) {
var do_kernel_action = options.kernel_action || restart_and_resolve;
// no need to confirm if the kernel is not connected
if (options.confirm === false || !that.kernel.is_connected()) {
var default_button = options.dialog.buttons[Object.keys(options.dialog.buttons)[0]];
promise.then(default_button.click);
restart_and_resolve();
do_kernel_action();
return promise;
}
options.dialog.notebook = this;
@ -2316,7 +2341,7 @@ define([
var click = button.click;
button.click = function () {
promise.then(click);
restart_and_resolve();
do_kernel_action();
};
});
options.dialog.buttons = buttons;

@ -317,8 +317,7 @@ define([
};
var on_error = function (xhr, status, err) {
that.events.trigger('kernel_dead.Kernel', {kernel: that});
that._kernel_dead();
that.events.trigger('kernel_failed_restart.Kernel', {kernel: that});
if (error) {
error(xhr, status, err);
}

@ -62,6 +62,9 @@ define([
this.events.on('kernel_dead.Kernel', function () {
that.delete();
});
this.events.on('kernel_failed_restart.Kernel', function () {
that.notebook.start_session();
});
};
@ -188,7 +191,7 @@ define([
* @param {function} [error] - functon executed on ajax error
*/
Session.prototype.delete = function (success, error) {
if (this.kernel) {
if (this.kernel && this.kernel.is_connected()) {
this.events.trigger('kernel_killed.Session', {session: this, kernel: this.kernel});
this.kernel._kernel_dead();
}

@ -254,7 +254,7 @@ data-notebook-path="{{notebook_path | urlencode}}"
title="Send KeyboardInterrupt (CTRL-C) to the Kernel">
<a href="#">Interrupt</a>
</li>
<li id="restart_kernel"
<li id="restart_kernel"
title="Restart the Kernel">
<a href="#">Restart</a>
</li>
@ -270,6 +270,10 @@ data-notebook-path="{{notebook_path | urlencode}}"
title="Reconnect to the Kernel">
<a href="#">Reconnect</a>
</li>
<li id="halt_kernel"
title="Shutdown the Kernel">
<a href="#">Shutdown</a>
</li>
<li class="divider"></li>
<li id="menu-change-kernel" class="dropdown-submenu">
<a href="#">Change kernel</a>

@ -0,0 +1,44 @@
casper.notebook_test(function () {
var that = this;
var menuItems = ['#restart_kernel', '#restart_clear_output', '#restart_run_all', '#halt_kernel']
var cancelSelector = ".modal-footer button:first-of-type"
menuItems.forEach( function(selector) {
that.thenClick(selector);
that.waitForSelector(cancelSelector);
that.thenClick(cancelSelector);
that.waitWhileSelector(".modal-content", function() {
that.test.assert(true, selector + " confirmation modal pops up and is cancelable");
});
});
var haltSelector = menuItems.pop();
var confirmSelector = ".modal-footer .btn-danger"
menuItems.forEach( function(selector) {
that.thenClick(haltSelector);
that.waitForSelector(confirmSelector);
that.thenClick(confirmSelector);
// wait for shutdown to go through
that.waitFor(function() { return this.evaluate(function() {
return IPython.notebook.kernel.is_connected() === false;
})});
// Click on one of the restarts
that.thenClick(selector);
// Kernel should get connected, no need for confirmation.
that.waitFor(function() { return this.evaluate(function() {
return IPython.notebook.kernel.is_connected() === true;
})});
that.then(function() {
that.test.assert(true, "no confirmation for " + selector + " after session halted")
})
});
});
Loading…
Cancel
Save