main.js
148 lines
| 4.4 KiB
| application/javascript
|
JavascriptLexer
|
r17189 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
|
r17193 | require([ | ||
|
r17200 | 'jquery', | ||
|
r18752 | 'base/js/namespace', | ||
'base/js/dialog', | ||||
|
r17195 | 'base/js/events', | ||
|
r17189 | 'base/js/page', | ||
'base/js/utils', | ||||
|
r18643 | 'contents', | ||
|
r17189 | 'tree/js/notebooklist', | ||
'tree/js/clusterlist', | ||||
'tree/js/sessionlist', | ||||
'tree/js/kernellist', | ||||
|
r18555 | 'tree/js/terminallist', | ||
|
r17189 | 'auth/js/loginwidget', | ||
|
r17323 | // only loaded, not used: | ||
|
r17312 | 'jqueryui', | ||
'bootstrap', | ||||
|
r17319 | 'custom/custom', | ||
|
r17189 | ], function( | ||
|
r18752 | $, | ||
IPython, | ||||
dialog, | ||||
|
r17202 | events, | ||
|
r18752 | page, | ||
utils, | ||||
contents_service, | ||||
|
r17202 | notebooklist, | ||
clusterlist, | ||||
sesssionlist, | ||||
|
r18555 | kernellist, | ||
terminallist, | ||||
|
r17202 | loginwidget){ | ||
|
r18752 | "use strict"; | ||
|
r4488 | |||
|
r17202 | page = new page.Page(); | ||
|
r17210 | var common_options = { | ||
|
r17198 | base_url: utils.get_body_data("baseUrl"), | ||
notebook_path: utils.get_body_data("notebookPath"), | ||||
|
r17189 | }; | ||
|
r18752 | var session_list = new sesssionlist.SesssionList($.extend({ | ||
|
r17210 | events: events}, | ||
common_options)); | ||||
|
r18752 | var contents = new contents_service.Contents($.extend({ | ||
|
r18624 | events: events}, | ||
common_options)); | ||||
|
r18752 | var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ | ||
|
r18643 | contents: contents, | ||
|
r17210 | session_list: session_list}, | ||
common_options)); | ||||
|
r18752 | var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); | ||
var kernel_list = new kernellist.KernelList('#running_list', $.extend({ | ||||
|
r17210 | session_list: session_list}, | ||
common_options)); | ||||
|
r18557 | |||
|
r18752 | var terminal_list; | ||
|
r18557 | if (utils.get_body_data("terminalsAvailable") === "True") { | ||
terminal_list = new terminallist.TerminalList('#terminal_list', common_options); | ||||
} | ||||
|
r18752 | var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); | ||
|
r13016 | |||
|
r18659 | $('#new_notebook').click(function (e) { | ||
|
r18760 | contents.new_untitled(common_options.notebook_path, { | ||
|
r18758 | type: "notebook", | ||
|
r18681 | extra_settings: {async: false}, // So we can open a new window afterwards | ||
|
r18661 | success: function (data) { | ||
|
r18649 | window.open( | ||
utils.url_join_encode( | ||||
common_options.base_url, 'notebooks', | ||||
|
r18752 | data.path | ||
|
r18649 | ), '_blank'); | ||
}, | ||||
|
r18661 | error: function(error) { | ||
|
r18649 | dialog.modal({ | ||
title : 'Creating Notebook Failed', | ||||
|
r18661 | body : "The error was: " + error.message, | ||
|
r18649 | buttons : {'OK' : {'class' : 'btn-primary'}} | ||
}); | ||||
} | ||||
}); | ||||
|
r13016 | }); | ||
|
r17202 | |||
|
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(){ | ||||
//refresh immediately , then start interval | ||||
|
r17651 | session_list.load_sessions(); | ||
cluster_list.load_list(); | ||||
|
r6844 | if (!interval_id){ | ||
interval_id = setInterval(function(){ | ||||
|
r17651 | session_list.load_sessions(); | ||
cluster_list.load_list(); | ||||
|
r6844 | }, time_refresh*1000); | ||
} | ||||
|
r17189 | }; | ||
|
r6844 | |||
var disable_autorefresh = function(){ | ||||
clearInterval(interval_id); | ||||
interval_id = 0; | ||||
|
r17189 | }; | ||
|
r6844 | |||
// stop autorefresh when page lose focus | ||||
$(window).blur(function() { | ||||
disable_autorefresh(); | ||||
|
r17189 | }); | ||
|
r6844 | |||
//re-enable when page get focus back | ||||
$(window).focus(function() { | ||||
enable_autorefresh(); | ||||
}); | ||||
// finally start it, it will refresh immediately | ||||
enable_autorefresh(); | ||||
|
r17189 | page.show(); | ||
|
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; | ||||
|
r17189 | events.trigger('app_initialized.DashboardApp'); | ||
|
r6838 | // bound the upload method to the on change of the file select list | ||
$("#alternate_upload").change(function (event){ | ||||
|
r17189 | notebook_list.handleFilesUpload(event,'form'); | ||
|
r6838 | }); | ||
|
r10927 | |||
// set hash on tab click | ||||
$("#tabs").find("a").click(function() { | ||||
window.location.hash = $(this).attr("href"); | ||||
|
r17189 | }); | ||
|
r10927 | |||
// load tab if url hash | ||||
if (window.location.hash) { | ||||
$("#tabs").find("a[href=" + window.location.hash + "]").click(); | ||||
} | ||||
|
r4488 | }); | ||