Selection optimization and lock useless choice if no plate selected
This commit is contained in:
parent
6e9ffb780e
commit
d1ebe7fe48
3 changed files with 63 additions and 104 deletions
|
@ -39,7 +39,7 @@ class Command(db.Model):
|
||||||
number = db.Column(db.Integer, nullable=False)
|
number = db.Column(db.Integer, nullable=False)
|
||||||
|
|
||||||
pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
||||||
sandwitch_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
sandwitch_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
client_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
client_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
|
||||||
|
|
||||||
date = db.Column(db.Date, default=datetime.datetime.now().date)
|
date = db.Column(db.Date, default=datetime.datetime.now().date)
|
||||||
|
|
|
@ -19,7 +19,7 @@ def authenticated_only(f):
|
||||||
|
|
||||||
|
|
||||||
def command_json(c):
|
def command_json(c):
|
||||||
content = " - ".join([s.id for s in c.content])
|
ingredient = " - ".join([s.id for s in c.content])
|
||||||
sauces = " - ".join([s.id for s in c.sauce])
|
sauces = " - ".join([s.id for s in c.sauce])
|
||||||
if c.error:
|
if c.error:
|
||||||
state = "error"
|
state = "error"
|
||||||
|
@ -31,7 +31,7 @@ def command_json(c):
|
||||||
state = "waiting"
|
state = "waiting"
|
||||||
else:
|
else:
|
||||||
state = "unknown"
|
state = "unknown"
|
||||||
return {"id": c.number, "plate": c.plate_id, "content": content, "sauce": sauces, "drink": c.drink_id, "dessert": c.dessert_id, "state": state}
|
return {"id": c.number, "plate": c.plate_id, "ingredient": ingredient, "sauce": sauces, "drink": c.drink_id, "dessert": c.dessert_id, "state": state}
|
||||||
|
|
||||||
|
|
||||||
@socketio.on("connect")
|
@socketio.on("connect")
|
||||||
|
@ -59,17 +59,7 @@ def addcmd(json):
|
||||||
c.number = Command.query.filter_by(date=datetime.datetime.now().date()).order_by(Command.number.desc()).first().number+1
|
c.number = Command.query.filter_by(date=datetime.datetime.now().date()).order_by(Command.number.desc()).first().number+1
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
c.number = 1
|
c.number = 1
|
||||||
|
c.pc_id = current_user.id
|
||||||
if "pc" in json:
|
|
||||||
try:
|
|
||||||
c.pc_id = User.query.get(json["pc"]).id
|
|
||||||
except AttributeError:
|
|
||||||
c.pc_id = 0
|
|
||||||
if "sandwitch" in json:
|
|
||||||
try:
|
|
||||||
c.sandwitch_id = User.query.get(json["sandwitch"]).id
|
|
||||||
except AttributeError:
|
|
||||||
c.sandwitch_id = 0
|
|
||||||
if "client" in json:
|
if "client" in json:
|
||||||
try:
|
try:
|
||||||
c.client_id = User.query.get(json["client"]).id
|
c.client_id = User.query.get(json["client"]).id
|
||||||
|
@ -80,8 +70,8 @@ def addcmd(json):
|
||||||
c.plate_id = Plate.query.get(json["plate"]).id
|
c.plate_id = Plate.query.get(json["plate"]).id
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if "content" in json:
|
if "ingredient" in json:
|
||||||
for i in json["content"]:
|
for i in json["ingredient"]:
|
||||||
try:
|
try:
|
||||||
c.content.append(Ingredient.query.get(i))
|
c.content.append(Ingredient.query.get(i))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -5,12 +5,12 @@ 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, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
|
||||||
let radios = {"plate": null};
|
let radios = {"plate": null, "drink": null, "dessert": null};
|
||||||
|
|
||||||
|
|
||||||
function addcmd(id, plate, content, sauce, drink, dessert, state) {
|
function addcmd(id, plate, ingredient, sauce, drink, dessert, state) {
|
||||||
$(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>`);
|
$(list).append(`<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <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>`);
|
||||||
let e = document.querySelector(`.liste #cmd${id}`);
|
let e = document.querySelector(`.liste #cmd${id}`);
|
||||||
e.addEventListener( "click" ,ev => {
|
e.addEventListener( "click" ,ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
@ -43,88 +43,39 @@ function addcmd(id, plate, content, sauce, drink, dessert, state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addplate(id, name) {
|
function addplate(id, name) {
|
||||||
$(plate).append(`<li><input type="radio" name="plat" id="${id}"><label for="${id}">${name}</label></li>`);
|
$(plate).append(`<li><input type="radio" name="plate" id="${id}"><label for="${id}">${name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=${id} ]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
if (e.checked) {
|
radiocheck(e, "plate",0);
|
||||||
let curr, name;
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
||||||
if (e.id === radios["plate"]) {
|
el.disabled = !e.checked;
|
||||||
e.checked = false;
|
if (!e.checked)
|
||||||
radios["plate"] = null;
|
el.checked = false
|
||||||
curr = null;
|
});
|
||||||
name = null;
|
|
||||||
} else {
|
|
||||||
radios["plate"] = e.id;
|
|
||||||
curr = e.id;
|
|
||||||
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
|
||||||
}
|
|
||||||
current["plate"] = curr;
|
|
||||||
document.querySelectorAll("#resume p")[0].innerHTML = name;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addingredient(id, name) {
|
function addingredient(id, name) {
|
||||||
$(ingredient).append(`<li><input type="checkbox" name="ingredient" id="${id}"><label for="${id}">${name}</label></li>`);
|
$(ingredient).append(`<li><input type="checkbox" disabled=true name="ingredient" id="${id}"><label for="${id}">${name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=${id} ]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
if (e.checked)
|
checkcheck(e, "ingredient", 1, 3)
|
||||||
current["content"].push(e.id);
|
|
||||||
else
|
|
||||||
current["content"].splice(current["content"].indexOf(e.id), 1);
|
|
||||||
let content = [];
|
|
||||||
document.querySelectorAll("input[name=ingredient]").forEach( e => {
|
|
||||||
if (e.checked)
|
|
||||||
content.push(document.querySelector(`label[for=${e.id}]`).innerHTML)
|
|
||||||
});
|
|
||||||
document.querySelectorAll("#resume p")[1].innerHTML = content.join(" - ");
|
|
||||||
document.querySelectorAll("input[name=ingredient]").forEach( e => {
|
|
||||||
if (!e.checked)
|
|
||||||
e.disabled = content.length === 3
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addsauce(id, name) {
|
function addsauce(id, name) {
|
||||||
$(sauce).append(`<li><input type="checkbox" name="sauce" id="${id}"><label for="${id}">${name}</label></li>`);
|
$(sauce).append(`<li><input type="checkbox" disabled=true name="sauce" id="${id}"><label for="${id}">${name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=${id} ]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
if (e.checked)
|
checkcheck(e, "sauce", 2, 2)
|
||||||
current["sauce"].push(e.id);
|
|
||||||
else
|
|
||||||
current["sauce"].splice(current["sauce"].indexOf(e.id), 1);
|
|
||||||
let content = [];
|
|
||||||
document.querySelectorAll("input[name=sauce]").forEach( e => {
|
|
||||||
if (e.checked)
|
|
||||||
content.push(document.querySelector(`label[for=${e.id}]`).innerHTML)
|
|
||||||
});
|
|
||||||
document.querySelectorAll("#resume p")[2].innerHTML = content.join(" - ");
|
|
||||||
document.querySelectorAll("input[name=sauce]").forEach( e => {
|
|
||||||
if (!e.checked)
|
|
||||||
e.disabled = content.length === 2
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function adddrink(id, name) {
|
function adddrink(id, name) {
|
||||||
$(drink).append(`<li><input type="radio" name="boisson" id="${id}"><label for="${id}">${name}</label></li>`);
|
$(drink).append(`<li><input type="radio" name="drink" id="${id}"><label for="${id}">${name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=${id} ]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
if (e.checked) {
|
radiocheck(e, "drink", 3)
|
||||||
let curr, name;
|
|
||||||
if (e.id === radios["plate"]) {
|
|
||||||
e.checked = false;
|
|
||||||
radios["plate"] = null;
|
|
||||||
curr = null;
|
|
||||||
name = null;
|
|
||||||
} else {
|
|
||||||
radios["plate"] = e.id;
|
|
||||||
curr = e.id;
|
|
||||||
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
|
||||||
}
|
|
||||||
current["drink"] = curr;
|
|
||||||
document.querySelectorAll("#resume p")[3].innerHTML = name;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,22 +83,38 @@ function adddessert(id, name) {
|
||||||
$(dessert).append(`<li><input type="radio" name="dessert" id="${id}"><label for="${id}">${name}</label></li>`);
|
$(dessert).append(`<li><input type="radio" name="dessert" id="${id}"><label for="${id}">${name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=${id} ]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
|
radiocheck(e, "dessert", 4)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function radiocheck (e, n, p) {
|
||||||
if (e.checked) {
|
if (e.checked) {
|
||||||
let curr, name;
|
let curr, name;
|
||||||
if (e.id === radios["plate"]) {
|
if (e.id === radios[n]) {
|
||||||
e.checked = false;
|
e.checked = false;
|
||||||
radios["plate"] = null;
|
radios[n] = null;
|
||||||
curr = null;
|
curr = null;
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
radios["plate"] = e.id;
|
radios[n] = e.id;
|
||||||
curr = e.id;
|
curr = e.id;
|
||||||
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
||||||
}
|
}
|
||||||
current["dessert"] = curr;
|
current[n] = curr;
|
||||||
document.querySelectorAll("#resume p")[4].innerHTML = name;
|
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(" - ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear(e) {
|
function clear(e) {
|
||||||
|
@ -193,7 +160,7 @@ socket.on("list command", data => {
|
||||||
child = list.lastElementChild;
|
child = list.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let c of data.list) {
|
for (let c of data.list) {
|
||||||
addcmd(c.id, c.plate, c.content, c.sauce, c.drink, c.dessert, c.state);
|
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,7 +220,7 @@ socket.on("list dessert", data => {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("new command", 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.ingredient, data.sauce, data.drink, data.dessert, data.state);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("cleared command", data => {
|
socket.on("cleared command", data => {
|
||||||
|
@ -274,14 +241,16 @@ socket.on("glitched command", data => {
|
||||||
|
|
||||||
document.querySelector(".validation").addEventListener("click", ev => {
|
document.querySelector(".validation").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
current["pc"] = 1;
|
|
||||||
current["sandwitch"] = 1;
|
|
||||||
current["client"] = 1;
|
current["client"] = 1;
|
||||||
|
|
||||||
socket.emit("add command", current);
|
socket.emit("add command", current);
|
||||||
current = {"plate": null, "content": [], "sauce": [], "drink": null, "dessert": null};
|
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
|
||||||
document.querySelectorAll("input").forEach( e => {
|
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
|
||||||
e.checked = false
|
e.checked = false;
|
||||||
|
});
|
||||||
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( e => {
|
||||||
|
e.checked = false;
|
||||||
|
e.disabled = true;
|
||||||
});
|
});
|
||||||
document.querySelectorAll("#resume p").forEach( e => {
|
document.querySelectorAll("#resume p").forEach( e => {
|
||||||
e.innerHTML = ""
|
e.innerHTML = ""
|
||||||
|
|
Reference in a new issue