Archived
1
0
Fork 0

Fiw service and WIP commands

This commit is contained in:
Ethanell 2020-06-01 17:32:49 +02:00
parent 6d0f000787
commit 769ccf7bd9
6 changed files with 28 additions and 18 deletions

View file

@ -5,6 +5,9 @@ const WIP = document.getElementById("WIP");
const done = document.getElementById("done");
const waiting = document.getElementById("waiting");
let service = {};
function addCmd(c) {
done.insertAdjacentHTML("beforeend", `<div id=cmd${c.number}>
<h1>${c.number}</h1>
@ -54,14 +57,14 @@ function wait(e) {
}
function waiter() {
if (WIP.children.length < 3) {
let limit = Object.keys(service).filter(x=>x.startsWith("sandwich") && service[x]).length;
if (WIP.children.length < limit) {
let i;
if (waiting.children.length < 3 - WIP.children.length)
if (waiting.children.length < limit - WIP.children.length)
i = waiting.children.length;
else
i = 3 - WIP.children.length;
for (i-=1; i >= 0; i--)
socket.emit("WIP command", waiting.children[i].querySelector("h1").innerHTML);
i = limit - WIP.children.length;
socket.emit("WIP command", waiting.children[i-1].querySelector("h1").innerHTML);
}
}
@ -84,10 +87,12 @@ socket.on("list command", data => {
});
socket.on("list service", async data => {
if (!data || Object.keys(data).length === 0) {
if (!data || Object.keys(data).length === 0)
await alert("No service set !");
} else
else {
service = data;
socket.emit("list command");
}
});
socket.on("set service", () => {

View file

@ -20,7 +20,6 @@ async function next() {
await addUser(usersAdd.pop());
else
socket.emit("set service", users);
console.log(users)
}
function hinter(ev) {

View file

@ -12,22 +12,22 @@ module.exports = socket => {
throw new Error("Service not found");
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
console.log(sn + " " + s[sn + "Busy"])
if (!s[sn + "Busy"]) {
s[sn + "Busy"] = true;
sandwich = s[sn];
await s.reload();
if (!c.WIP && s[sn] && !s[sn + "Busy"]) {
sandwich = sn;
break;
}
}
if (sandwich) {
s[sandwich + "Busy"] = true;
await c.setSandwich(s[sandwich]);
c.WIP = true;
await c.setSandwich(sandwich);
await c.save();
await s.save();
await c.save();
let send = {
number: data,
sandwich: sandwich.username
sandwich: s[sandwich].username
}
socket.emit("WIP command", send);
socket.broadcast.emit("WIP command", send);

View file

@ -7,9 +7,13 @@ module.exports = socket => {
if (!s)
s = await models.Service.create();
for (let u in data)
await s["set"+u.charAt(0).toUpperCase()+u.slice(1)](data[u]);
for (let u in data) {
if (!(s[u] && s[u].username === data[u]) || !data[u])
s[u + "Busy"] = false;
await s["set" + u.charAt(0).toUpperCase() + u.slice(1)](data[u]);
}
await s.save();
socket.emit("set service", data);
socket.broadcast.emit("set service", data);
} catch (e) {

View file

@ -80,7 +80,7 @@ async function resetService(c) {
let service = await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}, include: ["sandwich1", "sandwich2", "sandwich3"]});
if (c.WIP && service) {
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
if (service[sn].username === c.sandwichUsername) {
if (service[sn] && service[sn].username === c.sandwichUsername) {
service[sn + "Busy"] = false;
await service.save();
break;

View file

@ -9,6 +9,8 @@ block content
li Menu
a(href="/service" target="popup")
li Service
a(href="/kitchen")
li Kitchen
a(href="#popup")
li#logout Disconnect