simplify start-server links as pure links to /spawn/:user/:server

instead of API requests

this gets better progress-page loading and options form rendering
This commit is contained in:
Min RK
2019-02-25 13:45:02 +01:00
parent 0c028c7186
commit 6f63ac7831
2 changed files with 8 additions and 22 deletions

View File

@@ -1,10 +1,16 @@
// Copyright (c) Jupyter Development Team. // Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License. // Distributed under the terms of the Modified BSD License.
require(["jquery", "moment", "jhapi"], function($, moment, JHAPI) { require(["jquery", "moment", "jhapi", "utils"], function(
$,
moment,
JHAPI,
utils
) {
"use strict"; "use strict";
var base_url = window.jhdata.base_url; var base_url = window.jhdata.base_url;
var prefix = window.jhdata.prefix;
var user = window.jhdata.user; var user = window.jhdata.user;
var api = new JHAPI(base_url); var api = new JHAPI(base_url);
@@ -28,7 +34,6 @@ require(["jquery", "moment", "jhapi"], function($, moment, JHAPI) {
// enable buttons on a server row // enable buttons on a server row
// once the server is running or not // once the server is running or not
row.find(".btn").attr("disabled", false); row.find(".btn").attr("disabled", false);
row.find(".start-server").click(startServer);
row.find(".stop-server").click(stopServer); row.find(".stop-server").click(stopServer);
row.find(".delete-server").click(deleteServer); row.find(".delete-server").click(deleteServer);
@@ -58,25 +63,6 @@ require(["jquery", "moment", "jhapi"], function($, moment, JHAPI) {
}); });
} }
function startServer() {
var row = getRow($(this));
var serverName = row.data("server-name");
// before request
disableRow(row);
// request
api.start_named_server(user, serverName, {
success: function(reply) {
enableRow(row, true);
// TODO: this may 404 on the wrong server
// in case of slow startup
// it should really redirect to a `/spawn?server=...` page
window.location.href = row.find(".server-link").attr("href");
},
});
}
function deleteServer() { function deleteServer() {
var row = getRow($(this)); var row = getRow($(this));
var serverName = row.data("server-name"); var serverName = row.data("server-name");
@@ -122,7 +108,6 @@ require(["jquery", "moment", "jhapi"], function($, moment, JHAPI) {
}); });
}); });
$(".start-server").click(startServer);
$(".stop-server").click(stopServer); $(".stop-server").click(stopServer);
$(".delete-server").click(deleteServer); $(".delete-server").click(deleteServer);

View File

@@ -72,6 +72,7 @@
<td> <td>
<a role="button" class="stop-server btn btn-xs btn-danger{% if not spawner.active %} hidden{% endif %}" id="stop-{{ spawner.name }}">stop</a> <a role="button" class="stop-server btn btn-xs btn-danger{% if not spawner.active %} hidden{% endif %}" id="stop-{{ spawner.name }}">stop</a>
<a role="button" class="start-server btn btn-xs btn-primary {% if spawner.active %} hidden{% endif %}" id="start-{{ spawner.name }}" <a role="button" class="start-server btn btn-xs btn-primary {% if spawner.active %} hidden{% endif %}" id="start-{{ spawner.name }}"
href="{{ base_url }}spawn/{{ user.name }}/{{ spawner.name }}"
> >
start start
</a> </a>