##// END OF EJS Templates
Merge pull request #7748 from minrk/poll-windows...
Merge pull request #7748 from minrk/poll-windows add no-op every 5s on Windows

File last commit:

r20000:30763f2f
r20412:0e5d86a4 merge
Show More
terminallist.js
121 lines | 4.0 KiB | application/javascript | JavascriptLexer
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'base/js/utils',
'jquery',
'tree/js/notebooklist',
], function(IPython, utils, $, notebooklist) {
"use strict";
var TerminalList = function (selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* Parameters:
* selector: string
* options: dictionary
* Dictionary of keyword arguments.
* base_url: string
*/
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 this.base_url = options.base_url || utils.get_body_data("baseUrl");
Jonathan Frederic
Remove terminals page of the dashboard,...
r19992 this.element_name = options.element_name || 'running';
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 this.selector = selector;
this.terminals = [];
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
this.load_terminals();
}
};
TerminalList.prototype = Object.create(notebooklist.NotebookList.prototype);
TerminalList.prototype.bind_events = function () {
var that = this;
$('#refresh_' + this.element_name + '_list').click(function () {
that.load_terminals();
});
Jonathan Frederic
New Terminal into new new button
r20000 $('#new-terminal').click($.proxy(this.new_terminal, this));
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 };
Min RK
create new terminals with POST /api/terminals...
r18616 TerminalList.prototype.new_terminal = function () {
Thomas Kluyver
Make a window immediately, and set its location on response...
r18688 var w = window.open();
var base_url = this.base_url;
Min RK
create new terminals with POST /api/terminals...
r18616 var settings = {
type : "POST",
Thomas Kluyver
Make a window immediately, and set its location on response...
r18688 dataType: "json",
Min RK
create new terminals with POST /api/terminals...
r18616 success : function (data, status, xhr) {
var name = data.name;
Thomas Kluyver
Make a window immediately, and set its location on response...
r18688 w.location = utils.url_join_encode(base_url, 'terminals', name);
Min RK
create new terminals with POST /api/terminals...
r18616 },
Thomas Kluyver
Close new window on error creating terminal
r18690 error : function(jqXHR, status, error){
w.close();
utils.log_ajax_error(jqXHR, status, error);
},
Min RK
create new terminals with POST /api/terminals...
r18616 };
var url = utils.url_join_encode(
this.base_url,
'api/terminals'
);
$.ajax(url, settings);
Thomas Kluyver
Show terminals as terminals/name...
r18559 };
Min RK
create new terminals with POST /api/terminals...
r18616
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 TerminalList.prototype.load_terminals = function() {
var url = utils.url_join_encode(this.base_url, 'api/terminals');
$.ajax(url, {
type: "GET",
cache: false,
dataType: "json",
success: $.proxy(this.terminals_loaded, this),
error : utils.log_ajax_error
});
};
TerminalList.prototype.terminals_loaded = function (data) {
this.terminals = data;
this.clear_list();
Matthias Bussonnier
Some code cleanup in javascript and python...
r19739 var item, term;
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 for (var i=0; i < this.terminals.length; i++) {
term = this.terminals[i];
item = this.new_item(-1);
this.add_link(term.name, item);
this.add_shutdown_button(term.name, item);
}
$('#terminal_list_header').toggle(data.length === 0);
};
TerminalList.prototype.add_link = function(name, item) {
item.data('term-name', name);
Thomas Kluyver
Show terminals as terminals/name...
r18559 item.find(".item_name").text("terminals/" + name);
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 item.find(".item_icon").addClass("fa fa-terminal");
var link = item.find("a.item_link")
.attr('href', utils.url_join_encode(this.base_url, "terminals", name));
link.attr('target', '_blank');
this.add_shutdown_button(name, item);
};
TerminalList.prototype.add_shutdown_button = function(name, item) {
var that = this;
Bussonnier Matthias
make shutdown yellow/orange
r19643 var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-xs btn-warning").
Thomas Kluyver
Add list of available terminals in the dashboard
r18555 click(function (e) {
var settings = {
processData : false,
type : "DELETE",
dataType : "json",
success : function () {
that.load_terminals();
},
error : utils.log_ajax_error,
};
var url = utils.url_join_encode(that.base_url, 'api/terminals', name);
$.ajax(url, settings);
return false;
});
item.find(".item_buttons").text("").append(shutdown_button);
};
return {TerminalList: TerminalList};
});