1
0
Fork 0

Kitchen integration P1

This commit is contained in:
Ethanell 2020-02-02 18:51:02 +01:00
parent e5d66bb13c
commit 5bd03af017
7 changed files with 219 additions and 135 deletions

View file

@ -46,6 +46,7 @@ class Command(db.Model):
take = db.Column(db.Time, default=datetime.datetime.now().time)
done = db.Column(db.Time)
give = db.Column(db.Time)
WIP = db.Column(db.Boolean, default=False)
error = db.Column(db.Boolean, default=False)
plate_id = db.Column(db.String, db.ForeignKey("plate.id"))
@ -122,3 +123,14 @@ class Dessert(db.Model):
def __repr__(self):
return f"<Dessert {self.id}>"
class Service(db.Model):
sandwitch1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
sandwitch2_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
sandwitch3_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
date = db.Column(db.Date, default=datetime.datetime.now().date, primary_key=True, unique=True)
sandwitch1 = db.Column(db.Boolean, default=False)
sandwitch2 = db.Column(db.Boolean, default=False)
sandwitch3 = db.Column(db.Boolean, default=False)

View file

@ -53,3 +53,9 @@ def stocks():
@login_required
def menu():
return render_template("menu.html")
@app.route("/cuisine")
@login_required
def cuisine():
return render_template("cuisine.html")

View file

@ -5,7 +5,7 @@ from flask_login import current_user
from flask_socketio import emit, disconnect
from app import socketio, db
from app.models import User, Command, Plate, Ingredient, Sauce, Drink, Dessert
from app.models import User, Command, Plate, Ingredient, Sauce, Drink, Dessert, Service
def authenticated_only(f):
@ -22,18 +22,26 @@ def authenticated_only(f):
def command_json(c):
ingredient = " - ".join([s.id for s in c.content])
sauces = " - ".join([s.id for s in c.sauce])
sandwitch = None
if c.error:
state = "error"
elif c.give:
state = "gave"
elif c.done:
state = "done"
elif c.WIP:
state = "WIP"
elif c.take:
state = "waiting"
else:
state = "unknown"
if c.sandwitch_id:
try:
sandwitch = User.query.get(c.sandwitch_id).username
except AttributeError:
pass
return {"id": c.number, "plate": c.plate_id, "ingredient": ingredient, "sauce": sauces, "drink": c.drink_id,
"dessert": c.dessert_id, "state": state}
"dessert": c.dessert_id, "state": state, "sandwitch": sandwitch}
@socketio.on("connect")
@ -110,6 +118,12 @@ def rmcmd(json):
c.done = None
c.give = None
c.error = False
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
if c.WIP and service:
sandwitchs = [service.sandwitch1_id, service.sandwitch2_id, service.sandwitch3_id]
if c.sandwitch_id in sandwitchs:
setattr(service, f"sandwitch{sandwitchs.index(c.sandwitch_id)+1}", False)
c.WIP = False
db.session.commit()
emit("cleared command", {"id": json["id"]}, broadcast=True)
@ -120,6 +134,12 @@ def donecmd(json):
c = Command.query.get(json["id"])
if c:
c.done = datetime.datetime.now().time()
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
if service and c.WIP:
sandwitchs = [service.sandwitch1_id, service.sandwitch2_id, service.sandwitch3_id]
if c.sandwitch_id in sandwitchs:
setattr(service, f"sandwitch{sandwitchs.index(c.sandwitch_id)+1}", False)
c.WIP = False
db.session.commit()
emit("finish command", {"id": json["id"]}, broadcast=True)
@ -134,6 +154,26 @@ def givecmd(json):
emit("gave command", {"id": json["id"]}, broadcast=True)
@socketio.on("WIP command")
@authenticated_only
def wipcmd(json):
c = Command.query.get(json["id"])
if c:
c.WIP = True
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
sandwitch = None
if service:
sandwitchs = [service.sandwitch1, service.sandwitch2, service.sandwitch3]
for i, s in enumerate(sandwitchs):
if not s:
setattr(service, f"sandwitch{i+1}", True)
c.sandwitch_id = getattr(service, f"sandwitch{i+1}_id")
sandwitch = User.query.get(c.sandwitch_id).username
break
db.session.commit()
emit("WIPed command", {"id": json["id"], "sandwitch": sandwitch}, broadcast=True)
@socketio.on("error command")
@authenticated_only
def errcmd(json):
@ -198,3 +238,18 @@ def lsusers(json):
if not json or "user" not in json or json["user"] in u.username:
users_list.append(u.username)
emit("list users", {"list": users_list})
@socketio.on("list service")
@authenticated_only
def lsservice():
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
s = []
if service:
for u in [service.sandwitch1_id, service.sandwitch2_id, service.sandwitch3_id]:
try:
s.append([u, User.query.get(u).username])
except AttributeError:
s.append([])
emit("list service", {"list": s})

View file

@ -520,6 +520,10 @@ textarea.input2 + .focus-input2::after {
display: none;
}
.liste .WIP {
background-color: rgb(70, 170, 185);
}
.liste .finis {
background-color: rgb(185, 176, 30);
}

114
app/static/js/kitchen.js Normal file
View file

