##// END OF EJS Templates
Add list of available terminals in the dashboard
Thomas Kluyver -
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.load_terminals = function() {
43 var that = this;
44 var url = utils.url_join_encode(this.base_url, 'api/terminals');
45 $.ajax(url, {
46 type: "GET",
47 cache: false,
48 dataType: "json",
49 success: $.proxy(this.terminals_loaded, this),
50 error : utils.log_ajax_error
51 });
52 };
53
54 TerminalList.prototype.terminals_loaded = function (data) {
55 this.terminals = data;
56 this.clear_list();
57 var item, path_name, term;
58 for (var i=0; i < this.terminals.length; i++) {
59 term = this.terminals[i];
60 item = this.new_item(-1);
61 this.add_link(term.name, item);
62 this.add_shutdown_button(term.name, item);
63 }
64 $('#terminal_list_header').toggle(data.length === 0);
65 };
66
67 TerminalList.prototype.new_terminal = function() {
68 var url = utils.url_join_encode(this.base_url, 'terminals/new');
69 window.open(url, '_blank');
70 };
71
72 TerminalList.prototype.add_link = function(name, item) {
73 item.data('term-name', name);
74 item.find(".item_name").text(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 });
@@ -11,6 +11,7 b' require(['
11 'tree/js/clusterlist',
11 'tree/js/clusterlist',
12 'tree/js/sessionlist',
12 'tree/js/sessionlist',
13 'tree/js/kernellist',
13 'tree/js/kernellist',
14 'tree/js/terminallist',
14 'auth/js/loginwidget',
15 'auth/js/loginwidget',
15 // only loaded, not used:
16 // only loaded, not used:
16 'jqueryui',
17 'jqueryui',
@@ -25,7 +26,8 b' require(['
25 notebooklist,
26 notebooklist,
26 clusterlist,
27 clusterlist,
27 sesssionlist,
28 sesssionlist,
28 kernellist,
29 kernellist,
30 terminallist,
29 loginwidget){
31 loginwidget){
30
32
31 page = new page.Page();
33 page = new page.Page();
@@ -44,6 +46,7 b' require(['
44 kernel_list = new kernellist.KernelList('#running_list', $.extend({
46 kernel_list = new kernellist.KernelList('#running_list', $.extend({
45 session_list: session_list},
47 session_list: session_list},
46 common_options));
48 common_options));
49 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
47 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
50 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
48
51
49 $('#new_notebook').click(function (e) {
52 $('#new_notebook').click(function (e) {
@@ -24,6 +24,7 b' data-notebook-path="{{notebook_path}}"'
24 <ul id="tabs" class="nav nav-tabs">
24 <ul id="tabs" class="nav nav-tabs">
25 <li class="active"><a href="#notebooks" data-toggle="tab">Notebooks</a></li>
25 <li class="active"><a href="#notebooks" data-toggle="tab">Notebooks</a></li>
26 <li><a href="#running" data-toggle="tab">Running</a></li>
26 <li><a href="#running" data-toggle="tab">Running</a></li>
27 <li><a href="#terminals" data-toggle="tab">Terminals</a></li>
27 <li><a href="#clusters" data-toggle="tab">Clusters</a></li>
28 <li><a href="#clusters" data-toggle="tab">Clusters</a></li>
28 </ul>
29 </ul>
29
30
@@ -80,6 +81,27 b' data-notebook-path="{{notebook_path}}"'
80 </div>
81 </div>
81 </div>
82 </div>
82
83
84 <div id="terminals" class="tab-pane">
85
86 <div id="terminal_toolbar" class="row">
87 <div class="col-xs-8 no-padding">
88 <span id="terminal_list_info">Currently running terminals</span>
89 </div>
90 <div class="col-xs-4 no-padding tree-buttons">
91 <span id="terminal_buttons" class="pull-right">
92 <button id="new_terminal" title="New terminal" class="btn btn-default btn-xs">New Terminal</button>
93 <button id="refresh_terminal_list" title="Refresh terminal list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button>
94 </span>
95 </div>
96 </div>
97
98 <div id="terminal_list">
99 <div id="terminal_list_header" class="row list_header">
100 <div> There are no terminals running. </div>
101 </div>
102 </div>
103 </div>
104
83 <div id="clusters" class="tab-pane">
105 <div id="clusters" class="tab-pane">
84
106
85 <div id="cluster_toolbar" class="row">
107 <div id="cluster_toolbar" class="row">
General Comments 0
You need to be logged in to leave comments. Login now