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,
defaultValue: DataTypes.NOW,
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"

View file

@ -323,11 +323,11 @@ socket.on("clear command", data => {
clear(document.querySelector(`.list #cmd${data}`))
});
socket.on("WIPed command", data => {
WIP(document.querySelector(`.list #cmd${data.id}`), data.sandwich)
socket.on("WIP command", data => {
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}`))
});

View file

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

View file

@ -66,7 +66,7 @@ socket.on("add user", () => {
socket.on("set service", () => {
console.log("close !")
window.close();
})
});
socket.on("fail add user", data => {
alert("User creation fail !");
@ -76,7 +76,7 @@ socket.on("fail add user", data => {
socket.on("internal error", () => {
alert("An error occurred !");
})
});
document.querySelectorAll("input[type='text']").forEach(e => {
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 utils = require("./utils");
module.exports = socket => {
return async (data) => {
@ -11,7 +10,6 @@ module.exports = socket => {
c.give = null;
c.error = false;
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}}));
c.WIP = false;
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()
utils.resetService(c, await models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}}));
await utils.resetService(c);
c.WIP = false;
await c.save();

View file

@ -10,6 +10,8 @@ const addCommand = require("./addCommand");
const addUSer = require("./addUser");
const setService = require("./setService");
const giveCommand = require("./giveCommand");
const WIPCommand = require("./WIPCommand");
const doneCommand = require("./doneCommand");
const errorCommand = require("./errorCommand");
const clearCommand = require("./clearCommand");
const price = require("./price")
@ -28,6 +30,8 @@ module.exports = socket => {
socket.on("add user", addUSer(socket));
socket.on("set service", setService(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("clear command", clearCommand(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) {
let sandwiches = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id]
if (c.sandwichId in sandwiches)
service["sandwich"+sandwiches.indexOf(c.sandwichId)+1] = false;
for (let sn of ["sandwich1", "sandwich2", "sandwich3"]) {
if (service[sn].username === c.sandwichUsername) {
service[sn + "Busy"] = false;
await service.save();
break;
}
}
}
}