Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
// Copyright (c) IPython Development Team.
2
// Distributed under the terms of the Modified BSD License.
3
4
require([
5
'jquery',
6
'base/js/namespace',
7
'base/js/dialog',
8
'base/js/events',
9
'base/js/page',
10
'base/js/utils',
11
'services/config',
12
'contents',
13
'tree/js/notebooklist',
14
'tree/js/clusterlist',
15
'tree/js/sessionlist',
16
'tree/js/kernellist',
17
'tree/js/terminallist',
18
'tree/js/newnotebook',
19
'auth/js/loginwidget',
20
// only loaded, not used:
21
'jqueryui',
22
'bootstrap',
23
'custom/custom',
24
], function(
25
$,
26
IPython,
27
dialog,
28
events,
29
page,
30
utils,
31
config,
32
contents_service,
33
notebooklist,
34
clusterlist,
35
sesssionlist,
36
kernellist,
37
terminallist,
38
newnotebook,
39
loginwidget){
40
"use strict";
41
42
page = new page.Page();
43
44
var common_options = {
45
base_url: utils.get_body_data("baseUrl"),
46
notebook_path: utils.get_body_data("notebookPath"),
47
};
48
var cfg = new config.ConfigSection('tree', common_options);
49
cfg.load();
50
common_options.config = cfg;
51
var common_config = new config.ConfigSection('common', common_options);
52
common_config.load();
53
54
var session_list = new sesssionlist.SesssionList($.extend({
55
events: events},
56
common_options));
57
var contents = new contents_service.Contents({
58
base_url: common_options.base_url,
59
common_config: common_config
60
});
61
var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
62
contents: contents,
63
session_list: session_list},
64
common_options));
65
var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
66
var kernel_list = new kernellist.KernelList('#running_list', $.extend({
67
session_list: session_list},
68
common_options));
69
70
var terminal_list;
71
if (utils.get_body_data("terminalsAvailable") === "True") {
72
terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
73
}
74
75
var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
76
77
var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons",
78
$.extend(
79
{contents: contents},
80
common_options
81
)
82
);
83
84
var interval_id=0;
85
// auto refresh every xx secondes, no need to be fast,
86
// update is done most of the time when page get focus
87
IPython.tree_time_refresh = 60; // in sec
88
89
// limit refresh on focus at 1/10sec, otherwise this
90
// can cause too frequent refresh on switching through windows or tabs.
91
IPython.min_delta_refresh = 10; // in sec
92
93
var _last_refresh = null;
94
95
var _refresh_list = function(){
96
_last_refresh = new Date();
97
session_list.load_sessions();
98
cluster_list.load_list();
99
if (terminal_list) {
100
terminal_list.load_terminals();
101
}
102
};
103
104
var enable_autorefresh = function(){
105
/**
106
*refresh immediately , then start interval
107
*/
108
var now = new Date();
109
110
if (now - _last_refresh < IPython.min_delta_refresh*1000){
111
console.log("Reenabling autorefresh too close to last tree refresh, not refreshing immediately again.");
112
} else {
113
_refresh_list();
114
}
115
if (!interval_id){
116
interval_id = setInterval(_refresh_list,
117
IPython.tree_time_refresh*1000
118
);
119
}
120
};
121
122
var disable_autorefresh = function(){
123
clearInterval(interval_id);
124
interval_id = 0;
125
};
126
127
// stop autorefresh when page lose focus
128
$(window).blur(function() {
129
disable_autorefresh();
130
});
131
132
//re-enable when page get focus back
133
$(window).focus(function() {
134
enable_autorefresh();
135
});
136
137
// finally start it, it will refresh immediately
138
enable_autorefresh();
139
140
page.show();
141
142
// For backwards compatability.
143
IPython.page = page;
144
IPython.notebook_list = notebook_list;
145
IPython.cluster_list = cluster_list;
146
IPython.session_list = session_list;
147
IPython.kernel_list = kernel_list;
148
IPython.login_widget = login_widget;
149
IPython.new_notebook_widget = new_buttons;
150
151
events.trigger('app_initialized.DashboardApp');
152
utils.load_extensions_from_config(cfg);
153
utils.load_extensions_from_config(common_config);
154
155
// bound the upload method to the on change of the file select list
156
$("#alternate_upload").change(function (event){
157
notebook_list.handleFilesUpload(event,'form');
158
});
159
160
// set hash on tab click
161
$("#tabs").find("a").click(function(e) {
162
// Prevent the document from jumping when the active tab is changed to a
163
// tab that has a lot of content.
164
e.preventDefault();
165
166
// Set the hash without causing the page to jump.
167
// http://stackoverflow.com/a/14690177/2824256
168
var hash = $(this).attr("href");
169
if(window.history.pushState) {
170
window.history.pushState(null, null, hash);
171
} else {
172
window.location.hash = hash;
173
}
174
});
175
176
// load tab if url hash
177
if (window.location.hash) {
178
$("#tabs").find("a[href=" + window.location.hash + "]").click();
179
}
180
});
181
182