From 6a09ae8ff7cf567b5092d63f594390f830da65af Mon Sep 17 00:00:00 2001 From: flifloo Date: Mon, 27 Jan 2020 00:22:42 +0100 Subject: [PATCH] Add status commands and add commands --- app/routes.py | 80 ++++++++++++-- app/templates/login.html | 2 - app/templates/pc.html | 225 ++++++++++++++++++++------------------ app/templates/stocks.html | 31 +----- 4 files changed, 190 insertions(+), 148 deletions(-) diff --git a/app/routes.py b/app/routes.py index f622def..64bd26d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -40,25 +40,83 @@ def index(): @app.route("/pc") @login_required -def root(): +def pc(): return render_template("pc.html") +@app.route("/stocks") +@login_required +def stocks(): + return render_template("stocks.html") + + +@app.route("/menu") +@login_required +def menu(): + return render_template("menu.html") + + +commands = [ + { + "id": 1, + "plate": "sanddwitch", + "content": "Jambon - Tomate - Brie", + "drink": "Boisson surprise", + "dessert": "Panini nutella", + "state": "waiting" + }, + { + "id": 2, + "plate": "sanddwitch", + "content": "Jambon - Tomate - Brie", + "drink": "Boisson surprise", + "dessert": "Panini nutella", + "state": "gave" + }, + { + "id": 3, + "plate": "sanddwitch", + "content": "Jambon - Tomate - Brie", + "drink": "Boisson surprise", + "dessert": "Panini nutella", + "state": "error" + } +] + + @socketio.on("connect") def test_connect(): - emit("my response", {"data": "Connected"}) + emit("command list", {"list": commands, "idcom": len(commands)}) -@socketio.on("disconnect") -def test_disconnect(): - print("Client disconnected") +@socketio.on("add command") +def addcmd(json): + commands.append({"id": len(commands)+1, "plate": json["plate"], "content": json["content"], "drink": json["drink"], "dessert": json["dessert"], "state": "waiting"}) + emit("new command", commands[-1], broadcast=True) -@socketio.on("message") -def handle_message(message): - print("received message: " + message) +@socketio.on("clear command") +def rmcmd(json): + for i, c in enumerate(commands): + if c["id"] == json["id"]: + c["state"] = "waiting" + break + emit("cleared command", {"id": json["id"]}, broadcast=True) -@socketio.on("my event") -def handle_my_custom_event(json): - print("received json: " + str(json)) +@socketio.on("give command") +def givecmd(json): + for i, c in enumerate(commands): + if c["id"] == json["id"]: + c["state"] = "gave" + break + emit("gave command", {"id": json["id"]}, broadcast=True) + + +@socketio.on("error command") +def errcmd(json): + for i, c in enumerate(commands): + if c["id"] == json["id"]: + c["state"] = "error" + break + emit("glitched command", {"id": json["id"]}, broadcast=True) diff --git a/app/templates/login.html b/app/templates/login.html index 9368aed..6f3a6c2 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -64,8 +64,6 @@ - - diff --git a/app/templates/pc.html b/app/templates/pc.html index 57cc8af..0d9955e 100644 --- a/app/templates/pc.html +++ b/app/templates/pc.html @@ -1,31 +1,10 @@ - - - - BDE INFO - Kfet - - - - - - - - - - - - - - - - - - - - +{% extends "base.html" %} + +{% block content %} @@ -42,7 +21,7 @@
@@ -111,103 +90,135 @@
- -
- + - - - + - - + + - + - - - - + +{% endblock %} diff --git a/app/templates/stocks.html b/app/templates/stocks.html index 0ab479a..3e5627b 100644 --- a/app/templates/stocks.html +++ b/app/templates/stocks.html @@ -1,28 +1,6 @@ - - - - BDE INFO - Kfet - - - - - - - - - - - - - - - - - - - +{% extends "base.html" %} - +{% block content %}
@@ -72,7 +50,4 @@
- - - - +{% endblock %}