Add remove option on menu, support of remove on commands, remove socket for dish, ingredient, sauce, drink and dessert
This commit is contained in:
parent
79d330ae47
commit
270c671b8e
8 changed files with 243 additions and 47 deletions
|
@ -107,6 +107,31 @@ function addDessert(d) {
|
|||
})
|
||||
}
|
||||
|
||||
function removeDish(d) {
|
||||
dish.querySelector("#dish"+d).parentElement.remove();
|
||||
delete db.dish[d];
|
||||
}
|
||||
|
||||
function removeIngredient(d) {
|
||||
ingredient.querySelector("#ingredient"+d).parentElement.remove();
|
||||
delete db.ingredient[d];
|
||||
}
|
||||
|
||||
function removeSauce(d) {
|
||||
sauce.querySelector("#sauce"+d).parentElement.remove();
|
||||
delete db.sauce[d];
|
||||
}
|
||||
|
||||
function removeDrink(d) {
|
||||
drink.querySelector("#drink"+d).parentElement.remove();
|
||||
delete db.drink[d];
|
||||
}
|
||||
|
||||
function removeDessert(d) {
|
||||
dessert.querySelector("#dessert"+d).parentElement.remove();
|
||||
delete db.dessert[d];
|
||||
}
|
||||
|
||||
function radioCheck (e) {
|
||||
if (e.checked) {
|
||||
let curr, name;
|
||||
|
@ -336,58 +361,73 @@ socket.on("add user", data => {
|
|||
});
|
||||
|
||||
socket.on("set dish", data => {
|
||||
if (data.available && db.dish[data.id] === undefined) {
|
||||
if (data.available && db.dish[data.id] === undefined)
|
||||
addDish(data);
|
||||
} else if (!data.available && db.dish[data.id] !== undefined) {
|
||||
dish.querySelector("#dish" + data.id).parentElement.remove();
|
||||
delete db.dish[data.id];
|
||||
} else {
|
||||
else if (!data.available && db.dish[data.id] !== undefined)
|
||||
removeDish(data.id);
|
||||
else
|
||||
db.dish[data.id] = data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("set ingredient", data => {
|
||||
if (data.available && db.ingredient[data.id] === undefined) {
|
||||
if (data.available && db.ingredient[data.id] === undefined)
|
||||
addIngredient(data);
|
||||
} else if (!data.available && db.ingredient[data.id] !== undefined) {
|
||||
ingredient.querySelector("#ingredient" + data.id).parentElement.remove();
|
||||
delete db.ingredient[data.id];
|
||||
} else {
|
||||
else if (!data.available && db.ingredient[data.id] !== undefined)
|
||||
removeIngredient(data.id);
|
||||
else
|
||||
db.ingredient[data.id] = data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("set sauce", data => {
|
||||
if (data.available && db.sauce[data.id] === undefined) {
|
||||
if (data.available && db.sauce[data.id] === undefined)
|
||||
addSauce(data);
|
||||
} else if (!data.available && db.sauce[data.id] !== undefined) {
|
||||
sauce.querySelector("#sauce" + data.id).parentElement.remove();
|
||||
delete db.sauce[data.id];
|
||||
} else {
|
||||
else if (!data.available && db.sauce[data.id] !== undefined)
|
||||
removeSauce(data.id);
|
||||
else
|
||||
db.sauce[data.id] = data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("set drink", data => {
|
||||
if (data.available && db.drink[data.id] === undefined) {
|
||||
if (data.available && db.drink[data.id] === undefined)
|
||||
addDrink(data);
|
||||
} else if (!data.available && db.drink[data.id] !== undefined) {
|
||||
drink.querySelector("#drink" + data.id).parentElement.remove();
|
||||
delete db.drink[data.id];
|
||||
} else {
|
||||
else if (!data.available && db.drink[data.id] !== undefined)
|
||||
removeDrink(data.id);
|
||||
else
|
||||
db.drink[data.id] = data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("set dessert", data => {
|
||||
if (data.available && db.dessert[data.id] === undefined) {
|
||||
if (data.available && db.dessert[data.id] === undefined)
|
||||
addDessert(data);
|
||||
} else if (!data.available && db.dessert[data.id] !== undefined) {
|
||||
dessert.querySelector("#dessert" + data.id).parentElement.remove();
|
||||
delete db.dessert[data.id];
|
||||
} else {
|
||||
else if (!data.available && db.dessert[data.id] !== undefined)
|
||||
removeDessert(data.id)
|
||||
else
|
||||
db.dessert[data.id] = data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("remove dish", data => {
|
||||
if (db.dish[data])
|
||||
removeDish(data);
|
||||
});
|
||||
|
||||
socket.on("remove ingredient", data => {
|
||||
if (db.ingredient[data])
|
||||
removeIngredient(data);
|
||||
});
|
||||
|
||||
socket.on("remove sauce", data => {
|
||||
if (db.sauce[data])
|
||||
removeSauce(data);
|
||||
});
|
||||
|
||||
socket.on("remove drink", data => {
|
||||
if (db.drink[data])
|
||||
removeDrink(data);
|
||||
});
|
||||
|
||||
socket.on("remove dessert", data => {
|
||||
if (db.dessert[data])
|
||||
removeDessert(data);
|
||||
});
|
||||
|
||||
socket.on("price", data => {
|
||||
|
|
|
@ -72,47 +72,63 @@ function popup(ob, el) {
|
|||
|
||||
function addDish(d) {
|
||||
db.dish[d.id] = d;
|
||||
dish.insertAdjacentHTML("beforeend", `<li><a id="dish${d.id}">${d.name}</a></li>`);
|
||||
let e = document.getElementById(`dish${d.id}`);
|
||||
e.addEventListener("click", () => {
|
||||
popup(db.dish[d.id], e);
|
||||
dish.insertAdjacentHTML("beforeend", `<li><a id="remove-dish${d.id}">\u274C</a> <a id="dish${d.id}">${d.name}</a></li>`);
|
||||
document.getElementById(`dish${d.id}`).addEventListener("click", ev => {
|
||||
popup(db.dish[d.id], ev.target);
|
||||
});
|
||||
document.getElementById("remove-dish"+d.id).addEventListener("click", () => {
|
||||
if (confirm("Remove "+d.name+" ?"))
|
||||
socket.emit("remove dish", d.id);
|
||||
});
|
||||
}
|
||||
|
||||
function addIngredient(i) {
|
||||
db.ingredient[i.id] = i;
|
||||
ingredient.insertAdjacentHTML("beforeend", `<li><a id="ingredient${i.id}">${i.name}</a></li>`);
|
||||
let e = document.getElementById(`ingredient${i.id}`);
|
||||
e.addEventListener("click", () => {
|
||||
popup(db.ingredient[i.id], e);
|
||||
ingredient.insertAdjacentHTML("beforeend", `<li><a id="remove-ingredient${i.id}">\u274C</a> <a id="ingredient${i.id}">${i.name}</a></li>`);
|
||||
document.getElementById(`ingredient${i.id}`).addEventListener("click", ev => {
|
||||
popup(db.ingredient[i.id], ev.target);
|
||||
});
|
||||
document.getElementById("remove-ingredient"+i.id).addEventListener("click", () => {
|
||||
if (confirm("Remove "+i.name+" ?"))
|
||||
socket.emit("remove ingredient", i.id);
|
||||
});
|
||||
}
|
||||
|
||||
function addSauce(s) {
|
||||
db.sauce[s.id] = s;
|
||||
sauce.insertAdjacentHTML("beforeend", `<li><a id="sauce${s.id}">${s.name}</a></li>`);
|
||||
let e = document.getElementById(`sauce${s.id}`);
|
||||
e.addEventListener("click", () => {
|
||||
popup(db.sauce[s.id], e);
|
||||
sauce.insertAdjacentHTML("beforeend", `<li><a id="remove-sauce${s.id}">\u274C</a> <a id="sauce${s.id}">${s.name}</a></li>`);
|
||||
document.getElementById(`sauce${s.id}`).addEventListener("click", ev => {
|
||||
popup(db.sauce[s.id], ev.target);
|
||||
});
|
||||
document.getElementById("remove-sauce"+s.id).addEventListener("click", () => {
|
||||
if (confirm("Remove "+s.name+" ?"))
|
||||
socket.emit("remove sauce", s.id);
|
||||
});
|
||||
}
|
||||
|
||||
function addDrink(d) {
|
||||
db.drink[d.id] = d;
|
||||
drink.insertAdjacentHTML("beforeend", `<li><a id="drink${d.id}">${d.name}</a></li>`);
|
||||
let e = document.getElementById(`drink${d.id}`);
|
||||
e.addEventListener("click", () => {
|
||||
popup(db.drink[d.id], e);
|
||||
drink.insertAdjacentHTML("beforeend", `<li><a id="remove-drink${d.id}">\u274C</a> <a id="drink${d.id}">${d.name}</a></li>`);
|
||||
document.getElementById(`drink${d.id}`).addEventListener("click", ev => {
|
||||
popup(db.drink[d.id], ev.target);
|
||||
});
|
||||
document.getElementById("remove-drink"+d.id).addEventListener("click", () => {
|
||||
if (confirm("Remove "+d.name+" ?"))
|
||||
socket.emit("remove drink", d.id);
|
||||
});
|
||||
}
|
||||
|
||||
function addDessert(d) {
|
||||
db.dessert[d.id] = d;
|
||||
dessert.insertAdjacentHTML("beforeend", `<li><a id="dessert${d.id}">${d.name}</a></li>`);
|
||||
dessert.insertAdjacentHTML("beforeend", `<li><a id="remove-dessert${d.id}">\u274C</a> <a id="dessert${d.id}">${d.name}</a></li>`);
|
||||
let e = document.getElementById(`dessert${d.id}`);
|
||||
e.addEventListener("click", () => {
|
||||
popup(db.dessert[d.id], e);
|
||||
});
|
||||
document.getElementById("remove-dessert"+d.id).addEventListener("click", () => {
|
||||
if (confirm("Remove "+d.name+" ?"))
|
||||
socket.emit("remove dessert", d.id);
|
||||
});
|
||||
}
|
||||
|
||||
socket.on("connected", () => {
|
||||
|
@ -213,6 +229,41 @@ socket.on("set dessert", data => {
|
|||
}
|
||||
});
|
||||
|
||||
socket.on("remove dish", data => {
|
||||
if (db.dish[data]) {
|
||||
dish.querySelector("#dish" + data).parentElement.remove();
|
||||
delete db.dish[data]
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("remove ingredient", data => {
|
||||
if (db.ingredient[data]) {
|
||||
ingredient.querySelector("#ingredient" + data).parentElement.remove();
|
||||
delete db.ingredient[data]
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("remove sauce", data => {
|
||||
if (db.sauce[data]) {
|
||||
sauce.querySelector("#sauce" + data).parentElement.remove();
|
||||
delete db.sauce[data]
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("remove drink", data => {
|
||||
if (db.drink[data]) {
|
||||
drink.querySelector("#drink" + data).parentElement.remove();
|
||||
delete db.drink[data]
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("remove dessert", data => {
|
||||
if (db.dessert[data]) {
|
||||
dessert.querySelector("#dessert" + data).parentElement.remove();
|
||||
delete db.dessert[data]
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("internal error", () => {
|
||||
alert("An error occurred !");
|
||||
})
|
||||
|
|
|
@ -14,6 +14,11 @@ const setSauce = require("./set/setSauce");
|
|||
const setDrink = require("./set/setDrink");
|
||||
const setDessert = require("./set/setDessert");
|
||||
const setService = require("./set/setService");
|
||||
const removeDish = require("./remove/removeDish");
|
||||
const removeIngredient = require("./remove/removeIngredient");
|
||||
const removeSauce = require("./remove/removeSauce");
|
||||
const removeDrink = require("./remove/removeDrink");
|
||||
const removeDessert = require("./remove/removeDessert");
|
||||
const giveCommand = require("./giveCommand");
|
||||
const WIPCommand = require("./WIPCommand");
|
||||
const doneCommand = require("./doneCommand");
|
||||
|
@ -38,6 +43,11 @@ module.exports = socket => {
|
|||
socket.on("set drink", setDrink(socket));
|
||||
socket.on("set dessert", setDessert(socket));
|
||||
socket.on("set service", setService(socket));
|
||||
socket.on("remove dish", removeDish(socket));
|
||||
socket.on("remove ingredient", removeIngredient(socket));
|
||||
socket.on("remove sauce", removeSauce(socket));
|
||||
socket.on("remove drink", removeDrink(socket));
|
||||
socket.on("remove dessert", removeDessert(socket));
|
||||
socket.on("give command", giveCommand(socket));
|
||||
socket.on("WIP command", WIPCommand(socket));
|
||||
socket.on("done command", doneCommand(socket));
|
||||
|
|
19
sockets/remove/removeDessert.js
Normal file
19
sockets/remove/removeDessert.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let d = await models.Dessert.findByPk(data);
|
||||
if (!d)
|
||||
throw new Error("Dessert not found !");
|
||||
|
||||
await d.destroy();
|
||||
|
||||
socket.emit("remove dessert", d.id);
|
||||
socket.broadcast.emit("remove dessert", d.id);
|
||||
} catch (e) {
|
||||
socket.emit("internal error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
19
sockets/remove/removeDish.js
Normal file
19
sockets/remove/removeDish.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let d = await models.Dish.findByPk(data);
|
||||
if (!d)
|
||||
throw new Error("Dish not found !");
|
||||
|
||||
await d.destroy();
|
||||
|
||||
socket.emit("remove dish", d.id);
|
||||
socket.broadcast.emit("remove dish", d.id);
|
||||
} catch (e) {
|
||||
socket.emit("internal error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
19
sockets/remove/removeDrink.js
Normal file
19
sockets/remove/removeDrink.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let d = await models.Drink.findByPk(data);
|
||||
if (!d)
|
||||
throw new Error("Drink not found !");
|
||||
|
||||
await d.destroy();
|
||||
|
||||
socket.emit("remove drink", d.id);
|
||||
socket.broadcast.emit("remove drink", d.id);
|
||||
} catch (e) {
|
||||
socket.emit("internal error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
19
sockets/remove/removeIngredient.js
Normal file
19
sockets/remove/removeIngredient.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let i = await models.Ingredient.findByPk(data);
|
||||
if (!i)
|
||||
throw new Error("Ingredient not found !");
|
||||
|
||||
await i.destroy();
|
||||
|
||||
socket.emit("remove ingredient", i.id);
|
||||
socket.broadcast.emit("remove ingredient", i.id);
|
||||
} catch (e) {
|
||||
socket.emit("internal error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
19
sockets/remove/removeSauce.js
Normal file
19
sockets/remove/removeSauce.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const models = require("../../models");
|
||||
|
||||
module.exports = socket => {
|
||||
return async (data) => {
|
||||
try {
|
||||
let s = await models.Sauce.findByPk(data);
|
||||
if (!s)
|
||||
throw new Error("Sauce not found !");
|
||||
|
||||
await s.destroy();
|
||||
|
||||
socket.emit("remove sauce", s.id);
|
||||
socket.broadcast.emit("remove sauce", s.id);
|
||||
} catch (e) {
|
||||
socket.emit("internal error");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue