diff --git a/app/models.py b/app/models.py index 67af9d2..4f8d627 100644 --- a/app/models.py +++ b/app/models.py @@ -126,11 +126,14 @@ class Dessert(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) 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) + 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) sandwitch1 = db.Column(db.Boolean, default=False) sandwitch2 = db.Column(db.Boolean, default=False) - sandwitch3 = db.Column(db.Boolean, default=False) \ No newline at end of file + sandwitch3 = db.Column(db.Boolean, default=False) diff --git a/app/sockets.py b/app/sockets.py index 9bf9d72..aac0e9f 100644 --- a/app/sockets.py +++ b/app/sockets.py @@ -113,7 +113,7 @@ def addcmd(json): @socketio.on("clear command") @authenticated_only 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: c.done = None c.give = None @@ -131,7 +131,7 @@ def rmcmd(json): @socketio.on("done command") @authenticated_only 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: c.done = datetime.datetime.now().time() service = Service.query.filter_by(date=datetime.datetime.now().date()).first() @@ -147,9 +147,15 @@ def donecmd(json): @socketio.on("give command") @authenticated_only 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: 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() emit("gave command", {"id": json["id"]}, broadcast=True) @@ -157,7 +163,7 @@ def givecmd(json): @socketio.on("WIP command") @authenticated_only 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: c.WIP = True service = Service.query.filter_by(date=datetime.datetime.now().date()).first() @@ -177,7 +183,7 @@ def wipcmd(json): @socketio.on("error command") @authenticated_only 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: c.error = True db.session.commit() diff --git a/app/static/js/kitchen.js b/app/static/js/kitchen.js index 5b5de84..bdf0ae6 100644 --- a/app/static/js/kitchen.js +++ b/app/static/js/kitchen.js @@ -7,27 +7,6 @@ let waiting = document.getElementById("attente"); function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) { done.insertAdjacentHTML("beforeend", `

${id}

${plate} | ${ingredient}

${sauce}

${drink}

${dessert}

`); 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); @@ -39,13 +18,12 @@ function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwitch) } function WIPed(e, name) { - for (let s of service) { - if (s[1] === name) { - e.querySelector("h2").innerHTML = name; - break; - } - } + e.querySelector("h2").innerHTML = name; 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(); } @@ -59,10 +37,22 @@ function wait(e) { 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 => { if (data === "ok") { socket.emit("list service"); - socket.emit("list command"); } }); @@ -77,38 +67,43 @@ socket.on("list command", data => { 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 - } + waiter(); }); socket.on("list service", data => { service = data["list"] if (service.length === 0) alert("No service set !"); + else + socket.emit("list command"); }); socket.on("new command", data => { addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state); + waiter(); }); socket.on("cleared command", data => { - wait(document.getElementById((`cmd${data.id}`))) + wait(document.getElementById((`cmd${data.id}`))); + waiter(); }); 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 => { - finish(document.getElementById((`cmd${data.id}`))) + finish(document.getElementById((`cmd${data.id}`))); + waiter(); }); socket.on("gave command", data => { - finish(document.getElementById((`cmd${data.id}`))) + finish(document.getElementById((`cmd${data.id}`))); + waiter(); }); socket.on("glitched command", data => { - finish(document.getElementById(`cmd${data.id}`)) + finish(document.getElementById(`cmd${data.id}`)); + waiter(); }); diff --git a/app/static/js/pc.js b/app/static/js/pc.js index 741c179..c11ce47 100644 --- a/app/static/js/pc.js +++ b/app/static/js/pc.js @@ -170,7 +170,7 @@ socket.on("list command", data => { child = list.lastElementChild; } 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); } });