Archived
1
0
Fork 0

Add done and WIP command, fix kitchen page

This commit is contained in:
Ethanell 2020-05-30 21:40:36 +02:00
parent a0a7bd4c10
commit bad1e38760
10 changed files with 147 additions and 54 deletions

View file

@ -5,6 +5,21 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
defaultValue: DataTypes.NOW, defaultValue: DataTypes.NOW,
primaryKey: true primaryKey: true
},
sandwich1Busy: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
sandwich2Busy: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
},
sandwich3Busy: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
} }
}, { }, {
tableName: "Services" tableName: "Services"

View file

@ -323,11 +323,11 @@ socket.on("clear command", data => {
clear(document.querySelector(`.list #cmd${data}`)) clear(document.querySelector(`.list #cmd${data}`))
}); });
socket.on("WIPed command", data => { socket.on("WIP command", data => {
WIP(document.querySelector(`.list #cmd${data.id}`), data.sandwich) WIP(document.querySelector(`.list #cmd${data.number}`), data.sandwich)
}); });
socket.on("finish command", data => { socket.on("done command", data => {
done(document.querySelector(`.list #cmd${data}`)) done(document.querySelector(`.list #cmd${data}`))
}); });

View file

@ -1,22 +1,25 @@
let socket = io(); const socket = io();
let WIP = document.getElementById("encours"); const WIP = document.getElementById("WIP");
let done = document.getElementById("realisee"); const done = document.getElementById("done");
let waiting = document.getElementById("attente"); const waiting = document.getElementById("waiting");
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) { function addCmd(c) {
for (let i of ["plate", "ingredient", "sauce", "drink", "dessert", "state", "sandwich"]) done.insertAdjacentHTML("beforeend", `<div id=cmd${c.number}>
if (!eval(i)) <h1>${c.number}</h1>
eval(`${i} = ""`); <h2>${c.sandwich}</h2>
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>`); <h3>${c.client}</h3>
let e = document.getElementById(`cmd${id}`); <p>${c.dish} | ${c.ingredient}</p>
switch (state) { <p>${c.sauce}</p>
case "WIP": <p>${c.drink}</p>
WIPed(e, sandwich); <p>${c.dessert}</p>
break; </div>`);
case "waiting": let e = document.getElementById(`cmd${c.number}`);
wait(e); if (c.error || c.give || c.done)
break; finish(e)
} else if (c.WIP)
WIPed(e, c.sandwich)
else
wait(e)
} }
function WIPed(e, name) { function WIPed(e, name) {
@ -32,8 +35,8 @@ function WIPed(e, name) {
WIP.children[names.indexOf(name)-1].insertAdjacentHTML("afterend", e.outerHTML); WIP.children[names.indexOf(name)-1].insertAdjacentHTML("afterend", e.outerHTML);
} }
WIP.querySelector(`#${e.id}`).addEventListener("click", ev => { WIP.querySelector(`#${e.id}`).addEventListener("click", () => {
socket.emit("done command", {"id": parseInt(e.id.replace("cmd", ""))}); socket.emit("done command", parseInt(e.id.replace("cmd", "")));
}); });
e.remove(); e.remove();
} }
@ -55,16 +58,13 @@ function waiter() {
i = waiting.children.length; i = waiting.children.length;
else else
i = 3 - WIP.children.length; i = 3 - WIP.children.length;
for (i-=1; i >= 0; i--) { for (i-=1; i >= 0; i--)
socket.emit("WIP command", {"id": waiting.children[i].querySelector("h1").innerHTML}) socket.emit("WIP command", waiting.children[i].querySelector("h1").innerHTML);
}
} }
} }
socket.on("connect", data => { socket.on("connected", () => {
if (data === "ok") { socket.emit("list service");
socket.emit("list service");
}
}); });
socket.on("list command", data => { socket.on("list command", data => {
@ -75,49 +75,57 @@ socket.on("list command", data => {
child = e.lastElementChild; child = e.lastElementChild;
} }
} }
for (let c of data.list) { for (let c of data) {
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.client,c.sandwich); addCmd(c);
} }
waiter(); waiter();
}); });
socket.on("list service", data => { socket.on("list service", data => {
if (Object.keys(data).length === 0) if (!data || Object.keys(data).length === 0) {
alert("No service set !"); alert("No service set !");
else } else
socket.emit("list command"); socket.emit("list command");
}); });
socket.on("set service", () => {
socket.emit("list service");
})
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, data.client, data.sandwich); addCmd(data);
waiter(); waiter();
}); });
socket.on("cleared command", data => { socket.on("clear command", data => {
wait(document.getElementById((`cmd${data.id}`))); wait(document.getElementById((`cmd${data}`)));
waiter(); waiter();
}); });
socket.on("WIPed command", data => { socket.on("WIP command", data => {
WIPed(document.getElementById((`cmd${data.id}`)), data.sandwich); WIPed(document.getElementById((`cmd${data.number}`)), data.sandwich);
waiter(); waiter();
}); });
socket.on("finish command", data => { socket.on("done command", data => {
finish(document.getElementById((`cmd${data.id}`))); finish(document.getElementById((`cmd${data}`)));
waiter(); waiter();
}); });
socket.on("gave command", data => { socket.on("give command", data => {
finish(document.getElementById((`cmd${data.id}`))); finish(document.getElementById((`cmd${data}`)));
waiter(); waiter();
}); });
socket.on("glitched command", data => { socket.on("error command", data => {
finish(document.getElementById(`cmd${data.id}`)); finish(document.getElementById(`cmd${data}`));
waiter(); waiter();
}); });
socket.on("internal error", () => {
alert("An error occurred !");
})
document.addEventListener("keyup", ev => { document.addEventListener("keyup", ev => {
let keys = [["Digit1", "Numpad1"], ["Digit2", "Numpad2"], ["Digit3", "Numpad3"]]; let keys = [["Digit1", "Numpad1"], ["Digit2", "Numpad2"], ["Digit3", "Numpad3"]];
for (let i=0; i<keys.length; i++) { for (let i=0; i<keys.length; i++) {

View file

@ -66,7 +66,7 @@ socket.on("add user", () => {
socket.on("set service", () => { socket.on("set service", () => {
console.log("close !") console.log("close !")
window.close(); window.close();
}) });
socket.on("fail add user", data => { socket.on("fail add user", data => {
alert("User creation fail !"); alert("User creation fail !");
@ -76,7 +76,7 @@ socket.on("fail add user", data => {
socket.on("internal error", () => { socket.on("internal error", () => {
alert("An error occurred !"); alert("An error occurred !");
}) });
document.querySelectorAll("input[type='text']").forEach(e => { document.querySelectorAll("input[type='text']").forEach(e => {
e.addEventListener("keyup", ev => {hinter(ev)}) e.addEventListener("keyup", ev => {hinter(ev)})

40
sockets/WIPCommand.js Normal file
View file

@ -0,0 +1,40 @@
const models = require("../models");
module.exports = socket => {
return async (data) => {
try {
let sandwich;
let c = await models.Command.findOne({where: {number: {[models.Sequelize.Op.eq]: data}, date: {[models.Sequelize.Op.eq]: new Date()}}});
let s = await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}, include: ["sandwich1", "sandwich2", "sandwich3"]});
if (!c)
throw new Error("Command not found")
else if (!s)
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];
break;
}
}
if (sandwich) {
c.WIP = true;
await c.setSandwich(sandwich);
await c.save();
await s.save();
let send = {
number: data,
sandwich: sandwich.username
}
socket.emit("WIP command", send);
socket.broadcast.emit("WIP command", send);
}
} catch (e) {
socket.emit("internal error");
console.error(e);
}
}
}

View file

@ -1,5 +1,4 @@
const models = require("../models"); const models = require("../models");
const utils = require("./utils");
module.exports = socket => { module.exports = socket => {
return async (data) => { return async (data) => {
@ -11,7 +10,6 @@ module.exports = socket => {
c.give = null; c.give = null;
c.error = false; c.error = false;
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}}));
c.WIP = false; c.WIP = false;
await c.save(); await c.save();

23
sockets/doneCommand.js Normal file
View file

@ -0,0 +1,23 @@
const models = require("../models");
const utils = require("./utils");
module.exports = socket => {
return async (data) => {
try {
let c = await models.Command.findOne({where: {number: {[models.Sequelize.Op.eq]: data}, date: {[models.Sequelize.Op.eq]: new Date()}}});
if (!c)
throw new Error("Command not found");
c.done = new Date();
await utils.resetService(c);
c.WIP = false;
await c.save();
socket.emit("done command", data);
socket.broadcast.emit("done command", data);
} catch (e) {
socket.emit("internal error");
console.error(e);
}
}
}

View file

@ -10,7 +10,7 @@ module.exports = socket => {
c.give = new Date() c.give = new Date()
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}})); await utils.resetService(c);
c.WIP = false; c.WIP = false;
await c.save(); await c.save();

View file

@ -10,6 +10,8 @@ const addCommand = require("./addCommand");
const addUSer = require("./addUser"); const addUSer = require("./addUser");
const setService = require("./setService"); const setService = require("./setService");
const giveCommand = require("./giveCommand"); const giveCommand = require("./giveCommand");
const WIPCommand = require("./WIPCommand");
const doneCommand = require("./doneCommand");
const errorCommand = require("./errorCommand"); const errorCommand = require("./errorCommand");
const clearCommand = require("./clearCommand"); const clearCommand = require("./clearCommand");
const price = require("./price") const price = require("./price")
@ -28,6 +30,8 @@ module.exports = socket => {
socket.on("add user", addUSer(socket)); socket.on("add user", addUSer(socket));
socket.on("set service", setService(socket)); socket.on("set service", setService(socket));
socket.on("give command", giveCommand(socket)); socket.on("give command", giveCommand(socket));
socket.on("WIP command", WIPCommand(socket));
socket.on("done command", doneCommand(socket));
socket.on("error command", errorCommand(socket)); socket.on("error command", errorCommand(socket));
socket.on("clear command", clearCommand(socket)); socket.on("clear command", clearCommand(socket));
socket.on("price", price(socket)); socket.on("price", price(socket));

View file

@ -17,11 +17,16 @@ function commandExport (c) {
} }
} }
function resetService(c, service) { 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) { if (c.WIP && service) {
let sandwiches = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id] for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
if (c.sandwichId in sandwiches) if (service[sn].username === c.sandwichUsername) {
service["sandwich"+sandwiches.indexOf(c.sandwichId)+1] = false; service[sn + "Busy"] = false;
await service.save();
break;
}
}
} }
} }