Skip to content

Commit

Permalink
Add shutdown button option
Browse files Browse the repository at this point in the history
  • Loading branch information
gnestor committed Oct 31, 2017
1 parent 600d57f commit f4783f7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions notebook/notebookapp.py
Expand Up @@ -264,6 +264,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.shutdown_button,
config=jupyter_app.config,
config_dir=jupyter_app.config_dir,
server_root_dir=root_dir,
Expand Down Expand Up @@ -916,6 +917,10 @@ 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'])

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,
Expand Down
3 changes: 2 additions & 1 deletion notebook/static/base/less/page.less
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
17 changes: 17 additions & 0 deletions notebook/static/tree/js/main.js
Expand Up @@ -209,4 +209,21 @@ require([
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);
}
});
});
});
7 changes: 6 additions & 1 deletion notebook/templates/tree.html
Expand Up @@ -12,7 +12,12 @@
{% 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">Shutdown</button>
</span>
{% endif %}
{% endblock %}

{% block site %}
Expand Down
1 change: 1 addition & 0 deletions notebook/tree/handlers.py
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

0 comments on commit f4783f7

Please sign in to comment.