Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shutdown button option #3004

Merged
merged 6 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
websocket_url=jupyter_app.websocket_url,
mathjax_url=jupyter_app.mathjax_url,
mathjax_config=jupyter_app.mathjax_config,
shutdown_button=jupyter_app.quit_button,
config=jupyter_app.config,
config_dir=jupyter_app.config_dir,
allow_password_change=jupyter_app.allow_password_change,
Expand Down Expand Up @@ -1023,6 +1024,11 @@ def _update_mathjax_url(self, change):
@observe('mathjax_config')
def _update_mathjax_config(self, change):
self.log.info(_("Using MathJax configuration file: %s"), change['new'])

quit_button = Bool(True, config=True,
help="""If True, display a button in the dashboard to quit
(shutdown the notebook server)."""
)

contents_manager_class = Type(
default_value=LargeFileManager,
Expand Down
3 changes: 2 additions & 1 deletion notebook/static/base/less/page.less
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ span#login_widget {
}

span#login_widget > .button,
#logout
#logout, #shutdown
{
.btn-default();
margin-left: 10px;
}

.nav-header {
Expand Down
4 changes: 4 additions & 0 deletions notebook/static/tree/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ requirejs([
'tree/js/kernellist',
'tree/js/terminallist',
'tree/js/newnotebook',
'tree/js/shutdownbutton',
'auth/js/loginwidget',
'bidi/bidi',
], function(
Expand All @@ -52,6 +53,7 @@ requirejs([
kernellist,
terminallist,
newnotebook,
shutdownbutton,
loginwidget,
bidi){
"use strict";
Expand Down Expand Up @@ -209,4 +211,6 @@ requirejs([
if (window.location.hash) {
$("#tabs").find("a[href=" + window.location.hash + "]").click();
}

shutdownbutton.activate();
});
48 changes: 48 additions & 0 deletions notebook/static/tree/js/shutdownbutton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

define([
'jquery',
'base/js/dialog',
'base/js/i18n',
'base/js/utils'
], function(
$,
dialog,
i18n,
utils
){
"use strict";

function display_shutdown_dialog() {
var body = $('<div/>').append(
$('<p/>').text(i18n.msg._("You have shut down Jupyter. You can now close this tab."))
).append(
$('<p/>').text(i18n.msg._("To use Jupyter again, you will need to relaunch it."))
);

dialog.modal({
title: i18n.msg._("Server stopped"),
body: body
})
}

function activate() {
// Add shutdown button
$("button#shutdown").click(function () {
utils.ajax(utils.url_path_join(
utils.get_body_data("baseUrl"),
"api",
"shutdown"
), {
type: "POST",
success: display_shutdown_dialog,
error: function (error) {
console.log(error);
}
});
});
}

return {activate: activate}
});
10 changes: 9 additions & 1 deletion notebook/templates/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
{% endblock %}

{% block headercontainer %}
<span class="flex-spacer"></span>
<span class="flex-spacer"></span>
{% if shutdown_button %}
<span id="shutdown_widget">
<button id="shutdown" class="btn btn-sm navbar-btn"
title="{% trans %}Stop the Jupyter server{% endtrans %}">
{% trans %}Quit{% endtrans %}
</button>
</span>
{% endif %}
{% endblock %}

{% block site %}
Expand Down
1 change: 1 addition & 0 deletions notebook/tree/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def get(self, path=''):
breadcrumbs=breadcrumbs,
terminals_available=self.settings['terminals_available'],
server_root=self.settings['server_root_dir'],
shutdown_button=self.settings.get('shutdown_button', False)
))
elif cm.file_exists(path):
# it's not a directory, we have redirecting to do
Expand Down