##// END OF EJS Templates
Merge pull request #7626 from Carreau/refresh-rate...
Min RK -
r20315:7c34f17e merge
parent child Browse files
Show More
@@ -1,166 +1,179 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 require([
4 require([
5 'jquery',
5 'jquery',
6 'base/js/namespace',
6 'base/js/namespace',
7 'base/js/dialog',
7 'base/js/dialog',
8 'base/js/events',
8 'base/js/events',
9 'base/js/page',
9 'base/js/page',
10 'base/js/utils',
10 'base/js/utils',
11 'services/config',
11 'services/config',
12 'contents',
12 'contents',
13 'tree/js/notebooklist',
13 'tree/js/notebooklist',
14 'tree/js/clusterlist',
14 'tree/js/clusterlist',
15 'tree/js/sessionlist',
15 'tree/js/sessionlist',
16 'tree/js/kernellist',
16 'tree/js/kernellist',
17 'tree/js/terminallist',
17 'tree/js/terminallist',
18 'tree/js/newnotebook',
18 'tree/js/newnotebook',
19 'auth/js/loginwidget',
19 'auth/js/loginwidget',
20 // only loaded, not used:
20 // only loaded, not used:
21 'jqueryui',
21 'jqueryui',
22 'bootstrap',
22 'bootstrap',
23 'custom/custom',
23 'custom/custom',
24 ], function(
24 ], function(
25 $,
25 $,
26 IPython,
26 IPython,
27 dialog,
27 dialog,
28 events,
28 events,
29 page,
29 page,
30 utils,
30 utils,
31 config,
31 config,
32 contents_service,
32 contents_service,
33 notebooklist,
33 notebooklist,
34 clusterlist,
34 clusterlist,
35 sesssionlist,
35 sesssionlist,
36 kernellist,
36 kernellist,
37 terminallist,
37 terminallist,
38 newnotebook,
38 newnotebook,
39 loginwidget){
39 loginwidget){
40 "use strict";
40 "use strict";
41
41
42 page = new page.Page();
42 page = new page.Page();
43
43
44 var common_options = {
44 var common_options = {
45 base_url: utils.get_body_data("baseUrl"),
45 base_url: utils.get_body_data("baseUrl"),
46 notebook_path: utils.get_body_data("notebookPath"),
46 notebook_path: utils.get_body_data("notebookPath"),
47 };
47 };
48 var cfg = new config.ConfigSection('tree', common_options);
48 var cfg = new config.ConfigSection('tree', common_options);
49 cfg.load();
49 cfg.load();
50 common_options.config = cfg;
50 common_options.config = cfg;
51 var common_config = new config.ConfigSection('common', common_options);
51 var common_config = new config.ConfigSection('common', common_options);
52 common_config.load();
52 common_config.load();
53
53
54 var session_list = new sesssionlist.SesssionList($.extend({
54 var session_list = new sesssionlist.SesssionList($.extend({
55 events: events},
55 events: events},
56 common_options));
56 common_options));
57 var contents = new contents_service.Contents($.extend({
57 var contents = new contents_service.Contents($.extend({
58 events: events},
58 events: events},
59 common_options));
59 common_options));
60 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
60 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
61 contents: contents,
61 contents: contents,
62 session_list: session_list},
62 session_list: session_list},
63 common_options));
63 common_options));
64 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
64 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
65 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
65 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
66 session_list: session_list},
66 session_list: session_list},
67 common_options));
67 common_options));
68
68
69 var terminal_list;
69 var terminal_list;
70 if (utils.get_body_data("terminalsAvailable") === "True") {
70 if (utils.get_body_data("terminalsAvailable") === "True") {
71 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
71 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
72 }
72 }
73
73
74 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
74 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
75
75
76 var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons",
76 var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons",
77 $.extend(
77 $.extend(
78 {contents: contents},
78 {contents: contents},
79 common_options
79 common_options
80 )
80 )
81 );
81 );
82
82
83 var interval_id=0;
83 var interval_id=0;
84 // auto refresh every xx secondes, no need to be fast,
84 // auto refresh every xx secondes, no need to be fast,
85 // update is done at least when page get focus
85 // update is done most of the time when page get focus
86 var time_refresh = 60; // in sec
86 IPython.tree_time_refresh = 60; // in sec
87
87
88 var enable_autorefresh = function(){
88 // limit refresh on focus at 1/10sec, otherwise this
89 /**
89 // can cause too frequent refresh on switching through windows or tabs.
90 *refresh immediately , then start interval
90 IPython.min_delta_refresh = 10; // in sec
91 */
91
92 var _last_refresh = null;
93
94 var _refresh_list = function(){
95 _last_refresh = new Date();
92 session_list.load_sessions();
96 session_list.load_sessions();
93 cluster_list.load_list();
97 cluster_list.load_list();
94 if (terminal_list) {
98 if (terminal_list) {
95 terminal_list.load_terminals();
99 terminal_list.load_terminals();
96 }
100 }
101 }
102
103 var enable_autorefresh = function(){
104 /**
105 *refresh immediately , then start interval
106 */
107 var now = new Date()
108
109 if (now - _last_refresh < IPython.min_delta_refresh*1000){
110 console.log("Reenabling autorefresh too close to last tree refresh, not refreshing immediately again.")
111 } else {
112 _refresh_list();
113 }
97 if (!interval_id){
114 if (!interval_id){
98 interval_id = setInterval(function(){
115 interval_id = setInterval(_refresh_list,
99 session_list.load_sessions();
116 IPython.tree_time_refresh*1000
100 cluster_list.load_list();
117 );
101 if (terminal_list) {
102 terminal_list.load_terminals();
103 }
104 }, time_refresh*1000);
105 }
118 }
106 };
119 };
107
120
108 var disable_autorefresh = function(){
121 var disable_autorefresh = function(){
109 clearInterval(interval_id);
122 clearInterval(interval_id);
110 interval_id = 0;
123 interval_id = 0;
111 };
124 };
112
125
113 // stop autorefresh when page lose focus
126 // stop autorefresh when page lose focus
114 $(window).blur(function() {
127 $(window).blur(function() {
115 disable_autorefresh();
128 disable_autorefresh();
116 });
129 });
117
130
118 //re-enable when page get focus back
131 //re-enable when page get focus back
119 $(window).focus(function() {
132 $(window).focus(function() {
120 enable_autorefresh();
133 enable_autorefresh();
121 });
134 });
122
135
123 // finally start it, it will refresh immediately
136 // finally start it, it will refresh immediately
124 enable_autorefresh();
137 enable_autorefresh();
125
138
126 page.show();
139 page.show();
127
140
128 // For backwards compatability.
141 // For backwards compatability.
129 IPython.page = page;
142 IPython.page = page;
130 IPython.notebook_list = notebook_list;
143 IPython.notebook_list = notebook_list;
131 IPython.cluster_list = cluster_list;
144 IPython.cluster_list = cluster_list;
132 IPython.session_list = session_list;
145 IPython.session_list = session_list;
133 IPython.kernel_list = kernel_list;
146 IPython.kernel_list = kernel_list;
134 IPython.login_widget = login_widget;
147 IPython.login_widget = login_widget;
135 IPython.new_notebook_widget = new_buttons;
148 IPython.new_notebook_widget = new_buttons;
136
149
137 events.trigger('app_initialized.DashboardApp');
150 events.trigger('app_initialized.DashboardApp');
138 utils.load_extensions_from_config(cfg);
151 utils.load_extensions_from_config(cfg);
139 utils.load_extensions_from_config(common_config);
152 utils.load_extensions_from_config(common_config);
140
153
141 // bound the upload method to the on change of the file select list
154 // bound the upload method to the on change of the file select list
142 $("#alternate_upload").change(function (event){
155 $("#alternate_upload").change(function (event){
143 notebook_list.handleFilesUpload(event,'form');
156 notebook_list.handleFilesUpload(event,'form');
144 });
157 });
145
158
146 // set hash on tab click
159 // set hash on tab click
147 $("#tabs").find("a").click(function(e) {
160 $("#tabs").find("a").click(function(e) {
148 // Prevent the document from jumping when the active tab is changed to a
161 // Prevent the document from jumping when the active tab is changed to a
149 // tab that has a lot of content.
162 // tab that has a lot of content.
150 e.preventDefault();
163 e.preventDefault();
151
164
152 // Set the hash without causing the page to jump.
165 // Set the hash without causing the page to jump.
153 // http://stackoverflow.com/a/14690177/2824256
166 // http://stackoverflow.com/a/14690177/2824256
154 var hash = $(this).attr("href");
167 var hash = $(this).attr("href");
155 if(window.history.pushState) {
168 if(window.history.pushState) {
156 window.history.pushState(null, null, hash);
169 window.history.pushState(null, null, hash);
157 } else {
170 } else {
158 window.location.hash = hash;
171 window.location.hash = hash;
159 }
172 }
160 });
173 });
161
174
162 // load tab if url hash
175 // load tab if url hash
163 if (window.location.hash) {
176 if (window.location.hash) {
164 $("#tabs").find("a[href=" + window.location.hash + "]").click();
177 $("#tabs").find("a[href=" + window.location.hash + "]").click();
165 }
178 }
166 });
179 });
General Comments 0
You need to be logged in to leave comments. Login now