1
0
Fork 0

Some code reformat

This commit is contained in:
Ethanell 2020-02-01 18:31:47 +01:00
parent 8dd2e156a1
commit 6e9ffb780e

View file

@ -1,21 +1,33 @@
let socket = io(); let socket = io();
let plate = document.querySelector('#plat ul'); let plate = document.querySelector("#plat ul");
let ingredient = document.querySelector('#ingredient ul'); let ingredient = document.querySelector("#ingredient ul");
let sauce = document.querySelector('#sauce ul'); let sauce = document.querySelector("#sauce ul");
let drink = document.querySelector('#boisson ul'); let drink = document.querySelector("#boisson ul");
let dessert = document.querySelector('#dessert ul'); let dessert = document.querySelector("#dessert ul");
let list = document.querySelector('.liste'); let list = document.querySelector(".liste");
let current = {"plate": null, "content": [], "sauce": [], "drink": null, "dessert": null}; let current = {"plate": null, "content": [], "sauce": [], "drink": null, "dessert": null};
let radios = {"plate": null}; let radios = {"plate": null};
function addcmd(id, plate, content, sauce, drink, dessert, state) { function addcmd(id, plate, content, sauce, drink, dessert, state) {
$(list).append(`<div class='com' id='cmd${id}'> <button class='donner' onclick='donner(${id})'>Donnée</button> <h1>${id}</h1> <div class='spec'> <p>${plate}</p><p>${content}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p><button class='annuler' onclick='annuler(${id})'>Annuler</button><button class='erreur' onclick='erreur(${id})'>Erreur</button> </div> </div>`); $(list).append(`<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <p>${plate}</p><p>${content}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p><button class="annuler">Annuler</button><button class="erreur">Erreur</button> </div> </div>`);
let e = document.querySelector(`.liste #cmd${id}`); let e = document.querySelector(`.liste #cmd${id}`);
e.addEventListener( "click" ,env => { e.addEventListener( "click" ,ev => {
env.stopPropagation(); ev.stopPropagation();
e.classList.toggle("show-spec"); e.classList.toggle("show-spec");
}); });
e.querySelector(".donner").addEventListener("click", ev => {
ev.stopPropagation();
socket.emit("give command", {"id": id});
});
e.querySelector(".annuler").addEventListener("click", ev => {
ev.stopPropagation();
socket.emit("clear command", {"id": id});
});
e.querySelector(".erreur").addEventListener("click", ev => {
ev.stopPropagation();
socket.emit("error command", {"id": id});
});
switch (state) { switch (state) {
case "done": case "done":
done(e); done(e);
@ -27,7 +39,7 @@ function addcmd(id, plate, content, sauce, drink, dessert, state) {
error(e); error(e);
break; break;
} }
document.querySelector('#resume>h1').innerHTML = `Commande ${id+1}`; document.querySelector("#resume>h1").innerHTML = `Commande ${id+1}`;
} }
function addplate(id, name) { function addplate(id, name) {
@ -139,41 +151,31 @@ function adddessert(id, name) {
} }
function clear(e) { function clear(e) {
e.classList.remove('finis'); e.classList.remove("finis");
e.classList.remove('donnee'); e.classList.remove("donnee");
e.classList.remove('probleme'); e.classList.remove("probleme");
e.classList.remove('show-spec'); e.classList.remove("show-spec");
list.prepend(e); list.prepend(e);
} }
function done(e) { function done(e) {
e.classList.remove('show-spec'); e.classList.remove("show-spec");
e.classList.add('finis'); e.classList.add("finis");
} }
function give(e) { function give(e) {
e.classList.remove('show-spec'); e.classList.remove("show-spec");
e.classList.add('donnee'); e.classList.add("donnee");
list.appendChild(e); list.appendChild(e);
} }
function error(e) { function error(e) {
e.classList.remove('show-spec'); e.classList.remove("show-spec");
e.classList.add('probleme'); e.classList.add("probleme");
list.appendChild(e); list.appendChild(e);
} }
function donner(id) { socket.on("connect", data => {
socket.emit("give command", {"id": id});
}
function annuler(id) {
socket.emit("clear command", {"id": id});
}
function erreur(id) {
socket.emit("error command", {"id": id});
}
socket.on("connect", function (data) {
if (data === "ok") { if (data === "ok") {
socket.emit("list plate"); socket.emit("list plate");
socket.emit("list ingredient"); socket.emit("list ingredient");
@ -184,7 +186,7 @@ socket.on("connect", function (data) {
} }
}); });
socket.on("list command", function (data) { socket.on("list command", data => {
let child = list.lastElementChild; let child = list.lastElementChild;
while (child) { while (child) {
list.removeChild(child); list.removeChild(child);
@ -195,7 +197,7 @@ socket.on("list command", function (data) {
} }
}); });
socket.on("list plate", function (data) { socket.on("list plate", data => {
let child = plate.lastElementChild; let child = plate.lastElementChild;
while (child) { while (child) {
plate.removeChild(child); plate.removeChild(child);
@ -206,7 +208,7 @@ socket.on("list plate", function (data) {
} }
}); });
socket.on("list ingredient", function (data) { socket.on("list ingredient", data => {
let child = ingredient.lastElementChild; let child = ingredient.lastElementChild;
while (child) { while (child) {
ingredient.removeChild(child); ingredient.removeChild(child);
@ -217,7 +219,7 @@ socket.on("list ingredient", function (data) {
} }
}); });
socket.on("list sauce", function (data) { socket.on("list sauce", data => {
let child = sauce.lastElementChild; let child = sauce.lastElementChild;
while (child) { while (child) {
sauce.removeChild(child); sauce.removeChild(child);
@ -228,7 +230,7 @@ socket.on("list sauce", function (data) {
} }
}); });
socket.on("list drink", function (data) { socket.on("list drink", data => {
let child = drink.lastElementChild; let child = drink.lastElementChild;
while (child) { while (child) {
drink.removeChild(child); drink.removeChild(child);
@ -239,7 +241,7 @@ socket.on("list drink", function (data) {
} }
}); });
socket.on("list dessert", function (data) { socket.on("list dessert", data => {
let child = dessert.lastElementChild; let child = dessert.lastElementChild;
while (child) { while (child) {
dessert.removeChild(child); dessert.removeChild(child);
@ -250,27 +252,27 @@ socket.on("list dessert", function (data) {
} }
}); });
socket.on("new command", function (data) { socket.on("new command", data => {
addcmd(data.id, data.plate, data.content, data.sauce, data.drink, data.dessert, data.state); addcmd(data.id, data.plate, data.content, data.sauce, data.drink, data.dessert, data.state);
}); });
socket.on("cleared command", function (data) { socket.on("cleared command", data => {
clear(document.querySelector(`.liste #cmd${data.id}`)); clear(document.querySelector(`.liste #cmd${data.id}`))
}); });
socket.on("finish command", function (data) { socket.on("finish command", data => {
done(document.querySelector(`.liste #cmd${data.id}`)); done(document.querySelector(`.liste #cmd${data.id}`))
}); });
socket.on("gave command", function (data) { socket.on("gave command", data => {
give(document.querySelector(`.liste #cmd${data.id}`)); give(document.querySelector(`.liste #cmd${data.id}`))
}); });
socket.on("glitched command", function (data) { socket.on("glitched command", data => {
error(document.querySelector(`.liste #cmd${data.id}`)); error(document.querySelector(`.liste #cmd${data.id}`))
}); });
document.querySelector('.validation').addEventListener('click', ev => { document.querySelector(".validation").addEventListener("click", ev => {
ev.stopPropagation(); ev.stopPropagation();
current["pc"] = 1; current["pc"] = 1;
current["sandwitch"] = 1; current["sandwitch"] = 1;