Archived
1
0
Fork 0

Setup dynamic max for ingredients and sauces, replace avoid if 0

This commit is contained in:
Ethanell 2020-05-30 16:11:58 +02:00
parent 78da882f85
commit df5cba87ad
3 changed files with 11 additions and 14 deletions

View file

@ -11,14 +11,12 @@ module.exports = (sequelize, DataTypes) => {
defaultValue: 0, defaultValue: 0,
allowNull: false allowNull: false
}, },
avoidIngredients: { maxIngredients: {
type: DataTypes.BOOLEAN, type: DataTypes.INTEGER,
defaultValue: false,
allowNull: false allowNull: false
}, },
avoidSauces: { maxSauces: {
type: DataTypes.BOOLEAN, type: DataTypes.INTEGER,
defaultValue: false,
allowNull: false allowNull: false
} }
}, { }, {

View file

@ -65,7 +65,7 @@ function addDish(d) {
el.click(); el.click();
}); });
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => { document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
el.disabled = !(e.checked && !db.dish[e.id.replace(e.name, "")]["avoid" + el.name.charAt(0).toUpperCase() + el.name.slice(1)]); el.disabled = !(e.checked && !(db.dish[e.id.replace(e.name, "")]["max" + el.name.charAt(0).toUpperCase() + el.name.slice(1)+"s"] === 0));
}); });
}) })
} }
@ -74,7 +74,7 @@ function addIngredient(i) {
ingredient.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="ingredient" id="ingredient${i.id}"><label for="ingredient${i.id}">${i.name}</label></li>`); ingredient.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="ingredient" id="ingredient${i.id}"><label for="ingredient${i.id}">${i.name}</label></li>`);
let e = document.querySelector(`input[id=ingredient${i.id}]`); let e = document.querySelector(`input[id=ingredient${i.id}]`);
e.addEventListener("click", () => { e.addEventListener("click", () => {
checkCheck(e, 3) checkCheck(e)
}) })
} }
@ -82,7 +82,7 @@ function addSauce(s) {
sauce.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="sauce" id="sauce${s.id}"><label for="sauce${s.id}">${s.name}</label></li>`); sauce.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="sauce" id="sauce${s.id}"><label for="sauce${s.id}">${s.name}</label></li>`);
let e = document.querySelector(`input[id=sauce${s.id}]`); let e = document.querySelector(`input[id=sauce${s.id}]`);
e.addEventListener("click", () => { e.addEventListener("click", () => {
checkCheck(e,2) checkCheck(e)
}) })
} }
@ -125,15 +125,14 @@ function radioCheck (e) {
} }
} }
function checkCheck(e, l) { function checkCheck(e) {
//ToDo setup dynamic maxSauces and maxIngredients from db !
if (e.checked) if (e.checked)
current[e.name].push(e.id.replace(e.name, "")); current[e.name].push(e.id.replace(e.name, ""));
else else
current[e.name].splice(current[e.name].indexOf(e.id.replace(e.name, "")), 1); current[e.name].splice(current[e.name].indexOf(e.id.replace(e.name, "")), 1);
document.querySelectorAll(`input[name=${e.name}]`).forEach( e => { document.querySelectorAll(`input[name=${e.name}]`).forEach( e => {
if (!e.checked) if (!e.checked)
e.disabled = current[e.name].length === l e.disabled = current[e.name].length === db.dish[current.dish]["max"+e.name.charAt(0).toUpperCase() + e.name.slice(1)+"s"];
}); });
current.price[e.name] = 0; current.price[e.name] = 0;
for (let i of current[e.name]) { for (let i of current[e.name]) {

View file

@ -8,8 +8,8 @@ module.exports = socket => {
id: d.id, id: d.id,
name: d.name, name: d.name,
price: d.price, price: d.price,
avoidIngredients: d.avoidIngredients, maxIngredients: d.maxIngredients,
avoidSauces: d.avoidSauces maxSauces: d.maxSauces
}); });
} }
socket.emit("list dish", dishes); socket.emit("list dish", dishes);