Skip to content

Commit

Permalink
proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed May 15, 2012
1 parent 341b864 commit f9c25e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
8 changes: 4 additions & 4 deletions IPython/frontend/html/notebook/handlers.py
Expand Up @@ -338,7 +338,7 @@ def post(self):

class KernelHandler(AuthenticatedHandler):

SUPPORTED_METHODS = ('DELETE')
SUPPORTED_METHODS = ('POST','DELETE')

@web.authenticated
def delete(self, kernel_id):
Expand All @@ -347,7 +347,6 @@ def delete(self, kernel_id):
self.set_status(204)
self.finish()


class KernelActionHandler(AuthenticatedHandler):

@web.authenticated
Expand Down Expand Up @@ -596,8 +595,9 @@ def get(self):
nlist=[]
for f in files :
nid = f['notebook_id']
if km.kernel_for_notebook(nid) is not None:
f['kernel_status']='on'
kid = km.kernel_for_notebook(nid)
if kid is not None:
f['kernel_status']=kid
else:
f['kernel_status']='off'
nlist.append(f)
Expand Down
36 changes: 34 additions & 2 deletions IPython/frontend/html/notebook/static/js/notebooklist.js
Expand Up @@ -89,7 +89,6 @@ var IPython = (function (IPython) {


NotebookList.prototype.load_list = function () {
this.clear_list();
var settings = {
processData : false,
cache : false,
Expand All @@ -104,15 +103,21 @@ var IPython = (function (IPython) {

NotebookList.prototype.list_loaded = function (data, status, xhr) {
var len = data.length;
this.clear_list();
// Todo: remove old children
for (var i=0; i<len; i++) {
var notebook_id = data[i].notebook_id;
var nbname = data[i].name;
var kernel = data[i].kernel_status;
var item = this.new_notebook_item(i);
this.add_link(notebook_id, nbname, item);
if (!IPython.read_only){
// hide delete buttons when readonly
this.add_delete_button(item);
if(kernel == 'off'){
this.add_delete_button(item);
} else {
this.add_shutdown_button(item,kernel);
}
}
};
};
Expand Down Expand Up @@ -176,6 +181,33 @@ var IPython = (function (IPython) {
};


NotebookList.prototype.add_shutdown_button = function (item,kernel) {
var new_buttons = $('<span/>').addClass('item_buttons');
var that = this;
var shutdown_button = $('<button>Shutdown</button>').button().
click(function (e) {
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
success : function (data, status, xhr) {
console.log('kernel killed');
that.load_list();
}
};
var url = $('body').data('baseProjectUrl') + 'kernels/'+kernel;
$.ajax(url, settings);
});
new_buttons.append(shutdown_button);
var e = item.find('.item_buttons');
if (e.length === 0) {
item.append(new_buttons);
} else {
e.replaceWith(new_buttons);
};
};

NotebookList.prototype.add_delete_button = function (item) {
var new_buttons = $('<span/>').addClass('item_buttons');
var delete_button = $('<button>Delete</button>').button().
Expand Down

0 comments on commit f9c25e3

Please sign in to comment.