kernellist.js
76 lines
| 2.2 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r17190 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
define([ | ||||
'base/js/namespace', | ||||
Jonathan Frederic
|
r17200 | 'jquery', | ||
Jonathan Frederic
|
r17190 | 'tree/js/notebooklist', | ||
Jonathan Frederic
|
r17202 | ], function(IPython, $, notebooklist) { | ||
Paul Ivanov
|
r15382 | "use strict"; | ||
jon
|
r17210 | var KernelList = function (selector, options) { | ||
Jonathan Frederic
|
r19176 | /** | ||
* Constructor | ||||
* | ||||
* Parameters: | ||||
* selector: string | ||||
* options: dictionary | ||||
* Dictionary of keyword arguments. | ||||
* session_list: SessionList instance | ||||
* base_url: string | ||||
* notebook_path: string | ||||
*/ | ||||
jon
|
r17210 | notebooklist.NotebookList.call(this, selector, $.extend({ | ||
MinRK
|
r17535 | element_name: 'running'}, | ||
jon
|
r17210 | options)); | ||
Paul Ivanov
|
r15382 | }; | ||
Jonathan Frederic
|
r17203 | KernelList.prototype = Object.create(notebooklist.NotebookList.prototype); | ||
Paul Ivanov
|
r15382 | |||
Min RK
|
r18928 | KernelList.prototype.add_duplicate_button = function () { | ||
Jonathan Frederic
|
r19176 | /** | ||
* do nothing | ||||
*/ | ||||
Min RK
|
r18928 | }; | ||
Paul Ivanov
|
r15454 | KernelList.prototype.sessions_loaded = function (d) { | ||
Paul Ivanov
|
r15479 | this.sessions = d; | ||
Paul Ivanov
|
r15454 | this.clear_list(); | ||
Min RK
|
r18928 | var item, path; | ||
for (path in d) { | ||||
if (!d.hasOwnProperty(path)) { | ||||
MinRK
|
r17535 | // nothing is safe in javascript | ||
continue; | ||||
} | ||||
item = this.new_item(-1); | ||||
this.add_link({ | ||||
Min RK
|
r18928 | name: path, | ||
path: path, | ||||
MinRK
|
r17535 | type: 'notebook', | ||
}, item); | ||||
Paul Ivanov
|
r15454 | } | ||
Peter Parente
|
r20447 | $('#running_list_placeholder').toggle($.isEmptyObject(d)); | ||
Jonathan Frederic
|
r17190 | }; | ||
Jonathan Frederic
|
r20164 | |||
KernelList.prototype.add_link = function (model, item) { | ||||
notebooklist.NotebookList.prototype.add_link.apply(this, [model, item]) | ||||
var running_indicator = item.find(".item_buttons") | ||||
.text(''); | ||||
var that = this; | ||||
var shutdown_button = $('<button/>') | ||||
.addClass('btn btn-warning btn-xs') | ||||
.text('Shutdown') | ||||
.click(function() { | ||||
var path = $(this).parent().parent().parent().data('path'); | ||||
that.shutdown_notebook(path); | ||||
}) | ||||
.appendTo(running_indicator); | ||||
}; | ||||
Paul Ivanov
|
r15454 | |||
Jonathan Frederic
|
r17190 | // Backwards compatability. | ||
Paul Ivanov
|
r15382 | IPython.KernelList = KernelList; | ||
Jonathan Frederic
|
r17201 | return {'KernelList': KernelList}; | ||
Jonathan Frederic
|
r17190 | }); | ||