main.js
162 lines
| 4.5 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r17189 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
Jonathan Frederic
|
r17193 | require([ | ||
Jonathan Frederic
|
r17200 | 'jquery', | ||
Min RK
|
r18752 | 'base/js/namespace', | ||
'base/js/dialog', | ||||
Jonathan Frederic
|
r17195 | 'base/js/events', | ||
Jonathan Frederic
|
r17189 | 'base/js/page', | ||
'base/js/utils', | ||||
Min RK
|
r19264 | 'services/config', | ||
Jeff Hemmelgarn
|
r18643 | 'contents', | ||
Jonathan Frederic
|
r17189 | 'tree/js/notebooklist', | ||
'tree/js/clusterlist', | ||||
'tree/js/sessionlist', | ||||
'tree/js/kernellist', | ||||
Thomas Kluyver
|
r18555 | 'tree/js/terminallist', | ||
Min RK
|
r19260 | 'tree/js/newnotebook', | ||
Jonathan Frederic
|
r17189 | 'auth/js/loginwidget', | ||
MinRK
|
r17323 | // only loaded, not used: | ||
MinRK
|
r17312 | 'jqueryui', | ||
'bootstrap', | ||||
Jason Grout
|
r17319 | 'custom/custom', | ||
Jonathan Frederic
|
r17189 | ], function( | ||
Min RK
|
r18752 | $, | ||
IPython, | ||||
dialog, | ||||
Jonathan Frederic
|
r17202 | events, | ||
Min RK
|
r18752 | page, | ||
utils, | ||||
Min RK
|
r19264 | config, | ||
Min RK
|
r18752 | contents_service, | ||
Min RK
|
r19260 | notebooklist, | ||
clusterlist, | ||||
sesssionlist, | ||||
Thomas Kluyver
|
r18555 | kernellist, | ||
terminallist, | ||||
Min RK
|
r19260 | newnotebook, | ||
Jonathan Frederic
|
r17202 | loginwidget){ | ||
Min RK
|
r18752 | "use strict"; | ||
Brian E. Granger
|
r4488 | |||
Jonathan Frederic
|
r17202 | page = new page.Page(); | ||
jon
|
r17210 | var common_options = { | ||
Jonathan Frederic
|
r17198 | base_url: utils.get_body_data("baseUrl"), | ||
notebook_path: utils.get_body_data("notebookPath"), | ||||
Jonathan Frederic
|
r17189 | }; | ||
Min RK
|
r19264 | var cfg = new config.ConfigSection('tree', common_options); | ||
cfg.load(); | ||||
common_options.config = cfg; | ||||
Min RK
|
r18752 | var session_list = new sesssionlist.SesssionList($.extend({ | ||
jon
|
r17210 | events: events}, | ||
common_options)); | ||||
Min RK
|
r18752 | var contents = new contents_service.Contents($.extend({ | ||
KesterTong
|
r18624 | events: events}, | ||
common_options)); | ||||
Min RK
|
r18752 | var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ | ||
Jeff Hemmelgarn
|
r18643 | contents: contents, | ||
jon
|
r17210 | session_list: session_list}, | ||
common_options)); | ||||
Min RK
|
r18752 | var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); | ||
var kernel_list = new kernellist.KernelList('#running_list', $.extend({ | ||||
jon
|
r17210 | session_list: session_list}, | ||
common_options)); | ||||
Thomas Kluyver
|
r18557 | |||
Min RK
|
r18752 | var terminal_list; | ||
Thomas Kluyver
|
r18557 | if (utils.get_body_data("terminalsAvailable") === "True") { | ||
terminal_list = new terminallist.TerminalList('#terminal_list', common_options); | ||||
} | ||||
Min RK
|
r18752 | var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); | ||
Zachary Sailer
|
r13016 | |||
Jonathan Frederic
|
r19694 | var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons", | ||
Min RK
|
r19260 | $.extend( | ||
{contents: contents}, | ||||
common_options | ||||
) | ||||
); | ||||
Jonathan Frederic
|
r17202 | |||
Matthias BUSSONNIER
|
r6844 | var interval_id=0; | ||
// auto refresh every xx secondes, no need to be fast, | ||||
// update is done at least when page get focus | ||||
var time_refresh = 60; // in sec | ||||
var enable_autorefresh = function(){ | ||||
Jonathan Frederic
|
r19176 | /** | ||
*refresh immediately , then start interval | ||||
*/ | ||||
Jeffrey Bush
|
r17651 | session_list.load_sessions(); | ||
cluster_list.load_list(); | ||||
Min RK
|
r19266 | if (terminal_list) { | ||
terminal_list.load_terminals(); | ||||
} | ||||
Matthias BUSSONNIER
|
r6844 | if (!interval_id){ | ||
interval_id = setInterval(function(){ | ||||
Min RK
|
r19266 | session_list.load_sessions(); | ||
cluster_list.load_list(); | ||||
if (terminal_list) { | ||||
terminal_list.load_terminals(); | ||||
} | ||||
}, time_refresh*1000); | ||||
} | ||||
Jonathan Frederic
|
r17189 | }; | ||
Matthias BUSSONNIER
|
r6844 | |||
var disable_autorefresh = function(){ | ||||
clearInterval(interval_id); | ||||
interval_id = 0; | ||||
Jonathan Frederic
|
r17189 | }; | ||
Matthias BUSSONNIER
|
r6844 | |||
// stop autorefresh when page lose focus | ||||
$(window).blur(function() { | ||||
disable_autorefresh(); | ||||
Jonathan Frederic
|
r17189 | }); | ||
Matthias BUSSONNIER
|
r6844 | |||
//re-enable when page get focus back | ||||
$(window).focus(function() { | ||||
enable_autorefresh(); | ||||
}); | ||||
// finally start it, it will refresh immediately | ||||
enable_autorefresh(); | ||||
Jonathan Frederic
|
r17189 | page.show(); | ||
Jason Grout
|
r17319 | |||
// For backwards compatability. | ||||
IPython.page = page; | ||||
IPython.notebook_list = notebook_list; | ||||
IPython.cluster_list = cluster_list; | ||||
IPython.session_list = session_list; | ||||
IPython.kernel_list = kernel_list; | ||||
IPython.login_widget = login_widget; | ||||
Jonathan Frederic
|
r19694 | IPython.new_notebook_widget = new_buttons; | ||
Jason Grout
|
r17319 | |||
Jonathan Frederic
|
r17189 | events.trigger('app_initialized.DashboardApp'); | ||
Matthias BUSSONNIER
|
r6838 | // bound the upload method to the on change of the file select list | ||
$("#alternate_upload").change(function (event){ | ||||
Jonathan Frederic
|
r17189 | notebook_list.handleFilesUpload(event,'form'); | ||
Matthias BUSSONNIER
|
r6838 | }); | ||
MinRK
|
r10927 | |||
// set hash on tab click | ||||
Jonathan Frederic
|
r19575 | $("#tabs").find("a").click(function(e) { | ||
// Prevent the document from jumping when the active tab is changed to a | ||||
// tab that has a lot of content. | ||||
e.preventDefault(); | ||||
// Set the hash without causing the page to jump. | ||||
// http://stackoverflow.com/a/14690177/2824256 | ||||
var hash = $(this).attr("href"); | ||||
if(window.history.pushState) { | ||||
window.history.pushState(null, null, hash); | ||||
} else { | ||||
window.location.hash = hash; | ||||
} | ||||
Jonathan Frederic
|
r17189 | }); | ||
MinRK
|
r10927 | |||
// load tab if url hash | ||||
if (window.location.hash) { | ||||
$("#tabs").find("a[href=" + window.location.hash + "]").click(); | ||||
} | ||||
Brian E. Granger
|
r4488 | }); | ||