From 86e45ab9f45b7259e4852de8667ba08bb2674012 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 31 Oct 2017 11:07:54 -0700 Subject: [PATCH 1/6] Add shutdown button option --- notebook/notebookapp.py | 5 +++++ notebook/static/base/less/page.less | 3 ++- notebook/static/tree/js/main.js | 17 +++++++++++++++++ notebook/templates/tree.html | 7 ++++++- notebook/tree/handlers.py | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 57993f318..64fafba96 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -273,6 +273,7 @@ class NotebookWebApplication(web.Application): websocket_url=jupyter_app.websocket_url, mathjax_url=jupyter_app.mathjax_url, mathjax_config=jupyter_app.mathjax_config, + shutdown_button=jupyter_app.shutdown_button, config=jupyter_app.config, config_dir=jupyter_app.config_dir, allow_password_change=jupyter_app.allow_password_change, @@ -1023,6 +1024,10 @@ class NotebookApp(JupyterApp): @observe('mathjax_config') def _update_mathjax_config(self, change): self.log.info(_("Using MathJax configuration file: %s"), change['new']) + + shutdown_button = Bool(False, config=True, + help="""Whether or not to display a shutdown server button in the dashboard""" + ) contents_manager_class = Type( default_value=LargeFileManager, diff --git a/notebook/static/base/less/page.less b/notebook/static/base/less/page.less index 85e7f825a..d2720b386 100644 --- a/notebook/static/base/less/page.less +++ b/notebook/static/base/less/page.less @@ -124,9 +124,10 @@ span#login_widget { } span#login_widget > .button, -#logout +#logout, #shutdown { .btn-default(); + margin-left: 10px; } .nav-header { diff --git a/notebook/static/tree/js/main.js b/notebook/static/tree/js/main.js index ebced6b6f..76be61fa3 100644 --- a/notebook/static/tree/js/main.js +++ b/notebook/static/tree/js/main.js @@ -209,4 +209,21 @@ requirejs([ if (window.location.hash) { $("#tabs").find("a[href=" + window.location.hash + "]").click(); } + + // Add shutdown button + $("button#shutdown").click(function () { + utils.ajax(utils.url_path_join( + utils.get_body_data("baseUrl"), + "api", + "shutdown" + ), { + type: "POST", + success: function() { + console.log('server shutdown'); + }, + error: function(error) { + console.log(error); + } + }); + }); }); diff --git a/notebook/templates/tree.html b/notebook/templates/tree.html index 1e2377b93..c1944f7a4 100644 --- a/notebook/templates/tree.html +++ b/notebook/templates/tree.html @@ -12,7 +12,12 @@ data-server-root="{{server_root}}" {% endblock %} {% block headercontainer %} - + + {% if shutdown_button %} + + + + {% endif %} {% endblock %} {% block site %} diff --git a/notebook/tree/handlers.py b/notebook/tree/handlers.py index ef4252761..4cc4c8062 100644 --- a/notebook/tree/handlers.py +++ b/notebook/tree/handlers.py @@ -51,6 +51,7 @@ class TreeHandler(IPythonHandler): 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 From c9a124d58cad637c9fc896fced02fd20ed1726aa Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 29 Mar 2018 11:50:38 +0200 Subject: [PATCH 2/6] Enable shutdown button by default --- notebook/notebookapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 64fafba96..9a700e0dc 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -1025,8 +1025,8 @@ class NotebookApp(JupyterApp): def _update_mathjax_config(self, change): self.log.info(_("Using MathJax configuration file: %s"), change['new']) - shutdown_button = Bool(False, config=True, - help="""Whether or not to display a shutdown server button in the dashboard""" + shutdown_button = Bool(True, config=True, + help="""If True, display a button in the dashboard to shutdown the server""" ) contents_manager_class = Type( From ae1b6fb835d733f140e983efa9ec9eef9f6ddee7 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 29 Mar 2018 11:53:00 +0200 Subject: [PATCH 3/6] Change button label to 'Quit' --- notebook/templates/tree.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/notebook/templates/tree.html b/notebook/templates/tree.html index c1944f7a4..e37f08d3c 100644 --- a/notebook/templates/tree.html +++ b/notebook/templates/tree.html @@ -15,7 +15,10 @@ data-server-root="{{server_root}}" {% if shutdown_button %} - + {% endif %} {% endblock %} From 8a97003a6a620d13256d7f1c44db3fe29321a689 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 29 Mar 2018 12:14:05 +0200 Subject: [PATCH 4/6] New module for shutdownbutton --- notebook/static/tree/js/main.js | 19 ++------- notebook/static/tree/js/shutdownbutton.js | 52 +++++++++++++++++++++++ 2 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 notebook/static/tree/js/shutdownbutton.js diff --git a/notebook/static/tree/js/main.js b/notebook/static/tree/js/main.js index 76be61fa3..5dcf8d806 100644 --- a/notebook/static/tree/js/main.js +++ b/notebook/static/tree/js/main.js @@ -35,6 +35,7 @@ requirejs([ 'tree/js/kernellist', 'tree/js/terminallist', 'tree/js/newnotebook', + 'tree/js/shutdownbutton', 'auth/js/loginwidget', 'bidi/bidi', ], function( @@ -52,6 +53,7 @@ requirejs([ kernellist, terminallist, newnotebook, + shutdownbutton, loginwidget, bidi){ "use strict"; @@ -210,20 +212,5 @@ requirejs([ $("#tabs").find("a[href=" + window.location.hash + "]").click(); } - // Add shutdown button - $("button#shutdown").click(function () { - utils.ajax(utils.url_path_join( - utils.get_body_data("baseUrl"), - "api", - "shutdown" - ), { - type: "POST", - success: function() { - console.log('server shutdown'); - }, - error: function(error) { - console.log(error); - } - }); - }); + shutdownbutton.activate(); }); diff --git a/notebook/static/tree/js/shutdownbutton.js b/notebook/static/tree/js/shutdownbutton.js new file mode 100644 index 000000000..c7231e73c --- /dev/null +++ b/notebook/static/tree/js/shutdownbutton.js @@ -0,0 +1,52 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'base/js/dialog', + 'base/js/events', + 'base/js/promises', + 'base/js/page', + 'base/js/utils' +], function( + $, + dialog, + events, + promises, + page, + utils +){ + "use strict"; + + function display_shutdown_dialog() { + var body = $('
').append( + $('

').text("You have shut down Jupyter. You can now close this tab.") + ).append( + $('

').text("To use Jupyter again, you will need to relaunch it.") + ); + + dialog.modal({ + title: "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} +}); From 9359a7378825e6b23f28ddde538e00c9715c8f23 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 29 Mar 2018 12:17:19 +0200 Subject: [PATCH 5/6] Allow translation of shutdown dialog --- notebook/static/tree/js/shutdownbutton.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/notebook/static/tree/js/shutdownbutton.js b/notebook/static/tree/js/shutdownbutton.js index c7231e73c..e8b789fd1 100644 --- a/notebook/static/tree/js/shutdownbutton.js +++ b/notebook/static/tree/js/shutdownbutton.js @@ -4,29 +4,25 @@ define([ 'jquery', 'base/js/dialog', - 'base/js/events', - 'base/js/promises', - 'base/js/page', + 'base/js/i18n', 'base/js/utils' ], function( $, dialog, - events, - promises, - page, + i18n, utils ){ "use strict"; function display_shutdown_dialog() { var body = $('

').append( - $('

').text("You have shut down Jupyter. You can now close this tab.") + $('

').text(i18n.msg._("You have shut down Jupyter. You can now close this tab.")) ).append( - $('

').text("To use Jupyter again, you will need to relaunch it.") + $('

').text(i18n.msg._("To use Jupyter again, you will need to relaunch it.")) ); dialog.modal({ - title: "Server stopped", + title: i18n.msg._("Server stopped"), body: body }) } From de37b584d1dab59ff454c2054d4a72e0820f9f4e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 3 Apr 2018 17:28:08 +0200 Subject: [PATCH 6/6] Rename config option to quit_button --- notebook/notebookapp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 9a700e0dc..9e445f697 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -273,7 +273,7 @@ class NotebookWebApplication(web.Application): websocket_url=jupyter_app.websocket_url, mathjax_url=jupyter_app.mathjax_url, mathjax_config=jupyter_app.mathjax_config, - shutdown_button=jupyter_app.shutdown_button, + shutdown_button=jupyter_app.quit_button, config=jupyter_app.config, config_dir=jupyter_app.config_dir, allow_password_change=jupyter_app.allow_password_change, @@ -1025,8 +1025,9 @@ class NotebookApp(JupyterApp): def _update_mathjax_config(self, change): self.log.info(_("Using MathJax configuration file: %s"), change['new']) - shutdown_button = Bool(True, config=True, - help="""If True, display a button in the dashboard to shutdown the server""" + 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(