From 65e664b14357564d19a55897cac9161b9fe6cd52 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 31 Oct 2014 15:42:52 -0700 Subject: [PATCH 1/3] Add list of available terminals in the dashboard --- IPython/html/static/tree/js/main.js | 5 +- IPython/html/static/tree/js/terminallist.js | 103 ++++++++++++++++++++ IPython/html/templates/tree.html | 22 +++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 IPython/html/static/tree/js/terminallist.js diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index ab0e08c03..ab29b0434 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -11,6 +11,7 @@ require([ 'tree/js/clusterlist', 'tree/js/sessionlist', 'tree/js/kernellist', + 'tree/js/terminallist', 'auth/js/loginwidget', // only loaded, not used: 'jqueryui', @@ -25,7 +26,8 @@ require([ notebooklist, clusterlist, sesssionlist, - kernellist, + kernellist, + terminallist, loginwidget){ page = new page.Page(); @@ -44,6 +46,7 @@ require([ kernel_list = new kernellist.KernelList('#running_list', $.extend({ session_list: session_list}, common_options)); + terminal_list = new terminallist.TerminalList('#terminal_list', common_options); login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').click(function (e) { diff --git a/IPython/html/static/tree/js/terminallist.js b/IPython/html/static/tree/js/terminallist.js new file mode 100644 index 000000000..91f313840 --- /dev/null +++ b/IPython/html/static/tree/js/terminallist.js @@ -0,0 +1,103 @@ +// 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) { + // Constructor + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // base_url: string + this.base_url = options.base_url || utils.get_body_data("baseUrl"); + this.element_name = options.element_name || 'terminal'; + 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(); + }); + $('#new_terminal').click($.proxy(this.new_terminal, this)); + }; + + TerminalList.prototype.load_terminals = function() { + var that = this; + 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(); + var item, path_name, term; + 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.new_terminal = function() { + var url = utils.url_join_encode(this.base_url, 'terminals/new'); + window.open(url, '_blank'); + }; + + TerminalList.prototype.add_link = function(name, item) { + item.data('term-name', name); + item.find(".item_name").text(name); + 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; + var shutdown_button = $(" + + + + + +
+
+
There are no terminals running.
+
+
+ +
From 4025b57ed87e77b87441d1e94f89b5894e1b813e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 31 Oct 2014 15:56:53 -0700 Subject: [PATCH 2/3] Only display terminals in dashboard if terminals are available --- IPython/html/notebookapp.py | 4 ++-- IPython/html/static/tree/js/main.js | 6 +++++- IPython/html/templates/tree.html | 7 ++++++- IPython/html/tree/handlers.py | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index f2d1c53b2..bf7f4f8d5 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -173,6 +173,7 @@ class NotebookWebApplication(web.Application): mathjax_url=ipython_app.mathjax_url, config=ipython_app.config, jinja2_env=env, + terminals_available=False, # Set later if terminals are available ) # allow custom overrides for the tornado web app. @@ -765,10 +766,9 @@ class NotebookApp(BaseIPythonApplication): try: from .terminal import initialize initialize(self.web_app) - self.web_app.terminals_available = True + self.web_app.settings['terminals_available'] = True except ImportError as e: self.log.info("Terminals not available (error was %s)", e) - self.web_app.terminals_available = False def init_signal(self): if not sys.platform.startswith('win'): diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index ab29b0434..1f1975828 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -46,7 +46,11 @@ require([ kernel_list = new kernellist.KernelList('#running_list', $.extend({ session_list: session_list}, common_options)); - terminal_list = new terminallist.TerminalList('#terminal_list', common_options); + + if (utils.get_body_data("terminalsAvailable") === "True") { + terminal_list = new terminallist.TerminalList('#terminal_list', common_options); + } + login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').click(function (e) { diff --git a/IPython/html/templates/tree.html b/IPython/html/templates/tree.html index 27cc5c837..b800b698c 100644 --- a/IPython/html/templates/tree.html +++ b/IPython/html/templates/tree.html @@ -12,6 +12,7 @@ data-base-url="{{base_url}}" data-notebook-path="{{notebook_path}}" +data-terminals-available="{{terminals_available}}" {% endblock %} @@ -24,7 +25,9 @@ data-notebook-path="{{notebook_path}}" @@ -80,7 +83,8 @@ data-notebook-path="{{notebook_path}}"
- + + {% if terminals_available %}
@@ -101,6 +105,7 @@ data-notebook-path="{{notebook_path}}"
+ {% endif %}
diff --git a/IPython/html/tree/handlers.py b/IPython/html/tree/handlers.py index 4c1fdf9a9..a57c993f0 100644 --- a/IPython/html/tree/handlers.py +++ b/IPython/html/tree/handlers.py @@ -55,7 +55,8 @@ class TreeHandler(IPythonHandler): self.write(self.render_template('tree.html', page_title=page_title, notebook_path=path, - breadcrumbs=breadcrumbs + breadcrumbs=breadcrumbs, + terminals_available=self.settings['terminals_available'], )) From d32322e33255e8d1ac15890c1d14aa204b6dd771 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 31 Oct 2014 17:28:51 -0700 Subject: [PATCH 3/3] Show terminals as terminals/name Bigger click target --- IPython/html/static/tree/js/terminallist.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/IPython/html/static/tree/js/terminallist.js b/IPython/html/static/tree/js/terminallist.js index 91f313840..c7ef391e2 100644 --- a/IPython/html/static/tree/js/terminallist.js +++ b/IPython/html/static/tree/js/terminallist.js @@ -39,6 +39,11 @@ define([ $('#new_terminal').click($.proxy(this.new_terminal, this)); }; + TerminalList.prototype.new_terminal = function() { + var url = utils.url_join_encode(this.base_url, 'terminals/new'); + window.open(url, '_blank'); + }; + TerminalList.prototype.load_terminals = function() { var that = this; var url = utils.url_join_encode(this.base_url, 'api/terminals'); @@ -63,15 +68,10 @@ define([ } $('#terminal_list_header').toggle(data.length === 0); }; - - TerminalList.prototype.new_terminal = function() { - var url = utils.url_join_encode(this.base_url, 'terminals/new'); - window.open(url, '_blank'); - }; TerminalList.prototype.add_link = function(name, item) { item.data('term-name', name); - item.find(".item_name").text(name); + item.find(".item_name").text("terminals/" + name); 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));