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