From b74b10e308ff96056a2c73b8ce4830a4e76e9a28 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Tue, 25 Feb 2014 18:09:16 -0800 Subject: [PATCH] added IPython.session_list before this, kernel_list and notebook_list each fetched and held onto their own copy of the sessions. --- IPython/html/static/tree/js/kernellist.js | 14 +++-- IPython/html/static/tree/js/main.js | 7 ++- IPython/html/static/tree/js/notebooklist.js | 32 ++--------- IPython/html/static/tree/js/sessionlist.js | 59 +++++++++++++++++++++ IPython/html/templates/tree.html | 1 + 5 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 IPython/html/static/tree/js/sessionlist.js diff --git a/IPython/html/static/tree/js/kernellist.js b/IPython/html/static/tree/js/kernellist.js index 7177d921f..d52e09c97 100644 --- a/IPython/html/static/tree/js/kernellist.js +++ b/IPython/html/static/tree/js/kernellist.js @@ -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(); } } diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index ee48102f9..92e400d14 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -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); diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index c6da89b9c..4b86310f5 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -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 0) { + for (var i=0; i +