From 5872aa1a28ae8ee70a7fca9e5fb001c2053ae2ee 2014-02-26 02:09:16 From: Paul Ivanov <pi@berkeley.edu> Date: 2014-02-26 02:09:16 Subject: [PATCH] added IPython.session_list before this, kernel_list and notebook_list each fetched and held onto their own copy of the sessions. --- diff --git a/IPython/html/static/tree/js/kernellist.js b/IPython/html/static/tree/js/kernellist.js index 7177d92..d52e09c 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 ee48102..92e400d 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 c6da89b..4b86310 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<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(); }; diff --git a/IPython/html/static/tree/js/sessionlist.js b/IPython/html/static/tree/js/sessionlist.js new file mode 100644 index 0000000..1b4a729 --- /dev/null +++ b/IPython/html/static/tree/js/sessionlist.js @@ -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)); diff --git a/IPython/html/templates/tree.html b/IPython/html/templates/tree.html index fac67bb..589376c 100644 --- a/IPython/html/templates/tree.html +++ b/IPython/html/templates/tree.html @@ -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>