1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Kfet-depreciated/app/static/js/kitchen.js

120 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-02-02 18:51:02 +01:00
let socket = io();
let WIP = document.getElementById("encours");
let done = document.getElementById("realisee");
let waiting = document.getElementById("attente");
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) {
2020-02-04 22:52:28 +01:00
for (let i of ["plate", "ingredient", "sauce", "drink", "dessert", "state", "sandwich"])
if (!eval(i))
eval(`${i} = ""`);
done.insertAdjacentHTML("beforeend", `<div id=cmd${id}> <h1>${id}</h1><h2>${sandwich}</h2><h3>${client}</h3><p>${plate} | ${ingredient}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p> </div>`);
2020-02-02 18:51:02 +01:00
let e = document.getElementById(`cmd${id}`);
switch (state) {
case "WIP":
2020-02-02 22:30:28 +01:00
WIPed(e, sandwich);
2020-02-02 18:51:02 +01:00
break;
case "waiting":
wait(e);
break;
}
}
function WIPed(e, name) {
2020-02-02 21:47:38 +01:00
e.querySelector("h2").innerHTML = name;
2020-02-04 22:12:28 +01:00
let names = [name];
WIP.querySelectorAll("h2").forEach(e => {
names.push(e.innerHTML)
});
names.sort();
if (names.indexOf(name) === 0)
WIP.insertAdjacentHTML("afterbegin", e.outerHTML);
else {
WIP.children[names.indexOf(name)-1].insertAdjacentHTML("afterend", e.outerHTML);
}
2020-02-02 21:47:38 +01:00
WIP.querySelector(`#${e.id}`).addEventListener("click", ev => {
socket.emit("done command", {"id": parseInt(e.id.replace("cmd", ""))});
});
2020-02-02 18:51:02 +01:00
e.remove();
}
function finish(e) {
done.insertAdjacentHTML("afterbegin", e.outerHTML);
e.remove();
}
function wait(e) {
waiting.insertAdjacentHTML("afterbegin", e.outerHTML);
e.remove();
}
2020-02-02 21:47:38 +01:00
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})
}
}
}
2020-02-02 18:51:02 +01:00
socket.on("connect", data => {
if (data === "ok") {
socket.emit("list service");
}
});
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.client,c.sandwich);
2020-02-02 18:51:02 +01:00
}
2020-02-02 21:47:38 +01:00
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("list service", data => {
if (Object.keys(data).length === 0)
2020-02-02 18:51:02 +01:00
alert("No service set !");
2020-02-02 21:47:38 +01:00
else
socket.emit("list command");
2020-02-02 18:51:02 +01:00
});
socket.on("new command", data => {
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state, data.client, data.sandwich);
2020-02-02 21:47:38 +01:00
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("cleared command", data => {
2020-02-02 21:47:38 +01:00
wait(document.getElementById((`cmd${data.id}`)));
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("WIPed command", data => {
2020-02-02 22:30:28 +01:00
WIPed(document.getElementById((`cmd${data.id}`)), data.sandwich);
2020-02-02 21:47:38 +01:00
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("finish command", data => {
2020-02-02 21:47:38 +01:00
finish(document.getElementById((`cmd${data.id}`)));
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("gave command", data => {
2020-02-02 21:47:38 +01:00
finish(document.getElementById((`cmd${data.id}`)));
waiter();
2020-02-02 18:51:02 +01:00
});
socket.on("glitched command", data => {
2020-02-02 21:47:38 +01:00
finish(document.getElementById(`cmd${data.id}`));
waiter();
2020-02-02 18:51:02 +01:00
});