2020-01-27 17:36:58 +01:00
|
|
|
let socket = io();
|
2020-02-01 18:31:47 +01:00
|
|
|
let plate = document.querySelector("#plat ul");
|
|
|
|
let ingredient = document.querySelector("#ingredient ul");
|
|
|
|
let sauce = document.querySelector("#sauce ul");
|
|
|
|
let drink = document.querySelector("#boisson ul");
|
|
|
|
let dessert = document.querySelector("#dessert ul");
|
|
|
|
let list = document.querySelector(".liste");
|
2020-02-01 19:41:07 +01:00
|
|
|
let current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
|
|
|
|
let radios = {"plate": null, "drink": null, "dessert": null};
|
2020-01-27 17:36:58 +01:00
|
|
|
|
2020-01-27 20:53:18 +01:00
|
|
|
|
2020-02-04 22:42:08 +01:00
|
|
|
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) {
|
2020-02-02 22:30:28 +01:00
|
|
|
if (!sandwich)
|
|
|
|
sandwich = "";
|
2020-02-04 22:42:08 +01:00
|
|
|
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <h2>${sandwich}</h2><h3>${client}</h3><p>${plate}</p><p>${ingredient}</p><p>${sauce}</p><p>${drink}</p><p>${dessert}</p><button class="annuler">Annuler</button><button class="erreur">Erreur</button> </div> </div>`);
|
2020-01-27 20:53:18 +01:00
|
|
|
let e = document.querySelector(`.liste #cmd${id}`);
|
2020-02-01 18:31:47 +01:00
|
|
|
e.addEventListener( "click" ,ev => {
|
|
|
|
ev.stopPropagation();
|
2020-01-27 20:53:18 +01:00
|
|
|
e.classList.toggle("show-spec");
|
2020-01-27 17:36:58 +01:00
|
|
|
});
|
2020-02-01 18:31:47 +01:00
|
|
|
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});
|
|
|
|
});
|
2020-01-27 17:36:58 +01:00
|
|
|
switch (state) {
|
2020-02-02 18:51:02 +01:00
|
|
|
case "WIP":
|
2020-02-02 22:30:28 +01:00
|
|
|
WIP(e, sandwich);
|
2020-02-02 18:51:02 +01:00
|
|
|
break;
|
2020-02-01 16:43:22 +01:00
|
|
|
case "done":
|
|
|
|
done(e);
|
|
|
|
break;
|
2020-01-27 17:36:58 +01:00
|
|
|
case "gave":
|
2020-01-27 20:53:18 +01:00
|
|
|
give(e);
|
2020-01-27 17:36:58 +01:00
|
|
|
break;
|
|
|
|
case "error":
|
2020-01-27 20:53:18 +01:00
|
|
|
error(e);
|
2020-01-27 17:36:58 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-02-01 18:31:47 +01:00
|
|
|
document.querySelector("#resume>h1").innerHTML = `Commande ${id+1}`;
|
2020-01-27 17:36:58 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function addplate(id, name) {
|
2020-02-02 16:02:41 +01:00
|
|
|
plate.insertAdjacentHTML("beforeend", `<li><input type="radio" name="plate" id="${id}"><label for="${id}">${name}</label></li>`);
|
2020-02-01 17:40:01 +01:00
|
|
|
let e = document.querySelector(`input[id=${id} ]`);
|
2020-01-27 20:53:18 +01:00
|
|
|
e.addEventListener("click", () => {
|
2020-02-01 19:41:07 +01:00
|
|
|
radiocheck(e, "plate",0);
|
|
|
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
|
|
|
el.disabled = !e.checked;
|
|
|
|
if (!e.checked)
|
|
|
|
el.checked = false
|
|
|
|
});
|
2020-01-27 20:53:18 +01:00
|
|
|
})
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
2020-01-27 20:53:18 +01:00
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function addingredient(id, name) {
|
2020-02-02 16:02:41 +01:00
|
|
|
ingredient.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="ingredient" id="${id}"><label for="${id}">${name}</label></li>`);
|
2020-02-01 17:40:01 +01:00
|
|
|
let e = document.querySelector(`input[id=${id} ]`);
|
2020-01-27 20:53:18 +01:00
|
|
|
e.addEventListener("click", () => {
|
2020-02-01 19:41:07 +01:00
|
|
|
checkcheck(e, "ingredient", 1, 3)
|
2020-01-27 20:53:18 +01:00
|
|
|
})
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
2020-01-27 20:53:18 +01:00
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function addsauce(id, name) {
|
2020-02-02 16:02:41 +01:00
|
|
|
sauce.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="sauce" id="${id}"><label for="${id}">${name}</label></li>`);
|
2020-02-01 17:40:01 +01:00
|
|
|
let e = document.querySelector(`input[id=${id} ]`);
|
2020-01-27 20:53:18 +01:00
|
|
|
e.addEventListener("click", () => {
|
2020-02-01 19:41:07 +01:00
|
|
|
checkcheck(e, "sauce", 2, 2)
|
2020-01-27 20:53:18 +01:00
|
|
|
})
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
2020-01-27 20:53:18 +01:00
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function adddrink(id, name) {
|
2020-02-02 16:02:41 +01:00
|
|
|
drink.insertAdjacentHTML("beforeend", `<li><input type="radio" name="drink" id="${id}"><label for="${id}">${name}</label></li>`);
|
2020-02-01 17:40:01 +01:00
|
|
|
let e = document.querySelector(`input[id=${id} ]`);
|
2020-01-27 20:53:18 +01:00
|
|
|
e.addEventListener("click", () => {
|
2020-02-01 19:41:07 +01:00
|
|
|
radiocheck(e, "drink", 3)
|
2020-01-27 20:53:18 +01:00
|
|
|
})
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
2020-01-27 20:53:18 +01:00
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function adddessert(id, name) {
|
2020-02-02 16:02:41 +01:00
|
|
|
dessert.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dessert" id="${id}"><label for="${id}">${name}</label></li>`);
|
2020-02-01 17:40:01 +01:00
|
|
|
let e = document.querySelector(`input[id=${id} ]`);
|
2020-01-27 20:53:18 +01:00
|
|
|
e.addEventListener("click", () => {
|
2020-02-01 19:41:07 +01:00
|
|
|
radiocheck(e, "dessert", 4)
|
2020-01-27 20:53:18 +01:00
|
|
|
})
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 19:41:07 +01:00
|
|
|
function radiocheck (e, n, p) {
|
|
|
|
if (e.checked) {
|
|
|
|
let curr, name;
|
|
|
|
if (e.id === radios[n]) {
|
|
|
|
e.checked = false;
|
|
|
|
radios[n] = null;
|
|
|
|
curr = null;
|
|
|
|
name = null;
|
|
|
|
} else {
|
|
|
|
radios[n] = e.id;
|
|
|
|
curr = e.id;
|
|
|
|
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
|
|
|
}
|
|
|
|
current[n] = curr;
|
|
|
|
document.querySelectorAll("#resume p")[p].innerHTML = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkcheck(e, n, p, l) {
|
|
|
|
if (e.checked)
|
|
|
|
current[n].push(e.id);
|
|
|
|
else
|
|
|
|
current[n].splice(current[n].indexOf(e.id), 1);
|
|
|
|
document.querySelectorAll(`input[name=${n}]`).forEach( e => {
|
|
|
|
if (!e.checked)
|
|
|
|
e.disabled = current[n].length === l
|
|
|
|
});
|
|
|
|
document.querySelectorAll("#resume p")[p].innerHTML = current[n].join(" - ");
|
|
|
|
}
|
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function clear(e) {
|
2020-02-01 18:31:47 +01:00
|
|
|
e.classList.remove("finis");
|
|
|
|
e.classList.remove("donnee");
|
|
|
|
e.classList.remove("probleme");
|
2020-02-02 18:51:02 +01:00
|
|
|
e.classList.remove("WIP");
|
2020-02-01 18:31:47 +01:00
|
|
|
e.classList.remove("show-spec");
|
2020-02-01 17:40:01 +01:00
|
|
|
list.prepend(e);
|
|
|
|
}
|
|
|
|
|
2020-02-02 18:51:02 +01:00
|
|
|
function WIP(e, name) {
|
|
|
|
e.classList.remove("show-spec");
|
|
|
|
e.classList.add("WIP");
|
|
|
|
e.querySelector("h2").innerHTML = name;
|
|
|
|
}
|
|
|
|
|
2020-02-01 17:40:01 +01:00
|
|
|
function done(e) {
|
2020-02-01 18:31:47 +01:00
|
|
|
e.classList.remove("show-spec");
|
|
|
|
e.classList.add("finis");
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function give(e) {
|
2020-02-01 18:31:47 +01:00
|
|
|
e.classList.remove("show-spec");
|
|
|
|
e.classList.add("donnee");
|
2020-02-01 17:40:01 +01:00
|
|
|
list.appendChild(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function error(e) {
|
2020-02-01 18:31:47 +01:00
|
|
|
e.classList.remove("show-spec");
|
|
|
|
e.classList.add("probleme");
|
2020-02-01 17:40:01 +01:00
|
|
|
list.appendChild(e);
|
|
|
|
}
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("connect", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
if (data === "ok") {
|
|
|
|
socket.emit("list plate");
|
|
|
|
socket.emit("list ingredient");
|
|
|
|
socket.emit("list sauce");
|
|
|
|
socket.emit("list drink");
|
|
|
|
socket.emit("list dessert");
|
|
|
|
socket.emit("list command");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list command", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = list.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
list.removeChild(child);
|
|
|
|
child = list.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let c of data.list) {
|
2020-02-04 22:42:08 +01:00
|
|
|
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.client, c.sandwich);
|
2020-02-01 17:40:01 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list plate", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = plate.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
plate.removeChild(child);
|
|
|
|
child = plate.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let p of data.list) {
|
|
|
|
addplate(p.id, p.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list ingredient", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = ingredient.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
ingredient.removeChild(child);
|
|
|
|
child = ingredient.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let i of data.list) {
|
|
|
|
addingredient(i.id, i.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list sauce", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = sauce.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
sauce.removeChild(child);
|
|
|
|
child = sauce.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let s of data.list) {
|
|
|
|
addsauce(s.id, s.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list drink", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = drink.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
drink.removeChild(child);
|
|
|
|
child = drink.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let d of data.list) {
|
|
|
|
adddrink(d.id, d.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("list dessert", data => {
|
2020-02-01 17:40:01 +01:00
|
|
|
let child = dessert.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
dessert.removeChild(child);
|
|
|
|
child = dessert.lastElementChild;
|
|
|
|
}
|
|
|
|
for (let d of data.list) {
|
|
|
|
adddessert(d.id, d.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("new command", data => {
|
2020-02-04 22:42:08 +01:00
|
|
|
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state, data.client, data.sandwich);
|
2020-02-01 17:40:01 +01:00
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("cleared command", data => {
|
|
|
|
clear(document.querySelector(`.liste #cmd${data.id}`))
|
2020-02-01 17:40:01 +01:00
|
|
|
});
|
|
|
|
|
2020-02-02 18:51:02 +01:00
|
|
|
socket.on("WIPed command", data => {
|
2020-02-02 22:30:28 +01:00
|
|
|
WIP(document.querySelector(`.liste #cmd${data.id}`), data.sandwich)
|
2020-02-02 18:51:02 +01:00
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("finish command", data => {
|
|
|
|
done(document.querySelector(`.liste #cmd${data.id}`))
|
2020-02-01 17:40:01 +01:00
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("gave command", data => {
|
|
|
|
give(document.querySelector(`.liste #cmd${data.id}`))
|
2020-02-01 17:40:01 +01:00
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
socket.on("glitched command", data => {
|
|
|
|
error(document.querySelector(`.liste #cmd${data.id}`))
|
2020-01-27 20:53:18 +01:00
|
|
|
});
|
|
|
|
|
2020-02-01 18:31:47 +01:00
|
|
|
document.querySelector(".validation").addEventListener("click", ev => {
|
2020-01-27 20:53:18 +01:00
|
|
|
ev.stopPropagation();
|
2020-02-02 16:02:41 +01:00
|
|
|
let user = document.getElementById("user");
|
2020-02-01 20:07:13 +01:00
|
|
|
if (!current.plate && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert) {
|
|
|
|
alert("Empty command !");
|
|
|
|
return;
|
2020-02-02 16:02:41 +01:00
|
|
|
} else if (user.style.color === "red") {
|
|
|
|
current["firstname"] = prompt("Prénom");
|
|
|
|
current["lastname"] = prompt("Nom");
|
2020-02-01 20:07:13 +01:00
|
|
|
}
|
2020-02-02 16:02:41 +01:00
|
|
|
|
|
|
|
current["client"] = user.value;
|
2020-01-27 20:53:18 +01:00
|
|
|
socket.emit("add command", current);
|
2020-02-01 19:41:07 +01:00
|
|
|
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
|
|
|
|
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
|
|
|
|
e.checked = false;
|
|
|
|
});
|
|
|
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( e => {
|
|
|
|
e.checked = false;
|
|
|
|
e.disabled = true;
|
2020-01-27 20:53:18 +01:00
|
|
|
});
|
|
|
|
document.querySelectorAll("#resume p").forEach( e => {
|
|
|
|
e.innerHTML = ""
|
|
|
|
});
|
2020-02-02 16:02:41 +01:00
|
|
|
user.value = "";
|
|
|
|
user.style.color = "";
|
|
|
|
document.getElementById("user_list").innerHTML = "";
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("user").addEventListener("keyup", ev => {hinter(ev)});
|
|
|
|
|
|
|
|
function hinter(ev) {
|
|
|
|
let input = ev.target;
|
|
|
|
let min_characters = 0;
|
|
|
|
if (input.value.length < min_characters)
|
|
|
|
return;
|
|
|
|
socket.emit("list users", {"user": input.value});
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.on("list users", data => {
|
|
|
|
let user_list = document.getElementById("user_list");
|
|
|
|
user_list.innerHTML = "";
|
|
|
|
for (let u of data["list"]) {
|
|
|
|
user_list.insertAdjacentHTML("beforeend", `<option value="${u}">`);
|
|
|
|
}
|
|
|
|
|
|
|
|
let user = document.getElementById("user");
|
|
|
|
if (data["list"].indexOf(user.value) === -1)
|
|
|
|
user.style.color = "red";
|
|
|
|
else {
|
|
|
|
user.style.color = "";
|
|
|
|
}
|
2020-01-27 20:53:18 +01:00
|
|
|
});
|