##// END OF EJS Templates
Refresh terminal list. closes #7018 .
Osada Paranaliyanage -
Show More
@@ -1,146 +1,152 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 'contents',
11 'contents',
12 'tree/js/notebooklist',
12 'tree/js/notebooklist',
13 'tree/js/clusterlist',
13 'tree/js/clusterlist',
14 'tree/js/sessionlist',
14 'tree/js/sessionlist',
15 'tree/js/kernellist',
15 'tree/js/kernellist',
16 'tree/js/terminallist',
16 'tree/js/terminallist',
17 'auth/js/loginwidget',
17 'auth/js/loginwidget',
18 // only loaded, not used:
18 // only loaded, not used:
19 'jqueryui',
19 'jqueryui',
20 'bootstrap',
20 'bootstrap',
21 'custom/custom',
21 'custom/custom',
22 ], function(
22 ], function(
23 $,
23 $,
24 IPython,
24 IPython,
25 dialog,
25 dialog,
26 events,
26 events,
27 page,
27 page,
28 utils,
28 utils,
29 contents_service,
29 contents_service,
30 notebooklist,
30 notebooklist,
31 clusterlist,
31 clusterlist,
32 sesssionlist,
32 sesssionlist,
33 kernellist,
33 kernellist,
34 terminallist,
34 terminallist,
35 loginwidget){
35 loginwidget){
36 "use strict";
36 "use strict";
37
37
38 page = new page.Page();
38 page = new page.Page();
39
39
40 var common_options = {
40 var common_options = {
41 base_url: utils.get_body_data("baseUrl"),
41 base_url: utils.get_body_data("baseUrl"),
42 notebook_path: utils.get_body_data("notebookPath"),
42 notebook_path: utils.get_body_data("notebookPath"),
43 };
43 };
44 var session_list = new sesssionlist.SesssionList($.extend({
44 var session_list = new sesssionlist.SesssionList($.extend({
45 events: events},
45 events: events},
46 common_options));
46 common_options));
47 var contents = new contents_service.Contents($.extend({
47 var contents = new contents_service.Contents($.extend({
48 events: events},
48 events: events},
49 common_options));
49 common_options));
50 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
50 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
51 contents: contents,
51 contents: contents,
52 session_list: session_list},
52 session_list: session_list},
53 common_options));
53 common_options));
54 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
54 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
55 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
55 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
56 session_list: session_list},
56 session_list: session_list},
57 common_options));
57 common_options));
58
58
59 var terminal_list;
59 var terminal_list;
60 if (utils.get_body_data("terminalsAvailable") === "True") {
60 if (utils.get_body_data("terminalsAvailable") === "True") {
61 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
61 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
62 }
62 }
63
63
64 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
64 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
65
65
66 $('#new_notebook').click(function (e) {
66 $('#new_notebook').click(function (e) {
67 var w = window.open();
67 var w = window.open();
68 contents.new_untitled(common_options.notebook_path, {type: "notebook"}).then(
68 contents.new_untitled(common_options.notebook_path, {type: "notebook"}).then(
69 function (data) {
69 function (data) {
70 w.location = utils.url_join_encode(
70 w.location = utils.url_join_encode(
71 common_options.base_url, 'notebooks', data.path
71 common_options.base_url, 'notebooks', data.path
72 );
72 );
73 },
73 },
74 function(error) {
74 function(error) {
75 w.close();
75 w.close();
76 dialog.modal({
76 dialog.modal({
77 title : 'Creating Notebook Failed',
77 title : 'Creating Notebook Failed',
78 body : "The error was: " + error.message,
78 body : "The error was: " + error.message,
79 buttons : {'OK' : {'class' : 'btn-primary'}}
79 buttons : {'OK' : {'class' : 'btn-primary'}}
80 });
80 });
81 }
81 }
82 );
82 );
83 });
83 });
84
84
85 var interval_id=0;
85 var interval_id=0;
86 // auto refresh every xx secondes, no need to be fast,
86 // auto refresh every xx secondes, no need to be fast,
87 // update is done at least when page get focus
87 // update is done at least when page get focus
88 var time_refresh = 60; // in sec
88 var time_refresh = 60; // in sec
89
89
90 var enable_autorefresh = function(){
90 var enable_autorefresh = function(){
91 //refresh immediately , then start interval
91 //refresh immediately , then start interval
92 session_list.load_sessions();
92 session_list.load_sessions();
93 cluster_list.load_list();
93 cluster_list.load_list();
94 if (terminal_list) {
95 terminal_list.load_terminals();
96 }
94 if (!interval_id){
97 if (!interval_id){
95 interval_id = setInterval(function(){
98 interval_id = setInterval(function(){
96 session_list.load_sessions();
99 session_list.load_sessions();
97 cluster_list.load_list();
100 cluster_list.load_list();
101 if (terminal_list) {
102 terminal_list.load_terminals();
103 }
98 }, time_refresh*1000);
104 }, time_refresh*1000);
99 }
105 }
100 };
106 };
101
107
102 var disable_autorefresh = function(){
108 var disable_autorefresh = function(){
103 clearInterval(interval_id);
109 clearInterval(interval_id);
104 interval_id = 0;
110 interval_id = 0;
105 };
111 };
106
112
107 // stop autorefresh when page lose focus
113 // stop autorefresh when page lose focus
108 $(window).blur(function() {
114 $(window).blur(function() {
109 disable_autorefresh();
115 disable_autorefresh();
110 });
116 });
111
117
112 //re-enable when page get focus back
118 //re-enable when page get focus back
113 $(window).focus(function() {
119 $(window).focus(function() {
114 enable_autorefresh();
120 enable_autorefresh();
115 });
121 });
116
122
117 // finally start it, it will refresh immediately
123 // finally start it, it will refresh immediately
118 enable_autorefresh();
124 enable_autorefresh();
119
125
120 page.show();
126 page.show();
121
127
122 // For backwards compatability.
128 // For backwards compatability.
123 IPython.page = page;
129 IPython.page = page;
124 IPython.notebook_list = notebook_list;
130 IPython.notebook_list = notebook_list;
125 IPython.cluster_list = cluster_list;
131 IPython.cluster_list = cluster_list;
126 IPython.session_list = session_list;
132 IPython.session_list = session_list;
127 IPython.kernel_list = kernel_list;
133 IPython.kernel_list = kernel_list;
128 IPython.login_widget = login_widget;
134 IPython.login_widget = login_widget;
129
135
130 events.trigger('app_initialized.DashboardApp');
136 events.trigger('app_initialized.DashboardApp');
131
137
132 // bound the upload method to the on change of the file select list
138 // bound the upload method to the on change of the file select list
133 $("#alternate_upload").change(function (event){
139 $("#alternate_upload").change(function (event){
134 notebook_list.handleFilesUpload(event,'form');
140 notebook_list.handleFilesUpload(event,'form');
135 });
141 });
136
142
137 // set hash on tab click
143 // set hash on tab click
138 $("#tabs").find("a").click(function() {
144 $("#tabs").find("a").click(function() {
139 window.location.hash = $(this).attr("href");
145 window.location.hash = $(this).attr("href");
140 });
146 });
141
147
142 // load tab if url hash
148 // load tab if url hash
143 if (window.location.hash) {
149 if (window.location.hash) {
144 $("#tabs").find("a[href=" + window.location.hash + "]").click();
150 $("#tabs").find("a[href=" + window.location.hash + "]").click();
145 }
151 }
146 });
152 });
General Comments 0
You need to be logged in to leave comments. Login now