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 prototype shutdown button to Notebook dashboard #1343

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions IPython/frontend/html/notebook/handlers.py
Expand Up @@ -312,6 +312,11 @@ def get(self, notebook_id):
mathjax_url=self.application.ipython_app.mathjax_url,
)

class ShutdownHandler(AuthenticatedHandler):
def get(self):
self.render('shutdown.html', logged_in=False, login_available=False)
self.application.ipython_app.ioloop.stop()

#-----------------------------------------------------------------------------
# Kernel handlers
#-----------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -49,7 +49,7 @@
ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler,
ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler
RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler, ShutdownHandler
)
from .notebookmanager import NotebookManager

Expand Down Expand Up @@ -106,6 +106,7 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager, log,
(r"/", ProjectDashboardHandler),
(r"/login", LoginHandler),
(r"/logout", LogoutHandler),
(r"/shutdown", ShutdownHandler),
(r"/new", NewHandler),
(r"/%s" % _notebook_id_regex, NamedNotebookHandler),
(r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
Expand Down Expand Up @@ -419,8 +420,10 @@ def start(self):
b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
new=2)
threading.Thread(target=b).start()

self.ioloop = ioloop.IOLoop.instance()
try:
ioloop.IOLoop.instance().start()
self.ioloop.start()
except KeyboardInterrupt:
info("Interrupted...")
finally:
Expand Down
Expand Up @@ -49,10 +49,14 @@ body {
float: left;
}

#notebooks_buttons {
#notebooks_buttons, #control_buttons {
float: right;
}

#control_toolbar {
padding-top: 0.5em;
}

#project_name {
height: 25px;
line-height: 25px;
Expand Down
1 change: 1 addition & 0 deletions IPython/frontend/html/notebook/static/js/menubar.js
Expand Up @@ -67,6 +67,7 @@ var IPython = (function (IPython) {
this.element.find('button#print_notebook').click(function () {
IPython.print_widget.print_notebook();
});
this.element.find('#shutdown_server').click(confirm_shutdown);
// Edit
this.element.find('#cut_cell').click(function () {
IPython.notebook.cut_cell();
Expand Down
27 changes: 27 additions & 0 deletions IPython/frontend/html/notebook/static/js/projectdashboardmain.js
Expand Up @@ -10,6 +10,30 @@
//============================================================================


confirm_shutdown = function () {
var dialog = $('<div/>');
dialog.html('Do you want to shut down the notebook server? ' +
'You will lose any unsaved work and all running kernels.');
$(document).append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Shutdown IPython Notebook?",
closeText: '',
buttons : {
"Shutdown": function () {
window.location.href = $('body').data('baseProjectUrl')+'shutdown';
$(this).dialog('close');
},
"Continue running": function () {
$(this).dialog('close');
}
}
});

};


$(document).ready(function () {

$('div#header').addClass('border-box-sizing');
Expand Down Expand Up @@ -37,6 +61,9 @@ $(document).ready(function () {
$('div#header').css('display','block');
$('div#main_app').css('display','block');

$('#shutdown').button().click(function(e) {
confirm_shutdown();
});

});

3 changes: 3 additions & 0 deletions IPython/frontend/html/notebook/templates/notebook.html
Expand Up @@ -77,6 +77,8 @@
</li>
<hr/>
<li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li>
<hr/>
<li id="shutdown_server"><a href="#">Shutdown Notebooks</a></li>
</ul>
</li>
<li><a href="#">Edit</a>
Expand Down Expand Up @@ -221,6 +223,7 @@
<script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ static_url("js/projectdashboardmain.js") }}" type="text/javascript" charset="utf-8"></script>

</body>

Expand Down
Expand Up @@ -35,6 +35,12 @@
<div id="notebook_list">
<div id="project_name"><h2>{{project}}</h2></div>
</div>

<div id="control_toolbar">
<span id="control_buttons">
<button id="shutdown">Shutdown Notebook Server</button>
</span>
</div>
{% end %}

{% block script %}
Expand Down
39 changes: 39 additions & 0 deletions IPython/frontend/html/notebook/templates/shutdown.html
@@ -0,0 +1,39 @@
{% extends layout.html %}

{% block stylesheet %}
<style type="text/css">
#app_hbox {
width: 100%
}

#content_panel {
width: 800px;
margin-left: auto;
margin-right: auto;
padding-top: 1em;
}

h1 {
font-size: 2em;
padding-bottom: 1em;
}

p {
padding-bottom: 1em;
}

</style>
{% end %}

{% block title %}
(Shutdown) IPython Notebook
{% end %}

{% block content_panel %}
<h1>Notebook Shutdown</h1>

<p>The IPython Notebook server has been stopped. You can close this tab.</p>

<p><a href="http://ipython.org/">IPython homepage</a></p>

{% end %}