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