From cf46e101444379492831457b1afc2081f44e1301 Mon Sep 17 00:00:00 2001 From: Kento HASEGAWA Date: Tue, 14 Aug 2018 18:54:53 +0900 Subject: [PATCH] Add a stop button --- comm/server/main.py | 16 ++++++++++ comm/server/static/js/pynq-manager.js | 29 ++++++++++++++++++- .../templates/part_question_status.html | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/comm/server/main.py b/comm/server/main.py index 06b627f..02d0729 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -262,6 +262,22 @@ def solve_questions(qname, qstr): return res +@app.route("/stop", methods=["POST"]) +def stop(): + _client = request.form["client"] + _url = _client + "/stop" + + try: + r = requests.get(_url) + client_res = json.loads(r.text)["status"] + except Exception as e: + client_res = "Connection error" + sys.stderr.write(str(e) + "\n") + + res = {"status": client_res} + + return json.dumps(res) + @app.route("/status", methods=["POST"]) def get_status(): _client = request.form["client"] diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index 8e06dcb..903fac2 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -74,7 +74,31 @@ var PynqManager = (function(){ _p.sendStop = function(){ - console.log("Not implemented!"); + for (var key in this.clients){ + (function(_key, _client){ + var statusObj = $(".client-status-row[data-cname='"+_key+"']").find(".client-status-value").eq(0) + $.ajax({ + type: "POST", + url: "/stop", + dataType: "json", + data: { + "client": _client + } + }).done(function(res){ + var answer = res["status"]; + var message = ""; + + if (answer) { + message = answer; + }else{ + message = "Illegal response: " + res; + } + statusObj.text(message); + }).fail(function(){ + statusObj.text("Connection error"); + }); + })(key, this.clients[key]); + } } @@ -139,6 +163,9 @@ $(function(){ var qname = $(this).data("qname"); pm.sendQuestion(qname, after=refresh_question_table); }); + $("#client-control-pane").find(".stop-button").eq(0).click(function(){ + pm.sendStop(); + }); }); } diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html index 61a5dc3..e46a98d 100644 --- a/comm/server/templates/part_question_status.html +++ b/comm/server/templates/part_question_status.html @@ -3,6 +3,7 @@

【{{qname}}】

+

-- 2.22.0