Fiw service and WIP commands
This commit is contained in:
parent
6d0f000787
commit
769ccf7bd9
6 changed files with 28 additions and 18 deletions
|
@ -5,6 +5,9 @@ const WIP = document.getElementById("WIP");
|
||||||
const done = document.getElementById("done");
|
const done = document.getElementById("done");
|
||||||
const waiting = document.getElementById("waiting");
|
const waiting = document.getElementById("waiting");
|
||||||
|
|
||||||
|
let service = {};
|
||||||
|
|
||||||
|
|
||||||
function addCmd(c) {
|
function addCmd(c) {
|
||||||
done.insertAdjacentHTML("beforeend", `<div id=cmd${c.number}>
|
done.insertAdjacentHTML("beforeend", `<div id=cmd${c.number}>
|
||||||
<h1>${c.number}</h1>
|
<h1>${c.number}</h1>
|
||||||
|
@ -54,14 +57,14 @@ function wait(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function waiter() {
|
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;
|
let i;
|
||||||
if (waiting.children.length < 3 - WIP.children.length)
|
if (waiting.children.length < limit - WIP.children.length)
|
||||||
i = waiting.children.length;
|
i = waiting.children.length;
|
||||||
else
|
else
|
||||||
i = 3 - WIP.children.length;
|
i = limit - WIP.children.length;
|
||||||
for (i-=1; i >= 0; i--)
|
socket.emit("WIP command", waiting.children[i-1].querySelector("h1").innerHTML);
|
||||||
socket.emit("WIP command", waiting.children[i].querySelector("h1").innerHTML);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +87,12 @@ socket.on("list command", data => {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list service", async 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 !");
|
await alert("No service set !");
|
||||||
} else
|
else {
|
||||||
|
service = data;
|
||||||
socket.emit("list command");
|
socket.emit("list command");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("set service", () => {
|
socket.on("set service", () => {
|
||||||
|
|
|
@ -20,7 +20,6 @@ async function next() {
|
||||||
await addUser(usersAdd.pop());
|
await addUser(usersAdd.pop());
|
||||||
else
|
else
|
||||||
socket.emit("set service", users);
|
socket.emit("set service", users);
|
||||||
console.log(users)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hinter(ev) {
|
function hinter(ev) {
|
||||||
|
|
|
@ -12,22 +12,22 @@ module.exports = socket => {
|
||||||
throw new Error("Service not found");
|
throw new Error("Service not found");
|
||||||
|
|
||||||
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
|
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
|
||||||
console.log(sn + " " + s[sn + "Busy"])
|
await s.reload();
|
||||||
if (!s[sn + "Busy"]) {
|
if (!c.WIP && s[sn] && !s[sn + "Busy"]) {
|
||||||
s[sn + "Busy"] = true;
|
sandwich = sn;
|
||||||
sandwich = s[sn];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sandwich) {
|
if (sandwich) {
|
||||||
|
s[sandwich + "Busy"] = true;
|
||||||
|
await c.setSandwich(s[sandwich]);
|
||||||
c.WIP = true;
|
c.WIP = true;
|
||||||
await c.setSandwich(sandwich);
|
|
||||||
await c.save();
|
|
||||||
await s.save();
|
await s.save();
|
||||||
|
await c.save();
|
||||||
let send = {
|
let send = {
|
||||||
number: data,
|
number: data,
|
||||||
sandwich: sandwich.username
|
sandwich: s[sandwich].username
|
||||||
}
|
}
|
||||||
socket.emit("WIP command", send);
|
socket.emit("WIP command", send);
|
||||||
socket.broadcast.emit("WIP command", send);
|
socket.broadcast.emit("WIP command", send);
|
||||||
|
|
|
@ -7,9 +7,13 @@ module.exports = socket => {
|
||||||
if (!s)
|
if (!s)
|
||||||
s = await models.Service.create();
|
s = await models.Service.create();
|
||||||
|
|
||||||
for (let u in data)
|
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["set" + u.charAt(0).toUpperCase() + u.slice(1)](data[u]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await s.save();
|
||||||
socket.emit("set service", data);
|
socket.emit("set service", data);
|
||||||
socket.broadcast.emit("set service", data);
|
socket.broadcast.emit("set service", data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -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"]});
|
let service = await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}, include: ["sandwich1", "sandwich2", "sandwich3"]});
|
||||||
if (c.WIP && service) {
|
if (c.WIP && service) {
|
||||||
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
|
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;
|
service[sn + "Busy"] = false;
|
||||||
await service.save();
|
await service.save();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,6 +9,8 @@ block content
|
||||||
li Menu
|
li Menu
|
||||||
a(href="/service" target="popup")
|
a(href="/service" target="popup")
|
||||||
li Service
|
li Service
|
||||||
|
a(href="/kitchen")
|
||||||
|
li Kitchen
|
||||||
a(href="#popup")
|
a(href="#popup")
|
||||||
li#logout Disconnect
|
li#logout Disconnect
|
||||||
|
|
||||||
|
|
Reference in a new issue