Kitchen integration P2
This commit is contained in:
parent
5bd03af017
commit
a1d88c7a6e
4 changed files with 48 additions and 44 deletions
|
@ -126,11 +126,14 @@ class Dessert(db.Model):
|
||||||
|
|
||||||
|
|
||||||
class Service(db.Model):
|
class Service(db.Model):
|
||||||
|
pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
|
||||||
sandwitch1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
|
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)
|
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)
|
sandwitch3_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
|
||||||
|
commi1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
|
||||||
|
commi2_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)
|
date = db.Column(db.Date, default=datetime.datetime.now().date, primary_key=True, unique=True)
|
||||||
|
|
||||||
sandwitch1 = db.Column(db.Boolean, default=False)
|
sandwitch1 = db.Column(db.Boolean, default=False)
|
||||||
sandwitch2 = db.Column(db.Boolean, default=False)
|
sandwitch2 = db.Column(db.Boolean, default=False)
|
||||||
sandwitch3 = db.Column(db.Boolean, default=False)
|
sandwitch3 = db.Column(db.Boolean, default=False)
|
||||||
|
|
|
@ -113,7 +113,7 @@ def addcmd(json):
|
||||||
@socketio.on("clear command")
|
@socketio.on("clear command")
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def rmcmd(json):
|
def rmcmd(json):
|
||||||
c = Command.query.get(json["id"])
|
c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first()
|
||||||
if c:
|
if c:
|
||||||
c.done = None
|
c.done = None
|
||||||
c.give = None
|
c.give = None
|
||||||
|
@ -131,7 +131,7 @@ def rmcmd(json):
|
||||||
@socketio.on("done command")
|
@socketio.on("done command")
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def donecmd(json):
|
def donecmd(json):
|
||||||
c = Command.query.get(json["id"])
|
c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first()
|
||||||
if c:
|
if c:
|
||||||
c.done = datetime.datetime.now().time()
|
c.done = datetime.datetime.now().time()
|
||||||
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
|
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
|
||||||
|
@ -147,9 +147,15 @@ def donecmd(json):
|
||||||
@socketio.on("give command")
|
@socketio.on("give command")
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def givecmd(json):
|
def givecmd(json):
|
||||||
c = Command.query.get(json["id"])
|
c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first()
|
||||||
if c:
|
if c:
|
||||||
c.give = datetime.datetime.now().time()
|
c.give = 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()
|
db.session.commit()
|
||||||
emit("gave command", {"id": json["id"]}, broadcast=True)
|
emit("gave command", {"id": json["id"]}, broadcast=True)
|
||||||
|
|
||||||
|
@ -157,7 +163,7 @@ def givecmd(json):
|
||||||
@socketio.on("WIP command")
|
@socketio.on("WIP command")
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def wipcmd(json):
|
def wipcmd(json):
|
||||||
c = Command.query.get(json["id"])
|
c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first()
|
||||||
if c:
|
if c:
|
||||||
c.WIP = True
|
c.WIP = True
|
||||||
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
|
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
|
||||||
|
@ -177,7 +183,7 @@ def wipcmd(json):
|
||||||
@socketio.on("error command")
|
@socketio.on("error command")
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def errcmd(json):
|
def errcmd(json):
|
||||||
c = Command.query.get(json["id"])
|
c = Command.query.filter_by(date=datetime.datetime.now().date(), number=json["id"]).first()
|
||||||
if c:
|
if c:
|
||||||
c.error = True
|
c.error = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -7,27 +7,6 @@ let waiting = document.getElementById("attente");
|
||||||
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) {
|
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>`);
|
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}`);
|
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) {
|
switch (state) {
|
||||||
case "WIP":
|
case "WIP":
|
||||||
WIPed(e, sandwitch);
|
WIPed(e, sandwitch);
|
||||||
|
@ -39,13 +18,12 @@ function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch)
|
||||||
}
|
}
|
||||||
|
|
||||||
function WIPed(e, name) {
|
function WIPed(e, name) {
|
||||||
for (let s of service) {
|
e.querySelector("h2").innerHTML = name;
|
||||||
if (s[1] === name) {
|
|
||||||
e.querySelector("h2").innerHTML = name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WIP.insertAdjacentHTML("afterbegin", e.outerHTML);
|
WIP.insertAdjacentHTML("afterbegin", e.outerHTML);
|
||||||
|
WIP.querySelector(`#${e.id}`).addEventListener("click", ev => {
|
||||||
|
socket.emit("done command", {"id": parseInt(e.id.replace("cmd", ""))});
|
||||||
|
console.log("test");
|
||||||
|
});
|
||||||
e.remove();
|
e.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +37,22 @@ function wait(e) {
|
||||||
e.remove();
|
e.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waiter() {
|
||||||
|
if (WIP.children.length < 3) {
|
||||||
|
let i, list;
|
||||||
|
if (waiting.children.length < 3 - WIP.children.length)
|
||||||
|
i = waiting.children.length;
|
||||||
|
else
|
||||||
|
i = 3 - WIP.children.length;
|
||||||
|
for (i-=1; i >= 0; i--) {
|
||||||
|
socket.emit("WIP command", {"id": waiting.children[i].querySelector("h1").innerHTML})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.on("connect", data => {
|
socket.on("connect", data => {
|
||||||
if (data === "ok") {
|
if (data === "ok") {
|
||||||
socket.emit("list service");
|
socket.emit("list service");
|
||||||
socket.emit("list command");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,38 +67,43 @@ socket.on("list command", data => {
|
||||||
for (let c of data.list) {
|
for (let c of data.list) {
|
||||||
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.sandwitch);
|
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.sandwitch);
|
||||||
}
|
}
|
||||||
if (!WIP.children.length) {
|
waiter();
|
||||||
waiting.children[0].innerHTML
|
|
||||||
//TODO: Auto WIP command
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list service", data => {
|
socket.on("list service", data => {
|
||||||
service = data["list"]
|
service = data["list"]
|
||||||
if (service.length === 0)
|
if (service.length === 0)
|
||||||
alert("No service set !");
|
alert("No service set !");
|
||||||
|
else
|
||||||
|
socket.emit("list command");
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("new command", data => {
|
socket.on("new command", data => {
|
||||||
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state);
|
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state);
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("cleared command", data => {
|
socket.on("cleared command", data => {
|
||||||
wait(document.getElementById((`cmd${data.id}`)))
|
wait(document.getElementById((`cmd${data.id}`)));
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("WIPed command", data => {
|
socket.on("WIPed command", data => {
|
||||||
WIPed(document.getElementById((`cmd${data.id}`)), data.sandwitch)
|
WIPed(document.getElementById((`cmd${data.id}`)), data.sandwitch);
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("finish command", data => {
|
socket.on("finish command", data => {
|
||||||
finish(document.getElementById((`cmd${data.id}`)))
|
finish(document.getElementById((`cmd${data.id}`)));
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("gave command", data => {
|
socket.on("gave command", data => {
|
||||||
finish(document.getElementById((`cmd${data.id}`)))
|
finish(document.getElementById((`cmd${data.id}`)));
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("glitched command", data => {
|
socket.on("glitched command", data => {
|
||||||
finish(document.getElementById(`cmd${data.id}`))
|
finish(document.getElementById(`cmd${data.id}`));
|
||||||
|
waiter();
|
||||||
});
|
});
|
||||||
|
|
|
@ -170,7 +170,7 @@ socket.on("list command", data => {
|
||||||
child = list.lastElementChild;
|
child = list.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let c of data.list) {
|
for (let c of data.list) {
|
||||||
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state);
|
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.sandwitch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue