From fc59441ddae3474cadffec1cd01df88d78efc2b6 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 29 Apr 2012 19:41:06 +0200 Subject: [PATCH] dashboard autorefresh refresh notebook list and cluster list when : - page get focus - every 60 sec when page is on focus stop refreshing every 60 sec when page loose focus --- .../static/js/projectdashboardmain.js | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/projectdashboardmain.js b/IPython/frontend/html/notebook/static/js/projectdashboardmain.js index 5957210a6..dbf9917d6 100644 --- a/IPython/frontend/html/notebook/static/js/projectdashboardmain.js +++ b/IPython/frontend/html/notebook/static/js/projectdashboardmain.js @@ -30,8 +30,41 @@ $(document).ready(function () { IPython.cluster_list = new IPython.ClusterList('div#cluster_list'); IPython.login_widget = new IPython.LoginWidget('span#login_widget'); - IPython.notebook_list.load_list(); - IPython.cluster_list.load_list(); + var interval_id=0; + // auto refresh every xx secondes, no need to be fast, + // update is done at least when page get focus + var time_refresh = 60; // in sec + + var enable_autorefresh = function(){ + //refresh immediately , then start interval + IPython.notebook_list.load_list(); + IPython.cluster_list.load_list(); + if (!interval_id){ + interval_id = setInterval(function(){ + IPython.notebook_list.load_list(); + IPython.cluster_list.load_list(); + }, time_refresh*1000); + } + } + + var disable_autorefresh = function(){ + clearInterval(interval_id); + interval_id = 0; + } + + // stop autorefresh when page lose focus + $(window).blur(function() { + disable_autorefresh(); + }) + + //re-enable when page get focus back + $(window).focus(function() { + enable_autorefresh(); + }); + + // finally start it, it will refresh immediately + enable_autorefresh(); + IPython.page.show(); // bound the upload method to the on change of the file select list