@ -0,0 +1,114 @@
let socket = io();
let service = [];
let WIP = document.getElementById("encours");
let done = document.getElementById("realisee");
let waiting = document.getElementById("attente");
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) {
done.insertAdjacentHTML("beforeend", `<div id=cmd${id}> <h1>${id}</h1><h2></h2><p>${plate} | ${ingredient}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p> </div>`);
let e = document.getElementById(`cmd${id}`);
e.addEventListener('keyup', ev => {
if(!['1', '2', '3'].includes(ev.key)) return;
let nth=+ev.key;
let elem=WIP.querySelector(`.commis${nth}`);
let next=waiting.querySelector('div');
if(!next) {
elem.classList.add('realisee');
done.appendChild(elem);
} else {
next.classList.add(`commis${nth}`);
WIP.replaceChild(next, elem);
next.classList.add('realisee');
done.prepend(elem);
elem.classList.remove(`commis${nth}`);
}
});
switch (state) {
case "WIP":
WIPed(e, sandwitch);
break;
case "waiting":
wait(e);
break;
}
}
function WIPed(e, name) {
for (let s of service) {
if (s[1] === name) {
e.querySelector("h2").innerHTML = name;
break;
}
}
WIP.insertAdjacentHTML("afterbegin", e.outerHTML);
e.remove();
}
function finish(e) {
done.insertAdjacentHTML("afterbegin", e.outerHTML);
e.remove();
}
function wait(e) {
waiting.insertAdjacentHTML("afterbegin", e.outerHTML);
e.remove();
}
socket.on("connect", data => {
if (data === "ok") {
socket.emit("list service");
socket.emit("list command");
}
});
socket.on("list command", data => {
for (let e of [WIP, done, waiting]) {
let child = e.lastElementChild;
while (child) {
e.removeChild(child);
child = e.lastElementChild;
}
}
for (let c of data.list) {
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.sandwitch);
}
if (!WIP.children.length) {
waiting.children[0].innerHTML
//TODO: Auto WIP command
}
});
socket.on("list service", data => {
service = data["list"]
if (service.length === 0)
alert("No service set !");
});
socket.on("new command", data => {
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state);
});
socket.on("cleared command", data => {
wait(document.getElementById((`cmd${data.id}`)))
});
socket.on("WIPed command", data => {
WIPed(document.getElementById((`cmd${data.id}`)), data.sandwitch)
});
socket.on("finish command", data => {
finish(document.getElementById((`cmd${data.id}`)))
});
socket.on("gave command", data => {
finish(document.getElementById((`cmd${data.id}`)))
});
socket.on("glitched command", data => {
finish(document.getElementById(`cmd${data.id}`))
});

View file

@ -9,8 +9,8 @@ let current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "des
let radios = {"plate": null, "drink": null, "dessert": null};
function addcmd(id, plate, ingredient, sauce, drink, dessert, state) {
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <p>${plate}</p><p>${ingredient}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p><button class="annuler">Annuler</button><button class="erreur">Erreur</button> </div> </div>`);
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) {
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <h2></h2><p>${plate}</p><p>${ingredient}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p><button class="annuler">Annuler</button><button class="erreur">Erreur</button> </div> </div>`);
let e = document.querySelector(`.liste #cmd${id}`);
e.addEventListener( "click" ,ev => {
ev.stopPropagation();
@ -29,6 +29,9 @@ function addcmd(id, plate, ingredient, sauce, drink, dessert, state) {
socket.emit("error command", {"id": id});
});
switch (state) {
case "WIP":
WIP(e, sandwitch);
break;
case "done":
done(e);
break;
@ -121,10 +124,17 @@ function clear(e) {
e.classList.remove("finis");
e.classList.remove("donnee");
e.classList.remove("probleme");
e.classList.remove("WIP");
e.classList.remove("show-spec");
list.prepend(e);
}
function WIP(e, name) {
e.classList.remove("show-spec");
e.classList.add("WIP");
e.querySelector("h2").innerHTML = name;
}
function done(e) {
e.classList.remove("show-spec");
e.classList.add("finis");
@ -227,6 +237,10 @@ socket.on("cleared command", data => {
clear(document.querySelector(`.liste #cmd${data.id}`))
});
socket.on("WIPed command", data => {
WIP(document.querySelector(`.liste #cmd${data.id}`), data.sandwitch)
});
socket.on("finish command", data => {
done(document.querySelector(`.liste #cmd${data.id}`))
});

View file

@ -1,141 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>BDE INFO - Kfet</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>
{% extends "base.html" %}
{% block content %}
<div class="bg-contact2" id="main-container" style="background-image: url('images/bg-01.jpg');">
<div id="middle-container">
<div id="encours">
<div class="commis1">
<h1>Commande 1</h1>
<p>Sandwich dinde - jambon - tomate</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div class="commis2">
<h1>Commande 2</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div class="commis3">
<h1>Commande 3</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
</div>
<div id="realisee">
</div>
<div id="attente">
<div>
<h1>Commande 4</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div>
<h1>Commande 5</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div>
<h1>Commande 6</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div>
<h1>Commande 7</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div>
<h1>Commande 8</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div>
<h1>Commande 9</h1>
<p>Sandwich dinde - jambon</p>
<p>Sauce ketchup - harissa</p>
<p>Coca-cola</p>
<p>Beignet Chocolat</p>
</div>
<div id="realisee">
</div>
</div>
</div>
<script>
const encours=document.querySelector('#encours');
const attente=document.querySelector('#attente');
const realisee=document.querySelector('#realisee');
document.body.addEventListener('keyup', ev => {
if(!['1', '2', '3'].includes(ev.key)) return;
let nth=+ev.key;
let elem=encours.querySelector(`.commis${nth}`);
let next=attente.querySelector('div');
if(!next) {
elem.classList.add('realisee');
realisee.appendChild(elem);
} else {
next.classList.add(`commis${nth}`);
encours.replaceChild(next, elem);
next.classList.add('realisee');
realisee.prepend(elem);
elem.classList.remove(`commis${nth}`);
}
});
</script>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='js/kitchen.js') }}"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-23581568-13"></script>
@ -146,6 +27,4 @@
gtag('config', 'UA-23581568-13');
</script>
</body>
</html>
{% endblock %}