Add socket give error and clear for commands
This commit is contained in:
parent
fed23f4248
commit
8f4cad8be6
6 changed files with 95 additions and 12 deletions
|
@ -15,7 +15,7 @@ function addCmd(command) {
|
|||
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${command.number}">
|
||||
<button class="give">Give</button>
|
||||
<h1>${command.number}</h1>
|
||||
<div class="spec">
|
||||
<div class="spec">
|
||||
<h2>${command.sandwich}</h2>
|
||||
<h3>${command.client}</h3>
|
||||
<p>${command.dish}</p>
|
||||
|
@ -34,15 +34,15 @@ function addCmd(command) {
|
|||
});
|
||||
e.querySelector(".give").addEventListener("click", ev => {
|
||||
ev.stopPropagation();
|
||||
socket.emit("give command", {"id": command.number});
|
||||
socket.emit("give command", command.number);
|
||||
});
|
||||
e.querySelector(".cancel").addEventListener("click", ev => {
|
||||
ev.stopPropagation();
|
||||
socket.emit("clear command", {"id": command.number});
|
||||
socket.emit("clear command", command.number);
|
||||
});
|
||||
e.querySelector(".error").addEventListener("click", ev => {
|
||||
ev.stopPropagation();
|
||||
socket.emit("error command", {"id": command.number});
|
||||
socket.emit("error command", command.number);
|
||||
});
|
||||
if (command.error)
|
||||
error(e)
|
||||
|
@ -161,12 +161,12 @@ function WIP(e, name) {
|
|||
|
||||
function done(e) {
|
||||
e.classList.remove("show-spec");
|
||||
e.classList.add("finis");
|
||||
e.classList.add("done");
|
||||
}
|
||||
|
||||
function give(e) {
|
||||
e.classList.remove("show-spec");
|
||||
e.classList.add("donnee");
|
||||
e.classList.add("give");
|
||||
list.appendChild(e);
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ socket.on("new command", data => {
|
|||
addCmd(data);
|
||||
});
|
||||
|
||||
socket.on("cleared command", data => {
|
||||
socket.on("clear command", data => {
|
||||
clear(document.querySelector(`.list #cmd${data}`))
|
||||
});
|
||||
|
||||
|
@ -282,11 +282,11 @@ socket.on("finish command", data => {
|
|||
done(document.querySelector(`.list #cmd${data}`))
|
||||
});
|
||||
|
||||
socket.on("gave command", data => {
|
||||
socket.on("give command", data => {
|
||||
give(document.querySelector(`.list #cmd${data}`))
|
||||
});
|
||||
|
||||
socket.on("glitched command", data => {
|
||||
socket.on("error command", data => {
|
||||
error(document.querySelector(`.list #cmd${data}`))
|
||||
});
|
||||
|
||||
|
|
|
@ -524,7 +524,7 @@ textarea.input2 + .focus-input2::after {
|
|||
background-color: rgb(70, 170, 185);
|
||||
}
|
||||
|
||||
.list .finis {
|
||||
.list .done {
|
||||
background-color: rgb(185, 176, 30);
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ textarea.input2 + .focus-input2::after {
|
|||
background-color: rgb(133, 1, 1);
|
||||
}
|
||||
|
||||
.list .warning .error, .list .warning .donner{
|
||||
.list .warning .error, .list .warning .give{
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ textarea.input2 + .focus-input2::after {
|
|||
background-color: rgb(133, 1, 1);
|
||||
}
|
||||
|
||||
.list .give .donner, .list .give .error{
|
||||
.list .give .give, .list .give .error{
|
||||
display : none;
|
||||
}
|
||||
|
||||
|
|
29
sockets/clearCommand.js
Normal file
29
sockets/clearCommand.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
const models = require("../models")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let c = await models.Command.findByPk(data);
|
||||
if (!c)
|
||||
throw new Error("Command not found");
|
||||
c.done = null;
|
||||
c.give = null;
|
||||
c.error = false;
|
||||
|
||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
||||
if (c.WIP && service) {
|
||||
let sandwichs = [service.sandwich1Id, service.sandwich2Id, service.sandwich3Id]
|
||||
if (c.sandwichId in sandwichs)
|
||||
service["sandwich"+sandwichs.indexOf(c.sandwichId)+1] = false;
|
||||
}
|
||||
c.WIP = false;
|
||||
|
||||
await c.save();
|
||||
socket.emit("clear command", data);
|
||||
socket.broadcast.emit("clear command", data);
|
||||
} catch (e) {
|
||||
socket.emit("error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
20
sockets/errorCommand.js
Normal file
20
sockets/errorCommand.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const models = require("../models")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let c = await models.Command.findByPk(data);
|
||||
if (!c)
|
||||
throw new Error("Command not found");
|
||||
|
||||
c.error = true;
|
||||
|
||||
await c.save();
|
||||
socket.emit("error command", data);
|
||||
socket.broadcast.emit("error command", data);
|
||||
} catch (e) {
|
||||
socket.emit("error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
28
sockets/giveCommand.js
Normal file
28
sockets/giveCommand.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const models = require("../models")
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let c = await models.Command.findByPk(data);
|
||||
if (!c)
|
||||
throw new Error("Command not found");
|
||||
|
||||
c.give = new Date()
|
||||
|
||||
let service = models.Service.findOne({where:{date:{[models.Sequelize.Op.eq]: new Date()}}});
|
||||
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;
|
||||
}
|
||||
c.WIP = false;
|
||||
|
||||
await c.save();
|
||||
socket.emit("give command", data);
|
||||
socket.broadcast.emit("give command", data);
|
||||
} catch (e) {
|
||||
socket.emit("error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,9 @@ const listSauce = require("./listSauce")
|
|||
const listDrink = require("./listDrink")
|
||||
const listDessert = require("./listDessert")
|
||||
const addCommand = require("./addCommand")
|
||||
const giveCommand = require("./giveCommand")
|
||||
const errorCommand = require("./errorCommand")
|
||||
const clearCommand = require("./clearCommand")
|
||||
|
||||
module.exports = socket => {
|
||||
socket.on("list command", listCommand(socket));
|
||||
|
@ -15,6 +18,9 @@ module.exports = socket => {
|
|||
socket.on("list dessert", listDessert(socket));
|
||||
socket.on("list dessert", listDessert(socket));
|
||||
socket.on("add command", addCommand(socket));
|
||||
socket.on("give command", giveCommand(socket));
|
||||
socket.on("error command", errorCommand(socket));
|
||||
socket.on("clear command", clearCommand(socket));
|
||||
console.log("New connection !");
|
||||
socket.emit("connected");
|
||||
}
|
||||
|
|
Reference in a new issue