From 7b533fd9a73121d403bfc5a11b5ff8a784047da4 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 4 Feb 2020 22:12:28 +0100 Subject: [PATCH] Sandwich order by name --- app/static/js/kitchen.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/static/js/kitchen.js b/app/static/js/kitchen.js index ba4fa14..3551aa8 100644 --- a/app/static/js/kitchen.js +++ b/app/static/js/kitchen.js @@ -20,7 +20,17 @@ function addcmd(id, plate, ingredient, sauce, drink, dessert, state, sandwich) { function WIPed(e, name) { e.querySelector("h2").innerHTML = name; - WIP.insertAdjacentHTML("afterbegin", e.outerHTML); + let names = [name]; + WIP.querySelectorAll("h2").forEach(e => { + names.push(e.innerHTML) + }); + names.sort(); + if (names.indexOf(name) === 0) + WIP.insertAdjacentHTML("afterbegin", e.outerHTML); + else { + 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", ""))}); });