Price and no ingredients support
This commit is contained in:
parent
03357f1a5b
commit
4094ffc5c8
4 changed files with 52 additions and 14 deletions
|
@ -63,6 +63,9 @@ class Plate(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
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")
|
command = db.relationship("Command", backref="plate", lazy="dynamic")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -73,6 +76,8 @@ class Ingredient(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
|
price = db.Column(db.Float, default=0)
|
||||||
|
|
||||||
command = db.relationship("Command", secondary="get")
|
command = db.relationship("Command", secondary="get")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -91,6 +96,8 @@ class Sauce(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
|
price = db.Column(db.Float, default=0)
|
||||||
|
|
||||||
command = db.relationship("Command", secondary="cover")
|
command = db.relationship("Command", secondary="cover")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -109,6 +116,8 @@ class Drink(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
|
price = db.Column(db.Float, default=0)
|
||||||
|
|
||||||
command = db.relationship("Command", backref="drink", lazy="dynamic")
|
command = db.relationship("Command", backref="drink", lazy="dynamic")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -119,6 +128,8 @@ class Dessert(db.Model):
|
||||||
id = db.Column(db.String, primary_key=True)
|
id = db.Column(db.String, primary_key=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
|
||||||
|
price = db.Column(db.Float, default=0)
|
||||||
|
|
||||||
command = db.relationship("Command", backref="dessert", lazy="dynamic")
|
command = db.relationship("Command", backref="dessert", lazy="dynamic")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -197,7 +197,7 @@ def errcmd(json):
|
||||||
def lsplate():
|
def lsplate():
|
||||||
plates = []
|
plates = []
|
||||||
for p in Plate.query.all():
|
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})
|
emit("list plate", {"list": plates})
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,8 +205,8 @@ def lsplate():
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def lsingredient():
|
def lsingredient():
|
||||||
ingredients = []
|
ingredients = []
|
||||||
for p in Ingredient.query.all():
|
for i in Ingredient.query.all():
|
||||||
ingredients.append({"id": p.id, "name": p.name})
|
ingredients.append({"id": i.id, "name": i.name, "price": i.price})
|
||||||
emit("list ingredient", {"list": ingredients})
|
emit("list ingredient", {"list": ingredients})
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,8 +214,8 @@ def lsingredient():
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def lssauce():
|
def lssauce():
|
||||||
sauces = []
|
sauces = []
|
||||||
for p in Sauce.query.all():
|
for s in Sauce.query.all():
|
||||||
sauces.append({"id": p.id, "name": p.name})
|
sauces.append({"id": s.id, "name": s.name, "price": s.price})
|
||||||
emit("list sauce", {"list": sauces})
|
emit("list sauce", {"list": sauces})
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ def lssauce():
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def lsdrink():
|
def lsdrink():
|
||||||
drinks = []
|
drinks = []
|
||||||
for p in Drink.query.all():
|
for d in Drink.query.all():
|
||||||
drinks.append({"id": p.id, "name": p.name})
|
drinks.append({"id": d.id, "name": d.name, "price": d.price})
|
||||||
emit("list drink", {"list": drinks})
|
emit("list drink", {"list": drinks})
|
||||||
|
|
||||||
|
|
||||||
|
@ -232,8 +232,8 @@ def lsdrink():
|
||||||
@authenticated_only
|
@authenticated_only
|
||||||
def lsdessert():
|
def lsdessert():
|
||||||
desserts = []
|
desserts = []
|
||||||
for p in Dessert.query.all():
|
for d in Dessert.query.all():
|
||||||
desserts.append({"id": p.id, "name": p.name})
|
desserts.append({"id": d.id, "name": d.name, "price": d.price})
|
||||||
emit("list dessert", {"list": desserts})
|
emit("list dessert", {"list": desserts})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ 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, "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 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) {
|
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) {
|
||||||
|
@ -54,9 +55,12 @@ function addplate(id, name) {
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
radiocheck(e, "plate",0);
|
radiocheck(e, "plate",0);
|
||||||
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
||||||
el.disabled = !e.checked;
|
if (e.checked && !db["plate"][e.id]["avoid ingredient"])
|
||||||
if (!e.checked)
|
el.disabled = false;
|
||||||
|
else {
|
||||||
|
el.disabled = true;
|
||||||
el.checked = false
|
el.checked = false
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -107,6 +111,11 @@ function radiocheck (e, n, p) {
|
||||||
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
||||||
}
|
}
|
||||||
current[n] = curr;
|
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;
|
document.querySelectorAll("#resume p")[p].innerHTML = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +129,11 @@ function checkcheck(e, n, p, l) {
|
||||||
if (!e.checked)
|
if (!e.checked)
|
||||||
e.disabled = current[n].length === l
|
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(" - ");
|
document.querySelectorAll("#resume p")[p].innerHTML = current[n].join(" - ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +169,14 @@ function error(e) {
|
||||||
list.appendChild(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 => {
|
socket.on("connect", data => {
|
||||||
if (data === "ok") {
|
if (data === "ok") {
|
||||||
socket.emit("list plate");
|
socket.emit("list plate");
|
||||||
|
@ -185,6 +207,7 @@ socket.on("list plate", data => {
|
||||||
}
|
}
|
||||||
for (let p of data.list) {
|
for (let p of data.list) {
|
||||||
addplate(p.id, p.name);
|
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) {
|
for (let i of data.list) {
|
||||||
addingredient(i.id, i.name);
|
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) {
|
for (let s of data.list) {
|
||||||
addsauce(s.id, s.name);
|
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) {
|
for (let d of data.list) {
|
||||||
adddrink(d.id, d.name);
|
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) {
|
for (let d of data.list) {
|
||||||
adddessert(d.id, d.name);
|
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;
|
current["client"] = user.value;
|
||||||
socket.emit("add command", current);
|
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 => {
|
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {
|
||||||
e.checked = false;
|
e.checked = false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<datalist id="user_list">
|
<datalist id="user_list">
|
||||||
</datalist>
|
</datalist>
|
||||||
<button class="validation" type="submit">Valider</button>
|
<button class="validation" type="submit">Valider</button>
|
||||||
<h2>3,40€</h2>
|
<h2>0€</h2>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Reference in a new issue