1
0
Fork 0

Price and no ingredients support

This commit is contained in:
Ethanell 2020-02-04 23:40:39 +01:00
parent 03357f1a5b
commit 4094ffc5c8
4 changed files with 52 additions and 14 deletions

View file

@ -63,6 +63,9 @@ class Plate(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
price = db.Column(db.Integer, default=0)
avoid_ingredient = db.Column(db.Boolean, default=False)
command = db.relationship("Command", backref="plate", lazy="dynamic")
def __repr__(self):
@ -73,6 +76,8 @@ class Ingredient(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
price = db.Column(db.Float, default=0)
command = db.relationship("Command", secondary="get")
def __repr__(self):
@ -91,6 +96,8 @@ class Sauce(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
price = db.Column(db.Float, default=0)
command = db.relationship("Command", secondary="cover")
def __repr__(self):
@ -109,6 +116,8 @@ class Drink(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
price = db.Column(db.Float, default=0)
command = db.relationship("Command", backref="drink", lazy="dynamic")
def __repr__(self):
@ -119,6 +128,8 @@ class Dessert(db.Model):
id = db.Column(db.String, primary_key=True)
name = db.Column(db.String, nullable=False)
price = db.Column(db.Float, default=0)
command = db.relationship("Command", backref="dessert", lazy="dynamic")
def __repr__(self):

View file

@ -197,7 +197,7 @@ def errcmd(json):
def lsplate():
plates = []
for p in Plate.query.all():
plates.append({"id": p.id, "name": p.name})
plates.append({"id": p.id, "name": p.name, "price": p.price, "avoid ingredient": p.avoid_ingredient})
emit("list plate", {"list": plates})
@ -205,8 +205,8 @@ def lsplate():
@authenticated_only
def lsingredient():
ingredients = []
for p in Ingredient.query.all():
ingredients.append({"id": p.id, "name": p.name})
for i in Ingredient.query.all():
ingredients.append({"id": i.id, "name": i.name, "price": i.price})
emit("list ingredient", {"list": ingredients})
@ -214,8 +214,8 @@ def lsingredient():
@authenticated_only
def lssauce():
sauces = []
for p in Sauce.query.all():
sauces.append({"id": p.id, "name": p.name})
for s in Sauce.query.all():
sauces.append({"id": s.id, "name": s.name, "price": s.price})
emit("list sauce", {"list": sauces})
@ -223,8 +223,8 @@ def lssauce():
@authenticated_only
def lsdrink():
drinks = []
for p in Drink.query.all():
drinks.append({"id": p.id, "name": p.name})
for d in Drink.query.all():
drinks.append({"id": d.id, "name": d.name, "price": d.price})
emit("list drink", {"list": drinks})
@ -232,8 +232,8 @@ def lsdrink():
@authenticated_only
def lsdessert():
desserts = []
for p in Dessert.query.all():
desserts.append({"id": p.id, "name": p.name})
for d in Dessert.query.all():
desserts.append({"id": d.id, "name": d.name, "price": d.price})
emit("list dessert", {"list": desserts})

View file

@ -5,8 +5,9 @@ let sauce = document.querySelector("#sauce ul");
let drink = document.querySelector("#boisson ul");
let dessert = document.querySelector("#dessert ul");
let list = document.querySelector(".liste");
let current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
let current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
let radios = {"plate": null, "drink": null, "dessert": null};
let db = {"plate": {}, "ingredient": {}, "sauce": {}, "drink": {}, "dessert": {}};
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) {
@ -54,9 +55,12 @@ function addplate(id, name) {
e.addEventListener("click", () => {
radiocheck(e, "plate",0);
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
el.disabled = !e.checked;
if (!e.checked)
if (e.checked && !db["plate"][e.id]["avoid ingredient"])
el.disabled = false;
else {
el.disabled = true;
el.checked = false
}
});
})
}
@ -107,6 +111,11 @@ function radiocheck (e, n, p) {
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
}
current[n] = curr;
if (curr)
current["price"][n] = db[n][curr]["price"];
else
current["price"][n] = 0;
price();
document.querySelectorAll("#resume p")[p].innerHTML = name;
}
}
@ -120,6 +129,11 @@ function checkcheck(e, n, p, l) {
if (!e.checked)
e.disabled = current[n].length === l
});
current["price"][n] = 0;
for (let i of current[n]) {
current["price"][n] += db[n][i]["price"]
}
price();
document.querySelectorAll("#resume p")[p].innerHTML = current[n].join(" - ");
}
@ -155,6 +169,14 @@ function error(e) {
list.appendChild(e);
}
function price () {
let p = 0;
for (let i in current["price"]) {
p += current["price"][i]
}
document.querySelector("#resume h2").innerHTML = p+"€";
}
socket.on("connect", data => {
if (data === "ok") {
socket.emit("list plate");
@ -185,6 +207,7 @@ socket.on("list plate", data => {
}
for (let p of data.list) {
addplate(p.id, p.name);
db["plate"][p.id] = {"name": p.name, "price": p.price, "avoid ingredient": p["avoid ingredient"]}
}
});
@ -196,6 +219,7 @@ socket.on("list ingredient", data => {
}
for (let i of data.list) {
addingredient(i.id, i.name);
db["ingredient"][i.id] = {"name": i.name, "price": i.price}
}
});
@ -207,6 +231,7 @@ socket.on("list sauce", data => {
}
for (let s of data.list) {
addsauce(s.id, s.name);
db["sauce"][s.id] = {"name": s.name, "price": s.price}
}
});
@ -218,6 +243,7 @@ socket.on("list drink", data => {
}
for (let d of data.list) {
adddrink(d.id, d.name);
db["drink"][d.id] = {"name": d.name, "price": d.price}
}
});
@ -229,6 +255,7 @@ socket.on("list dessert", data => {
}
for (let d of data.list) {
adddessert(d.id, d.name);
db["dessert"][d.id] = {"name": d.name, "price": d.price}
}
});
@ -269,7 +296,7 @@ document.querySelector(".validation").addEventListener("click", ev => {
current["client"] = user.value;
socket.emit("add command", current);
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null};
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
e.checked = false;
});

View file

@ -67,7 +67,7 @@
<datalist id="user_list">
</datalist>
<button class="validation" type="submit">Valider</button>
<h2>3,40€</h2>
<h2>0€</h2>
</div>
</form>