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