From 5228879c9640b08fdd9668c86fd938d6ed19cda8 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Thu, 26 Sep 2019 18:37:48 +0200 Subject: [PATCH 1/3] start on a simple client with fields and buttons --- client/index.css | 11 +++++++++++ client/index.html | 33 +++++++++++++++++++++++++++++++++ client/index.js | 18 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 client/index.css create mode 100644 client/index.html create mode 100644 client/index.js diff --git a/client/index.css b/client/index.css new file mode 100644 index 0000000..5e714e8 --- /dev/null +++ b/client/index.css @@ -0,0 +1,11 @@ +.input-group { + padding: 10px; +} + +input { + padding: 5px; +} + +label { + margin-right: 10px; +} diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..bbc989b --- /dev/null +++ b/client/index.html @@ -0,0 +1,33 @@ + + + + + + + + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ +

Result:

+ + + + diff --git a/client/index.js b/client/index.js new file mode 100644 index 0000000..b0c619d --- /dev/null +++ b/client/index.js @@ -0,0 +1,18 @@ +let call_backend = function(e) { + console.log("Call backend"); + type = event.target.getAttribute('name'); + console.log(type); + + var url = document.forms["link"]["url-field"].value; + var run = document.forms["link"]["run-field"].value; + var link = document.forms["link"]["link-field"].value; + + xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + document.getElementById("result").innerHTML = xmlhttp.responseText; + }; + }; + xmlhttp.open("POST", url + "/link/" (type==="start" ? "start" : "handoff") + "/" + run + "/" + link, true); + xmlhttp.send(); +} From 9a9669d87dd9c8fd44b5559ea6145b1846c7dd89 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Fri, 27 Sep 2019 15:20:10 +0200 Subject: [PATCH 2/3] add cors to server, fix client requests --- client/index.html | 6 +++--- client/index.js | 22 ++++++++++++---------- watcher/app.py | 2 ++ watcher/requirements.txt | 1 + 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/index.html b/client/index.html index bbc989b..f67053f 100644 --- a/client/index.html +++ b/client/index.html @@ -9,7 +9,7 @@
- +
@@ -21,8 +21,8 @@
- - + +
diff --git a/client/index.js b/client/index.js index b0c619d..52f5972 100644 --- a/client/index.js +++ b/client/index.js @@ -1,18 +1,20 @@ let call_backend = function(e) { - console.log("Call backend"); type = event.target.getAttribute('name'); - console.log(type); - var url = document.forms["link"]["url-field"].value; + var url_base = document.forms["link"]["url-field"].value; var run = document.forms["link"]["run-field"].value; var link = document.forms["link"]["link-field"].value; - xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - document.getElementById("result").innerHTML = xmlhttp.responseText; + x = new XMLHttpRequest(); + x.onreadystatechange = function() { + if (x.readyState === 4) { + console.log("response: " + x.responseText); + document.getElementById("result").innerHTML = x.responseText; }; }; - xmlhttp.open("POST", url + "/link/" (type==="start" ? "start" : "handoff") + "/" + run + "/" + link, true); - xmlhttp.send(); -} + + var url = "http://" + url_base + "/link/" + (type === "start" ? "start" : "handoff") + "/" + run + "/" + link; + // console.log(url); + x.open("GET", url, true); + x.send(); +}; diff --git a/watcher/app.py b/watcher/app.py index ee3538a..2ce46ee 100644 --- a/watcher/app.py +++ b/watcher/app.py @@ -2,9 +2,11 @@ from time import time import socketio from flask import Flask, render_template +from flask_cors import CORS sio = socketio.Server() app = Flask(__name__) +cors = CORS(app) app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app) # We request users to send the run number to prevent accidentially getting old requests from a previous run diff --git a/watcher/requirements.txt b/watcher/requirements.txt index 23c5fdc..426a190 100644 --- a/watcher/requirements.txt +++ b/watcher/requirements.txt @@ -1,2 +1,3 @@ flask +flask-cors python-socketio From a7ddca1d0b5a680d667289e1002b24a0dee74f55 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Fri, 27 Sep 2019 15:28:30 +0200 Subject: [PATCH 3/3] add run instructions for the client --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 83a5a11..93f0fff 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,18 @@ Go enjoy the dashboard @ *localhost:5000* ## The client This is an example client and will also be used as first link in the machine. + +### Requirements + +A local http file server of some kind. + for ex the python http server. + +### Running + +Go into the correct directory with the code + + cd watcher + +with python's http server + + python -m http.server