Show More
@@ -0,0 +1,103 b'' | |||
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | ||
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'base/js/utils', | |
|
7 | 'jquery', | |
|
8 | 'tree/js/notebooklist', | |
|
9 | ], function(IPython, utils, $, notebooklist) { | |
|
10 | "use strict"; | |
|
11 | ||
|
12 | var TerminalList = function (selector, options) { | |
|
13 | // Constructor | |
|
14 | // | |
|
15 | // Parameters: | |
|
16 | // selector: string | |
|
17 | // options: dictionary | |
|
18 | // Dictionary of keyword arguments. | |
|
19 | // base_url: string | |
|
20 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |
|
21 | this.element_name = options.element_name || 'terminal'; | |
|
22 | this.selector = selector; | |
|
23 | this.terminals = []; | |
|
24 | if (this.selector !== undefined) { | |
|
25 | this.element = $(selector); | |
|
26 | this.style(); | |
|
27 | this.bind_events(); | |
|
28 | this.load_terminals(); | |
|
29 | } | |
|
30 | }; | |
|
31 | ||
|
32 | TerminalList.prototype = Object.create(notebooklist.NotebookList.prototype); | |
|
33 | ||
|
34 | TerminalList.prototype.bind_events = function () { | |
|
35 | var that = this; | |
|
36 | $('#refresh_' + this.element_name + '_list').click(function () { | |
|
37 | that.load_terminals(); | |
|
38 | }); | |
|
39 | $('#new_terminal').click($.proxy(this.new_terminal, this)); | |
|
40 | }; | |
|
41 | ||
|
42 | TerminalList.prototype.new_terminal = function() { | |
|
43 | var url = utils.url_join_encode(this.base_url, 'terminals/new'); | |
|
44 | window.open(url, '_blank'); | |
|
45 | }; | |
|
46 | ||
|
47 | TerminalList.prototype.load_terminals = function() { | |
|
48 | var that = this; | |
|
49 | var url = utils.url_join_encode(this.base_url, 'api/terminals'); | |
|
50 | $.ajax(url, { | |
|
51 | type: "GET", | |
|
52 | cache: false, | |
|
53 | dataType: "json", | |
|
54 | success: $.proxy(this.terminals_loaded, this), | |
|
55 | error : utils.log_ajax_error | |
|
56 | }); | |
|
57 | }; | |
|
58 | ||
|
59 | TerminalList.prototype.terminals_loaded = function (data) { | |
|
60 | this.terminals = data; | |
|
61 | this.clear_list(); | |
|
62 | var item, path_name, term; | |
|
63 | for (var i=0; i < this.terminals.length; i++) { | |
|
64 | term = this.terminals[i]; | |
|
65 | item = this.new_item(-1); | |
|
66 | this.add_link(term.name, item); | |
|
67 | this.add_shutdown_button(term.name, item); | |
|
68 | } | |
|
69 | $('#terminal_list_header').toggle(data.length === 0); | |
|
70 | }; | |
|
71 | ||
|
72 | TerminalList.prototype.add_link = function(name, item) { | |
|
73 | item.data('term-name', name); | |
|
74 | item.find(".item_name").text("terminals/" + name); | |
|
75 | item.find(".item_icon").addClass("fa fa-terminal"); | |
|
76 | var link = item.find("a.item_link") | |
|
77 | .attr('href', utils.url_join_encode(this.base_url, "terminals", name)); | |
|
78 | link.attr('target', '_blank'); | |
|
79 | this.add_shutdown_button(name, item); | |
|
80 | }; | |
|
81 | ||
|
82 | TerminalList.prototype.add_shutdown_button = function(name, item) { | |
|
83 | var that = this; | |
|
84 | var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-xs btn-danger"). | |
|
85 | click(function (e) { | |
|
86 | var settings = { | |
|
87 | processData : false, | |
|
88 | type : "DELETE", | |
|
89 | dataType : "json", | |
|
90 | success : function () { | |
|
91 | that.load_terminals(); | |
|
92 | }, | |
|
93 | error : utils.log_ajax_error, | |
|
94 | }; | |
|
95 | var url = utils.url_join_encode(that.base_url, 'api/terminals', name); | |
|
96 | $.ajax(url, settings); | |
|
97 | return false; | |
|
98 | }); | |
|
99 | item.find(".item_buttons").text("").append(shutdown_button); | |
|
100 | }; | |
|
101 | ||
|
102 | return {TerminalList: TerminalList}; | |
|
103 | }); |
@@ -173,6 +173,7 b' class NotebookWebApplication(web.Application):' | |||
|
173 | 173 | mathjax_url=ipython_app.mathjax_url, |
|
174 | 174 | config=ipython_app.config, |
|
175 | 175 | jinja2_env=env, |
|
176 | terminals_available=False, # Set later if terminals are available | |
|
176 | 177 | ) |
|
177 | 178 | |
|
178 | 179 | # allow custom overrides for the tornado web app. |
@@ -765,10 +766,9 b' class NotebookApp(BaseIPythonApplication):' | |||
|
765 | 766 | try: |
|
766 | 767 | from .terminal import initialize |
|
767 | 768 | initialize(self.web_app) |
|
768 | self.web_app.terminals_available = True | |
|
769 | self.web_app.settings['terminals_available'] = True | |
|
769 | 770 | except ImportError as e: |
|
770 | 771 | self.log.info("Terminals not available (error was %s)", e) |
|
771 | self.web_app.terminals_available = False | |
|
772 | 772 | |
|
773 | 773 | def init_signal(self): |
|
774 | 774 | if not sys.platform.startswith('win'): |
@@ -11,6 +11,7 b' require([' | |||
|
11 | 11 | 'tree/js/clusterlist', |
|
12 | 12 | 'tree/js/sessionlist', |
|
13 | 13 | 'tree/js/kernellist', |
|
14 | 'tree/js/terminallist', | |
|
14 | 15 | 'auth/js/loginwidget', |
|
15 | 16 | // only loaded, not used: |
|
16 | 17 | 'jqueryui', |
@@ -25,7 +26,8 b' require([' | |||
|
25 | 26 | notebooklist, |
|
26 | 27 | clusterlist, |
|
27 | 28 | sesssionlist, |
|
28 |
kernellist, |
|
|
29 | kernellist, | |
|
30 | terminallist, | |
|
29 | 31 | loginwidget){ |
|
30 | 32 | |
|
31 | 33 | page = new page.Page(); |
@@ -44,6 +46,11 b' require([' | |||
|
44 | 46 | kernel_list = new kernellist.KernelList('#running_list', $.extend({ |
|
45 | 47 | session_list: session_list}, |
|
46 | 48 | common_options)); |
|
49 | ||
|
50 | if (utils.get_body_data("terminalsAvailable") === "True") { | |
|
51 | terminal_list = new terminallist.TerminalList('#terminal_list', common_options); | |
|
52 | } | |
|
53 | ||
|
47 | 54 | login_widget = new loginwidget.LoginWidget('#login_widget', common_options); |
|
48 | 55 | |
|
49 | 56 | $('#new_notebook').click(function (e) { |
@@ -12,6 +12,7 b'' | |||
|
12 | 12 | |
|
13 | 13 | data-base-url="{{base_url}}" |
|
14 | 14 | data-notebook-path="{{notebook_path}}" |
|
15 | data-terminals-available="{{terminals_available}}" | |
|
15 | 16 | |
|
16 | 17 | {% endblock %} |
|
17 | 18 | |
@@ -24,6 +25,9 b' data-notebook-path="{{notebook_path}}"' | |||
|
24 | 25 | <ul id="tabs" class="nav nav-tabs"> |
|
25 | 26 | <li class="active"><a href="#notebooks" data-toggle="tab">Notebooks</a></li> |
|
26 | 27 | <li><a href="#running" data-toggle="tab">Running</a></li> |
|
28 | {% if terminals_available %} | |
|
29 | <li><a href="#terminals" data-toggle="tab">Terminals</a></li> | |
|
30 | {% endif %} | |
|
27 | 31 | <li><a href="#clusters" data-toggle="tab">Clusters</a></li> |
|
28 | 32 | </ul> |
|
29 | 33 | |
@@ -79,6 +83,29 b' data-notebook-path="{{notebook_path}}"' | |||
|
79 | 83 | </div> |
|
80 | 84 | </div> |
|
81 | 85 | </div> |
|
86 | ||
|
87 | {% if terminals_available %} | |
|
88 | <div id="terminals" class="tab-pane"> | |
|
89 | ||
|
90 | <div id="terminal_toolbar" class="row"> | |
|
91 | <div class="col-xs-8 no-padding"> | |
|
92 | <span id="terminal_list_info">Currently running terminals</span> | |
|
93 | </div> | |
|
94 | <div class="col-xs-4 no-padding tree-buttons"> | |
|
95 | <span id="terminal_buttons" class="pull-right"> | |
|
96 | <button id="new_terminal" title="New terminal" class="btn btn-default btn-xs">New Terminal</button> | |
|
97 | <button id="refresh_terminal_list" title="Refresh terminal list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> | |
|
98 | </span> | |
|
99 | </div> | |
|
100 | </div> | |
|
101 | ||
|
102 | <div id="terminal_list"> | |
|
103 | <div id="terminal_list_header" class="row list_header"> | |
|
104 | <div> There are no terminals running. </div> | |
|
105 | </div> | |
|
106 | </div> | |
|
107 | </div> | |
|
108 | {% endif %} | |
|
82 | 109 | |
|
83 | 110 | <div id="clusters" class="tab-pane"> |
|
84 | 111 |
General Comments 0
You need to be logged in to leave comments.
Login now