mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-21 04:10:17 +08:00
added IPython.session_list
before this, kernel_list and notebook_list each fetched and held onto their own copy of the sessions.
This commit is contained in:
parent
06c689caa3
commit
b74b10e308
@ -21,22 +21,20 @@ var IPython = (function (IPython) {
|
||||
KernelList.prototype = Object.create(IPython.NotebookList.prototype);
|
||||
|
||||
KernelList.prototype.sessions_loaded = function (d) {
|
||||
this.sessions = d;
|
||||
// clear out the previous list
|
||||
this.clear_list();
|
||||
var len = d.length;
|
||||
var item;
|
||||
for (var i=0; i < d.length; i++) {
|
||||
var path= utils.url_path_join(d[i].notebook.path, d[i].notebook.name);
|
||||
item = this.new_notebook_item(i);
|
||||
for (var path in d) {
|
||||
item = this.new_notebook_item(-1);
|
||||
this.add_link('', path, item);
|
||||
this.sessions[path] = d[i].id;
|
||||
this.add_shutdown_button(item,this.sessions[path]);
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
$('#' + this.element_name + '_list_header').hide();
|
||||
} else {
|
||||
if ($.isEmptyObject(d)) {
|
||||
$('#' + this.element_name + '_list_header').show();
|
||||
} else {
|
||||
$('#' + this.element_name + '_list_header').hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ $(document).ready(function () {
|
||||
base_url : IPython.utils.get_body_data("baseUrl"),
|
||||
notebook_path : IPython.utils.get_body_data("notebookPath"),
|
||||
};
|
||||
IPython.session_list = new IPython.SesssionList(opts);
|
||||
IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts);
|
||||
IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts);
|
||||
IPython.kernel_list = new IPython.KernelList('#running_list', opts);
|
||||
@ -36,16 +37,14 @@ $(document).ready(function () {
|
||||
//refresh immediately , then start interval
|
||||
if($('.upload_button').length == 0)
|
||||
{
|
||||
IPython.notebook_list.load_sessions();
|
||||
IPython.kernel_list.load_sessions();
|
||||
IPython.session_list.load_sessions();
|
||||
IPython.cluster_list.load_list();
|
||||
}
|
||||
if (!interval_id){
|
||||
interval_id = setInterval(function(){
|
||||
if($('.upload_button').length == 0)
|
||||
{
|
||||
IPython.notebook_list.load_sessions();
|
||||
IPython.kernel_list.load_sessions();
|
||||
IPython.session_list.load_sessions();
|
||||
IPython.cluster_list.load_list();
|
||||
}
|
||||
}, time_refresh*1000);
|
||||
|
@ -15,6 +15,7 @@ var IPython = (function (IPython) {
|
||||
var utils = IPython.utils;
|
||||
|
||||
var NotebookList = function (selector, options, element_name) {
|
||||
var that = this
|
||||
// allow code re-use by just changing element_name in kernellist.js
|
||||
this.element_name = element_name || 'notebook';
|
||||
this.selector = selector;
|
||||
@ -27,6 +28,8 @@ var IPython = (function (IPython) {
|
||||
this.sessions = {};
|
||||
this.base_url = options.base_url || utils.get_body_data("baseUrl");
|
||||
this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
|
||||
$([IPython.events]).on('sessions_loaded.Dashboard',
|
||||
function(e, d) { that.sessions_loaded(d); });
|
||||
};
|
||||
|
||||
NotebookList.prototype.style = function () {
|
||||
@ -100,37 +103,12 @@ var IPython = (function (IPython) {
|
||||
};
|
||||
|
||||
NotebookList.prototype.load_sessions = function(){
|
||||
var that = this;
|
||||
var settings = {
|
||||
processData : false,
|
||||
cache : false,
|
||||
type : "GET",
|
||||
dataType : "json",
|
||||
success : $.proxy(that.sessions_loaded, this)
|
||||
};
|
||||
var url = utils.url_join_encode(this.base_url, 'api/sessions');
|
||||
$.ajax(url,settings);
|
||||
IPython.session_list.load_sessions();
|
||||
};
|
||||
|
||||
|
||||
NotebookList.prototype.sessions_loaded = function(data){
|
||||
this.sessions = {};
|
||||
var len = data.length;
|
||||
if (len > 0) {
|
||||
for (var i=0; i<len; i++) {
|
||||
var nb_path;
|
||||
if (!data[i].notebook.path) {
|
||||
nb_path = data[i].notebook.name;
|
||||
}
|
||||
else {
|
||||
nb_path = utils.url_path_join(
|
||||
data[i].notebook.path,
|
||||
data[i].notebook.name
|
||||
);
|
||||
}
|
||||
this.sessions[nb_path] = data[i].id;
|
||||
}
|
||||
}
|
||||
this.sessions = data;
|
||||
this.load_list();
|
||||
};
|
||||
|
||||
|
59
IPython/html/static/tree/js/sessionlist.js
Normal file
59
IPython/html/static/tree/js/sessionlist.js
Normal file
@ -0,0 +1,59 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (C) 2014 The IPython Development Team
|
||||
//
|
||||
// Distributed under the terms of the BSD License. The full license is in
|
||||
// the file COPYING, distributed as part of this software.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//============================================================================
|
||||
// Running Kernels List
|
||||
//============================================================================
|
||||
|
||||
var IPython = (function (IPython) {
|
||||
"use strict";
|
||||
|
||||
var utils = IPython.utils;
|
||||
|
||||
var SesssionList = function (options) {
|
||||
this.sessions = {};
|
||||
this.base_url = options.base_url || utils.get_body_data("baseUrl");
|
||||
};
|
||||
|
||||
SesssionList.prototype.load_sessions = function(){
|
||||
var that = this;
|
||||
var settings = {
|
||||
processData : false,
|
||||
cache : false,
|
||||
type : "GET",
|
||||
dataType : "json",
|
||||
success : $.proxy(that.sessions_loaded, this)
|
||||
};
|
||||
var url = utils.url_join_encode(this.base_url, 'api/sessions');
|
||||
$.ajax(url,settings);
|
||||
};
|
||||
|
||||
SesssionList.prototype.sessions_loaded = function(data){
|
||||
this.sessions = {};
|
||||
var len = data.length;
|
||||
if (len > 0) {
|
||||
for (var i=0; i<len; i++) {
|
||||
var nb_path;
|
||||
if (!data[i].notebook.path) {
|
||||
nb_path = data[i].notebook.name;
|
||||
}
|
||||
else {
|
||||
nb_path = utils.url_path_join(
|
||||
data[i].notebook.path,
|
||||
data[i].notebook.name
|
||||
);
|
||||
}
|
||||
this.sessions[nb_path] = data[i].id;
|
||||
}
|
||||
}
|
||||
$([IPython.events]).trigger('sessions_loaded.Dashboard', this.sessions);
|
||||
};
|
||||
IPython.SesssionList = SesssionList;
|
||||
|
||||
return IPython;
|
||||
|
||||
}(IPython));
|
@ -115,6 +115,7 @@ data-base-kernel-url="{{base_kernel_url}}"
|
||||
{{super()}}
|
||||
<script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{static_url("tree/js/sessionlist.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{static_url("tree/js/notebooklist.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{static_url("tree/js/kernellist.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="{{static_url("tree/js/clusterlist.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user