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