Archived
1
0
Fork 0

sandwiches & orders rework

This commit is contained in:
Ethanell 2020-09-28 15:08:58 +02:00
parent 80187cf71f
commit 498a2fa977
4 changed files with 27 additions and 36 deletions

View file

@ -1,25 +1,17 @@
const date = document.getElementById("date");
function collapse(e, subDiv) {
document.querySelectorAll("h4").forEach((e) => {
e.addEventListener("click", ev => {
ev.stopPropagation();
let action;
if (e.classList.contains("collapse"))
if (e.classList.contains("collapsed"))
action = "remove";
else
action = "add";
e.querySelectorAll("."+subDiv).forEach(e => e.classList[action]("hide"));
e.classList[action]("collapse");
e.parentElement.querySelectorAll(".collection").forEach(c => c.classList[action]("hide"));
e.classList[action]("collapsed");
})
}
document.querySelectorAll(".department").forEach(e => collapse(e, "user"));
document.querySelectorAll(".user").forEach(e => collapse(e, "order"));
document.querySelectorAll(".order").forEach(e => collapse(e, "sandwich"));
});
date.addEventListener("change", () => window.location.href = "?date="+date.value);

View file

@ -30,11 +30,11 @@ router.get("/", sessionCheck(2), async (req, res) => {
orders[o.DepartmentName][name][o.id] = o.Sandwiches;
}
res.render("orders", {title: "SOD - Orders", orders: orders, date: date});
}).post("/give", sessionCheck(2), async (req, res) => {
if (!req.body.id)
}).get("/give", sessionCheck(2), async (req, res) => {
if (!req.query.id)
return error(req, res, "Missing arg !", 400);
let order = await models.SandwichOrder.findByPk(req.body.id, {where: {give: false}});
let order = await models.SandwichOrder.findByPk(req.query.id, {where: {give: false}});
if (!order)
return error(req, res, "Invalid order id !", 400);

View file

@ -1,25 +1,22 @@
extends layout
block content
div#date-selector.card
div.container
label(for="date")=__("date")
input#date(type="date" value=date)
div#orders.card
div.container
h1=__("orders")
each user, department in orders
div.department
h2= department
div.container
h4=department
each orders, name in user
div.user
h3= name
each order, id in orders
div.order
h4 #{__("order")} N°#{id}
ul.collection.with-header
li.collection-header: h5 #{name} - #{__("order")} N°#{id}
each sandwich in order
div.sandwich
form.give(method="POST" action="/orders/give")
input(type="hidden" name="id" value=sandwich.SandwichOrder.id)
input.give(type="submit" value="v")
h4= sandwich.name
li.collection-item
div=sandwich.name
a.secondary-content(href="/orders/give?id="+sandwich.SandwichOrder.id)
i.material-icons check
script(src="/javascripts/orders.js")

View file

@ -1,13 +1,15 @@
extends layout
block content
div#date-selector.card
div.container
label(for="date")=__("date")
input#date(type="date" value=date)
div.card
div.container
h1=__("sandwiches")
ul.collection
each sandwich in sandwiches
div.sandwich
h2 #{sandwich.name}: #{sandwich.dataValues.number}
li.collection-item
div=sandwich.name
a.secondary-content=sandwich.dataValues.number
script(src="/javascripts/sandwiches.js")