Fix order taking of commands
This commit is contained in:
parent
d95a0e9918
commit
fed23f4248
16 changed files with 368 additions and 186 deletions
2
bin/www
2
bin/www
|
@ -27,7 +27,7 @@ let server = http.createServer(app);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const io = require("socket.io")(server);
|
const io = require("socket.io")(server);
|
||||||
io.on("connection", require("../socket"));
|
io.on("connection", require("../sockets"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen on provided port, on all network interfaces.
|
* Listen on provided port, on all network interfaces.
|
||||||
|
|
|
@ -3,7 +3,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
const Command = sequelize.define('Command', {
|
const Command = sequelize.define('Command', {
|
||||||
number: {
|
number: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: "uniqueNumberPerDay"
|
||||||
},
|
},
|
||||||
price: {
|
price: {
|
||||||
type: DataTypes.FLOAT,
|
type: DataTypes.FLOAT,
|
||||||
|
@ -12,7 +13,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
date: {
|
date: {
|
||||||
type: DataTypes.DATEONLY,
|
type: DataTypes.DATEONLY,
|
||||||
defaultValue: DataTypes.NOW,
|
defaultValue: DataTypes.NOW,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: "uniqueNumberPerDay"
|
||||||
},
|
},
|
||||||
take: {
|
take: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
@ -41,13 +43,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
Command.associate = function(models) {
|
Command.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
Command.belongsTo(models.User, {
|
Command.belongsTo(models.User, {
|
||||||
as: "command"
|
as: "client"
|
||||||
});
|
});
|
||||||
Command.belongsTo(models.User, {
|
Command.belongsTo(models.User, {
|
||||||
as: "pcCommand"
|
as: "pc"
|
||||||
});
|
});
|
||||||
Command.belongsTo(models.User, {
|
Command.belongsTo(models.User, {
|
||||||
as: "sandwichCommand"
|
as: "sandwich"
|
||||||
});
|
});
|
||||||
Command.belongsTo(models.Dish);
|
Command.belongsTo(models.Dish);
|
||||||
Command.belongsToMany(models.Ingredient, {
|
Command.belongsToMany(models.Ingredient, {
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
allowNull: false
|
allowNull: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
tableName: "dishes"
|
tableName: "Dishes"
|
||||||
});
|
});
|
||||||
Dish.associate = function(models) {
|
Dish.associate = function(models) {
|
||||||
Dish.hasMany(models.Command);
|
Dish.hasMany(models.Command);
|
||||||
|
|
|
@ -3,33 +3,27 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
const User = sequelize.define('User', {
|
const User = sequelize.define('User', {
|
||||||
username: {
|
username: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
},
|
},
|
||||||
passwordHash: {
|
passwordHash: {
|
||||||
type: DataTypes.STRING
|
type: DataTypes.STRING
|
||||||
},
|
},
|
||||||
firstName: {
|
firstName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: "userFullName"
|
||||||
},
|
},
|
||||||
lastName: {
|
lastName: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: "userFullName"
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
tableName: "Users"
|
tableName: "Users"
|
||||||
});
|
});
|
||||||
User.associate = function(models) {
|
User.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
User.hasMany(models.Command, {
|
|
||||||
as: "client"
|
|
||||||
});
|
|
||||||
User.hasMany(models.Command, {
|
|
||||||
as: "pc"
|
|
||||||
});
|
|
||||||
User.hasMany(models.Command, {
|
|
||||||
as: "sandwich"
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
return User;
|
return User;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,145 +1,153 @@
|
||||||
let socket = io();
|
const socket = io();
|
||||||
let plate = document.querySelector("#plat ul");
|
const dish = document.querySelector("#dish ul");
|
||||||
let ingredient = document.querySelector("#ingredient ul");
|
const ingredient = document.querySelector("#ingredient ul");
|
||||||
let sauce = document.querySelector("#sauce ul");
|
const sauce = document.querySelector("#sauce ul");
|
||||||
let drink = document.querySelector("#boisson ul");
|
const drink = document.querySelector("#drink ul");
|
||||||
let dessert = document.querySelector("#dessert ul");
|
const dessert = document.querySelector("#dessert ul");
|
||||||
let list = document.querySelector(".liste");
|
const list = document.querySelector(".list");
|
||||||
let current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
|
|
||||||
let radios = {"plate": null, "drink": null, "dessert": null};
|
let current = {dish: null, ingredient: [], sauce: [], drink: null, dessert: null, price: {}};
|
||||||
let db = {"plate": {}, "ingredient": {}, "sauce": {}, "drink": {}, "dessert": {}};
|
let radios = {dish: null, drink: null, dessert: null};
|
||||||
|
let db = {dish: {}, ingredient: {}, sauce: {}, drink: {}, dessert: {}};
|
||||||
|
|
||||||
|
|
||||||
function addcmd(id, plate, ingredient, sauce, drink, dessert, state, client, sandwich) {
|
function addCmd(command) {
|
||||||
for (let i of ["plate", "ingredient", "sauce", "drink", "dessert", "state", "sandwich"])
|
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${command.number}">
|
||||||
if (!eval(i))
|
<button class="give">Give</button>
|
||||||
eval(`${i} = ""`);
|
<h1>${command.number}</h1>
|
||||||
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${id}"> <button class="donner">Donnée</button> <h1>${id}</h1> <div class="spec"> <h2>${sandwich}</h2><h3>${client}</h3><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>`);
|
<div class="spec">
|
||||||
let e = document.querySelector(`.liste #cmd${id}`);
|
<h2>${command.sandwich}</h2>
|
||||||
|
<h3>${command.client}</h3>
|
||||||
|
<p>${command.dish}</p>
|
||||||
|
<p>${command.ingredients}</p>
|
||||||
|
<p>${command.sauces}</p>
|
||||||
|
<p>${command.drink}</p>
|
||||||
|
<p>${command.dessert}</p>
|
||||||
|
<button class="cancel">Cancel</button>
|
||||||
|
<button class="error">Error</button>
|
||||||
|
</div>
|
||||||
|
</div>`);
|
||||||
|
let e = document.querySelector(`.list #cmd${command.number}`);
|
||||||
e.addEventListener( "click" ,ev => {
|
e.addEventListener( "click" ,ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
e.classList.toggle("show-spec");
|
e.classList.toggle("show-spec");
|
||||||
});
|
});
|
||||||
e.querySelector(".donner").addEventListener("click", ev => {
|
e.querySelector(".give").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
socket.emit("give command", {"id": id});
|
socket.emit("give command", {"id": command.number});
|
||||||
});
|
});
|
||||||
e.querySelector(".annuler").addEventListener("click", ev => {
|
e.querySelector(".cancel").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
socket.emit("clear command", {"id": id});
|
socket.emit("clear command", {"id": command.number});
|
||||||
});
|
});
|
||||||
e.querySelector(".erreur").addEventListener("click", ev => {
|
e.querySelector(".error").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
socket.emit("error command", {"id": id});
|
socket.emit("error command", {"id": command.number});
|
||||||
});
|
});
|
||||||
switch (state) {
|
if (command.error)
|
||||||
case "WIP":
|
error(e)
|
||||||
WIP(e, sandwich);
|
else if (command.give)
|
||||||
break;
|
give(e)
|
||||||
case "done":
|
else if (command.done)
|
||||||
done(e);
|
done(e)
|
||||||
break;
|
else if (command.WIP)
|
||||||
case "gave":
|
WIP(e, command.sandwich)
|
||||||
give(e);
|
document.querySelector("#resume>h1").innerHTML = `Command ${command.number+1}`;
|
||||||
break;
|
|
||||||
case "error":
|
|
||||||
error(e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
document.querySelector("#resume>h1").innerHTML = `Commande ${id+1}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addplate(id, name) {
|
function addDish(d) {
|
||||||
plate.insertAdjacentHTML("beforeend", `<li><input type="radio" name="plate" id="${id}"><label for="${id}">${name}</label></li>`);
|
dish.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dish" id="dish${d.id}"><label for="dish${d.id}">${d.name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=dish${d.id}]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
radiocheck(e, "plate",0);
|
radioCheck(e);
|
||||||
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
||||||
if (el.checked)
|
if (el.checked)
|
||||||
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["plate"][e.id]["avoid " + el.name]);
|
el.disabled = !(e.checked && !db.dish[e.id.replace(e.name, "")]["avoid" + el.name.charAt(0).toUpperCase() + el.name.slice(1)]);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addingredient(id, name) {
|
function addIngredient(i) {
|
||||||
ingredient.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="ingredient" id="${id}"><label for="${id}">${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=${id} ]`);
|
let e = document.querySelector(`input[id=ingredient${i.id}]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
checkcheck(e, "ingredient", 1, 3)
|
checkCheck(e, 3)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addsauce(id, name) {
|
function addSauce(s) {
|
||||||
sauce.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="sauce" id="${id}"><label for="${id}">${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=${id} ]`);
|
let e = document.querySelector(`input[id=sauce${s.id}]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
checkcheck(e, "sauce", 2, 2)
|
checkCheck(e,2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function adddrink(id, name) {
|
function addDrink(d) {
|
||||||
drink.insertAdjacentHTML("beforeend", `<li><input type="radio" name="drink" id="${id}"><label for="${id}">${name}</label></li>`);
|
drink.insertAdjacentHTML("beforeend", `<li><input type="radio" name="drink" id="drink${d.id}"><label for="drink${d.id}">${d.name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=drink${d.id}]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
radiocheck(e, "drink", 3)
|
radioCheck(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function adddessert(id, name) {
|
function addDessert(d) {
|
||||||
dessert.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dessert" id="${id}"><label for="${id}">${name}</label></li>`);
|
dessert.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dessert" id="dessert${d.id}"><label for="dessert${d.id}">${d.name}</label></li>`);
|
||||||
let e = document.querySelector(`input[id=${id} ]`);
|
let e = document.querySelector(`input[id=dessert${d.id}]`);
|
||||||
e.addEventListener("click", () => {
|
e.addEventListener("click", () => {
|
||||||
radiocheck(e, "dessert", 4)
|
radioCheck(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function radiocheck (e, n, p) {
|
function radioCheck (e) {
|
||||||
if (e.checked) {
|
if (e.checked) {
|
||||||
let curr, name;
|
let curr, name;
|
||||||
if (e.id === radios[n]) {
|
if (e.id.replace(e.name, "") === radios[e.name]) {
|
||||||
e.checked = false;
|
e.checked = false;
|
||||||
radios[n] = null;
|
radios[e.name] = null;
|
||||||
curr = null;
|
curr = null;
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
radios[n] = e.id;
|
radios[e.name] = e.id.replace(e.name, "");
|
||||||
curr = e.id;
|
curr = e.id.replace(e.name, "");
|
||||||
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
||||||
}
|
}
|
||||||
current[n] = curr;
|
current[e.name] = curr;
|
||||||
if (curr)
|
if (curr)
|
||||||
current["price"][n] = db[n][curr]["price"];
|
current.price[e.name] = db[e.name][curr.replace(e.name, "")].price;
|
||||||
else
|
else
|
||||||
current["price"][n] = 0;
|
current.price[e.name] = 0;
|
||||||
price();
|
price();
|
||||||
document.querySelectorAll("#resume p")[p].innerHTML = name;
|
document.getElementById("p-"+e.name).innerHTML = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkcheck(e, n, p, l) {
|
function checkCheck(e, l) {
|
||||||
if (e.checked)
|
if (e.checked)
|
||||||
current[n].push(e.id);
|
current[e.name].push(e.id.replace(e.name, ""));
|
||||||
else
|
else
|
||||||
current[n].splice(current[n].indexOf(e.id), 1);
|
current[e.name].splice(current[e.name].indexOf(e.id.replace(e.name, "")), 1);
|
||||||
document.querySelectorAll(`input[name=${n}]`).forEach( e => {
|
document.querySelectorAll(`input[name=${e.name}]`).forEach( e => {
|
||||||
if (!e.checked)
|
if (!e.checked)
|
||||||
e.disabled = current[n].length === l
|
e.disabled = current[e.name].length === l
|
||||||
});
|
});
|
||||||
current["price"][n] = 0;
|
current.price[e.name] = 0;
|
||||||
for (let i of current[n]) {
|
for (let i of current[e.name]) {
|
||||||
current["price"][n] += db[n][i]["price"]
|
current.price[e.name] += db[e.name][i].price
|
||||||
}
|
}
|
||||||
price();
|
price();
|
||||||
document.querySelectorAll("#resume p")[p].innerHTML = current[n].join(" - ");
|
let names = [];
|
||||||
|
current[e.name].forEach(el=>names.push(document.querySelector(`label[for=${e.name}${el}]`).innerHTML));
|
||||||
|
document.getElementById("p-"+e.name).innerHTML = names.join(" - ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear(e) {
|
function clear(e) {
|
||||||
e.classList.remove("finis");
|
e.classList.remove("done");
|
||||||
e.classList.remove("donnee");
|
e.classList.remove("give");
|
||||||
e.classList.remove("probleme");
|
e.classList.remove("warning");
|
||||||
e.classList.remove("WIP");
|
e.classList.remove("WIP");
|
||||||
e.classList.remove("show-spec");
|
e.classList.remove("show-spec");
|
||||||
list.prepend(e);
|
list.prepend(e);
|
||||||
|
@ -164,29 +172,27 @@ function give(e) {
|
||||||
|
|
||||||
function error(e) {
|
function error(e) {
|
||||||
e.classList.remove("show-spec");
|
e.classList.remove("show-spec");
|
||||||
e.classList.add("probleme");
|
e.classList.add("warning");
|
||||||
list.appendChild(e);
|
list.appendChild(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
function price() {
|
function price() {
|
||||||
let p = 0;
|
let p = 0;
|
||||||
for (let i in current["price"]) {
|
for (let i in current.price) {
|
||||||
p += current["price"][i]
|
p += current.price[i]
|
||||||
}
|
}
|
||||||
p = p.toFixed(2);
|
p = p.toFixed(2);
|
||||||
document.querySelector("#resume h2").innerHTML = p+"€";
|
document.querySelector("#resume h2").innerHTML = p+"€";
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on("connect", data => {
|
socket.on("connected", () => {
|
||||||
if (data === "ok") {
|
socket.emit("list dish");
|
||||||
socket.emit("list plate");
|
socket.emit("list ingredient");
|
||||||
socket.emit("list ingredient");
|
socket.emit("list sauce");
|
||||||
socket.emit("list sauce");
|
socket.emit("list drink");
|
||||||
socket.emit("list drink");
|
socket.emit("list dessert");
|
||||||
socket.emit("list dessert");
|
socket.emit("list command");
|
||||||
socket.emit("list command");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list command", data => {
|
socket.on("list command", data => {
|
||||||
|
@ -195,20 +201,20 @@ socket.on("list command", data => {
|
||||||
list.removeChild(child);
|
list.removeChild(child);
|
||||||
child = list.lastElementChild;
|
child = list.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let c of data.list) {
|
for (let c of data) {
|
||||||
addcmd(c.id, c.plate, c.ingredient, c.sauce, c.drink, c.dessert, c.state, c.client, c.sandwich);
|
addCmd(c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list plate", data => {
|
socket.on("list dish", data => {
|
||||||
let child = plate.lastElementChild;
|
let child = dish.lastElementChild;
|
||||||
while (child) {
|
while (child) {
|
||||||
plate.removeChild(child);
|
dish.removeChild(child);
|
||||||
child = plate.lastElementChild;
|
child = dish.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let p of data.list) {
|
for (let d of data) {
|
||||||
addplate(p.id, p.name);
|
addDish(d);
|
||||||
db["plate"][p.id] = {"name": p.name, "price": p.price, "avoid ingredient": p.avoid_ingredient, "avoid sauce": p.avoid_sauce}
|
db.dish[d.id] = d;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -218,9 +224,9 @@ socket.on("list ingredient", data => {
|
||||||
ingredient.removeChild(child);
|
ingredient.removeChild(child);
|
||||||
child = ingredient.lastElementChild;
|
child = ingredient.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let i of data.list) {
|
for (let i of data) {
|
||||||
addingredient(i.id, i.name);
|
addIngredient(i);
|
||||||
db["ingredient"][i.id] = {"name": i.name, "price": i.price}
|
db.ingredient[i.id] = i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -230,9 +236,9 @@ socket.on("list sauce", data => {
|
||||||
sauce.removeChild(child);
|
sauce.removeChild(child);
|
||||||
child = sauce.lastElementChild;
|
child = sauce.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let s of data.list) {
|
for (let s of data) {
|
||||||
addsauce(s.id, s.name);
|
addSauce(s);
|
||||||
db["sauce"][s.id] = {"name": s.name, "price": s.price}
|
db.sauce[s.id] = s;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -242,9 +248,9 @@ socket.on("list drink", data => {
|
||||||
drink.removeChild(child);
|
drink.removeChild(child);
|
||||||
child = drink.lastElementChild;
|
child = drink.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let d of data.list) {
|
for (let d of data) {
|
||||||
adddrink(d.id, d.name);
|
addDrink(d);
|
||||||
db["drink"][d.id] = {"name": d.name, "price": d.price}
|
db.drink[d.id] = d;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -254,53 +260,57 @@ socket.on("list dessert", data => {
|
||||||
dessert.removeChild(child);
|
dessert.removeChild(child);
|
||||||
child = dessert.lastElementChild;
|
child = dessert.lastElementChild;
|
||||||
}
|
}
|
||||||
for (let d of data.list) {
|
for (let d of data) {
|
||||||
adddessert(d.id, d.name);
|
addDessert(d);
|
||||||
db["dessert"][d.id] = {"name": d.name, "price": d.price}
|
db.dessert[d.id] = d;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("new command", data => {
|
socket.on("new command", data => {
|
||||||
addcmd(data.id, data.plate, data.ingredient, data.sauce, data.drink, data.dessert, data.state, data.client, data.sandwich);
|
addCmd(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("cleared command", data => {
|
socket.on("cleared command", data => {
|
||||||
clear(document.querySelector(`.liste #cmd${data.id}`))
|
clear(document.querySelector(`.list #cmd${data}`))
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("WIPed command", data => {
|
socket.on("WIPed command", data => {
|
||||||
WIP(document.querySelector(`.liste #cmd${data.id}`), data.sandwich)
|
WIP(document.querySelector(`.list #cmd${data.id}`), data.sandwich)
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("finish command", data => {
|
socket.on("finish command", data => {
|
||||||
done(document.querySelector(`.liste #cmd${data.id}`))
|
done(document.querySelector(`.list #cmd${data}`))
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("gave command", data => {
|
socket.on("gave command", data => {
|
||||||
give(document.querySelector(`.liste #cmd${data.id}`))
|
give(document.querySelector(`.list #cmd${data}`))
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("glitched command", data => {
|
socket.on("glitched command", data => {
|
||||||
error(document.querySelector(`.liste #cmd${data.id}`))
|
error(document.querySelector(`.list #cmd${data}`))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("error", () => {
|
||||||
|
alert("An error occurred :")
|
||||||
|
})
|
||||||
|
|
||||||
document.querySelector(".validation").addEventListener("click", ev => {
|
document.querySelector(".validation").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
let user = document.getElementById("user");
|
let user = document.getElementById("user");
|
||||||
if (!current.plate && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert) {
|
if (!current.dish && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert) {
|
||||||
alert("Empty command !");
|
alert("Empty command !");
|
||||||
return;
|
return;
|
||||||
} else if (user.style.color === "red") {
|
} else if (user.style.color === "red") {
|
||||||
current["firstname"] = prompt("Prénom");
|
current.firstname = prompt("Prénom");
|
||||||
current["lastname"] = prompt("Nom");
|
current.lastname = prompt("Nom");
|
||||||
}
|
}
|
||||||
|
|
||||||
current["client"] = user.value;
|
current.client = user.value;
|
||||||
current["pc"] = pc_id;
|
current.pc = 0;
|
||||||
current["price"] = price();
|
current.price = price();
|
||||||
socket.emit("add command", current);
|
socket.emit("add command", current);
|
||||||
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
|
current = {dish: 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=dish],input[name=drink],input[name=dessert]").forEach( e => {
|
||||||
e.checked = false;
|
e.checked = false;
|
||||||
});
|
});
|
||||||
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( e => {
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( e => {
|
||||||
|
@ -329,12 +339,12 @@ function hinter(ev) {
|
||||||
socket.on("list users", data => {
|
socket.on("list users", data => {
|
||||||
let user_list = document.getElementById("user_list");
|
let user_list = document.getElementById("user_list");
|
||||||
user_list.innerHTML = "";
|
user_list.innerHTML = "";
|
||||||
for (let u of data["list"]) {
|
for (let u of data) {
|
||||||
user_list.insertAdjacentHTML("beforeend", `<option value="${u}">`);
|
user_list.insertAdjacentHTML("beforeend", `<option value="${u}">`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = document.getElementById("user");
|
let user = document.getElementById("user");
|
||||||
if (data["list"].indexOf(user.value) === -1)
|
if (data.indexOf(user.value) === -1)
|
||||||
user.style.color = "red";
|
user.style.color = "red";
|
||||||
else {
|
else {
|
||||||
user.style.color = "";
|
user.style.color = "";
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
[ RESTYLE TAG ]*/
|
[ RESTYLE TAG ]*/
|
||||||
|
|
||||||
* {
|
* {
|
||||||
margin: 0px;
|
margin: 0;
|
||||||
padding: 0px;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ body, html {
|
||||||
|
|
||||||
/*---------------------------------------------*/
|
/*---------------------------------------------*/
|
||||||
a {
|
a {
|
||||||
font-family: Poppins-Regular;
|
font-family: Poppins-Regular, serif;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.7;
|
line-height: 1.7;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
margin: 0px;
|
margin: 0;
|
||||||
transition: all 0.4s;
|
transition: all 0.4s;
|
||||||
-webkit-transition: all 0.4s;
|
-webkit-transition: all 0.4s;
|
||||||
-o-transition: all 0.4s;
|
-o-transition: all 0.4s;
|
||||||
|
@ -62,19 +62,19 @@ a:hover {
|
||||||
|
|
||||||
/*---------------------------------------------*/
|
/*---------------------------------------------*/
|
||||||
h1,h2,h3,h4,h5,h6 {
|
h1,h2,h3,h4,h5,h6 {
|
||||||
margin: 0px;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-family: Poppins-Regular;
|
font-family: Poppins-Regular, serif;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.7;
|
line-height: 1.7;
|
||||||
color: #e7e7e7;
|
color: #e7e7e7;
|
||||||
margin: 0px;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul, li {
|
ul, li {
|
||||||
margin: 0px;
|
margin: 0;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ iframe {
|
||||||
|
|
||||||
.contact2-form-title {
|
.contact2-form-title {
|
||||||
display: block;
|
display: block;
|
||||||
font-family: Poppins-Bold;
|
font-family: Poppins-Bold, serif;
|
||||||
font-size: 39px;
|
font-size: 39px;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
|
@ -203,7 +203,7 @@ iframe {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
font-family: Poppins-Regular;
|
font-family: Poppins-Regular, serif;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
color: #555555;
|
color: #555555;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
|
@ -245,10 +245,10 @@ iframe {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|
||||||
font-family: Poppins-Regular;
|
font-family: Poppins-Regular, serif;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #999999;
|
color: #999999;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
|
@ -351,8 +351,7 @@ textarea.input2 + .focus-input2::after {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
|
|
||||||
|
|
||||||
|
font-family: Poppins-Medium, serif;
|
||||||
font-family: Poppins-Medium;
|
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
|
@ -396,10 +395,10 @@ textarea.input2 + .focus-input2::after {
|
||||||
-ms-transform: translateY(-50%);
|
-ms-transform: translateY(-50%);
|
||||||
-o-transform: translateY(-50%);
|
-o-transform: translateY(-50%);
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
right: 0px;
|
right: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|
||||||
font-family: Poppins-Regular;
|
font-family: Poppins-Regular, serif;
|
||||||
color: #c80000;
|
color: #c80000;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
|
@ -416,7 +415,7 @@ textarea.input2 + .focus-input2::after {
|
||||||
|
|
||||||
.alert-validate::after {
|
.alert-validate::after {
|
||||||
content: "\f12a";
|
content: "\f12a";
|
||||||
font-family: FontAwesome;
|
font-family: FontAwesome, serif;
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
color: #c80000;
|
color: #c80000;
|
||||||
|
@ -454,7 +453,7 @@ textarea.input2 + .focus-input2::after {
|
||||||
}
|
}
|
||||||
|
|
||||||
.container h1{
|
.container h1{
|
||||||
font-family: Poppins-Bold;
|
font-family: Poppins-Bold, serif;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
}
|
}
|
||||||
|
@ -509,14 +508,14 @@ textarea.input2 + .focus-input2::after {
|
||||||
|
|
||||||
.list .spec{
|
.list .spec{
|
||||||
display:none;
|
display:none;
|
||||||
box-shadow: 0px 0px 0px 0px black;
|
box-shadow: 0 0 0 0 black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .show-spec .spec{
|
.list .show-spec .spec{
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .annuler {
|
.list .cancel {
|
||||||
background-color: rgb(179, 179, 179);
|
background-color: rgb(179, 179, 179);
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -529,32 +528,32 @@ textarea.input2 + .focus-input2::after {
|
||||||
background-color: rgb(185, 176, 30);
|
background-color: rgb(185, 176, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .donnee {
|
.list .give {
|
||||||
background-color: rgb(0, 105, 0);
|
background-color: rgb(0, 105, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .probleme {
|
.list .warning {
|
||||||
background-color: rgb(133, 1, 1);
|
background-color: rgb(133, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .probleme .erreur, .list .probleme .donner{
|
.list .warning .error, .list .warning .donner{
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .probleme .annuler{
|
.list .warning .cancel{
|
||||||
display: block;
|
display: block;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .erreur{
|
.list .error{
|
||||||
background-color: rgb(133, 1, 1);
|
background-color: rgb(133, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .donnee .donner, .list .donnee .erreur{
|
.list .give .donner, .list .give .error{
|
||||||
display : none;
|
display : none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list .donnee .annuler{
|
.list .give .cancel{
|
||||||
display : block;
|
display : block;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
@ -822,10 +821,10 @@ div#teams{
|
||||||
}
|
}
|
||||||
|
|
||||||
#okteam{
|
#okteam{
|
||||||
background: -webkit-linear-gradient(45deg, rgba(213,0,125), rgba(229,57,53));
|
background: -webkit-linear-gradient(45deg, rgb(213,0,125), rgb(229,57,53));
|
||||||
background: -o-linear-gradient(45deg, rgba(213,0,125), rgba(229,57,53));
|
background: -o-linear-gradient(45deg, rgb(213,0,125), rgb(229,57,53));
|
||||||
background: -moz-linear-gradient(45deg, rgba(213,0,125), rgba(229,57,53));
|
background: -moz-linear-gradient(45deg, rgb(213,0,125), rgb(229,57,53));
|
||||||
background: linear-gradient(45deg, rgba(213,0,125), rgba(229,57,53));
|
background: linear-gradient(45deg, rgb(213,0,125), rgb(229,57,53));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = (socket) => {
|
|
||||||
console.log("New connection !");
|
|
||||||
}
|
|
51
sockets/addCommand.js
Normal file
51
sockets/addCommand.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async (data) => {
|
||||||
|
try {
|
||||||
|
let o = await models.Command.findOne({
|
||||||
|
where: {date: {[models.Sequelize.Op.eq]: new Date()}},
|
||||||
|
order: [["number", "DESC"]]
|
||||||
|
});
|
||||||
|
let c = await models.Command.create({
|
||||||
|
number: o ? o.number + 1 : 1,
|
||||||
|
price: data.price
|
||||||
|
});
|
||||||
|
if (data.client)
|
||||||
|
await c.setClient(await models.User.findByPk(data.client));
|
||||||
|
if (data.pc)
|
||||||
|
await c.setPc(await models.User.findByPk(data.pc));
|
||||||
|
if (data.dish)
|
||||||
|
await c.setDish(await models.Dish.findByPk(data.dish));
|
||||||
|
if (data.ingredient)
|
||||||
|
for (let i in data.ingredient)
|
||||||
|
await c.addIngredient(await models.Ingredient.findByPk(i));
|
||||||
|
if (data.sauce)
|
||||||
|
for (let s in data.sauce)
|
||||||
|
await c.addSauce(await models.Sauce.findByPk(s));
|
||||||
|
if (data.drink)
|
||||||
|
await c.addDrink(await models.Drink.findByPk(data.drink));
|
||||||
|
if (data.dessert)
|
||||||
|
await c.setDessert(await models.Drink.findByPk(data.dessert));
|
||||||
|
let send = {
|
||||||
|
number: c.number,
|
||||||
|
sandwich: c.sandwich ? c.sandwich.username : null,
|
||||||
|
client: c.client ? c.client.firstName + " " + c.client.lastName : null,
|
||||||
|
dish: c.Dish ? c.Dish.name : null,
|
||||||
|
ingredients: c.Ingredients ? c.Ingredients.map(i => i.name) : null,
|
||||||
|
sauces: c.Sauces ? c.Sauces.map(s => s.name) : null,
|
||||||
|
drink: c.Drink ? c.Drink.name : null,
|
||||||
|
dessert: c.Dessert ? c.Dessert.name : null,
|
||||||
|
error: c.error,
|
||||||
|
give: c.give,
|
||||||
|
done: c.done,
|
||||||
|
WIP: c.WIP
|
||||||
|
}
|
||||||
|
socket.emit("new command", send);
|
||||||
|
socket.broadcast.emit("new command", send);
|
||||||
|
} catch (e) {
|
||||||
|
socket.emit("error");
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
sockets/index.js
Normal file
20
sockets/index.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
const listCommand = require("./listCommand")
|
||||||
|
const listDish = require("./listDish")
|
||||||
|
const listIngredient = require("./listIngredient")
|
||||||
|
const listSauce = require("./listSauce")
|
||||||
|
const listDrink = require("./listDrink")
|
||||||
|
const listDessert = require("./listDessert")
|
||||||
|
const addCommand = require("./addCommand")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
socket.on("list command", listCommand(socket));
|
||||||
|
socket.on("list dish", listDish(socket));
|
||||||
|
socket.on("list ingredient", listIngredient(socket));
|
||||||
|
socket.on("list sauce", listSauce(socket));
|
||||||
|
socket.on("list drink", listDrink(socket));
|
||||||
|
socket.on("list dessert", listDessert(socket));
|
||||||
|
socket.on("list dessert", listDessert(socket));
|
||||||
|
socket.on("add command", addCommand(socket));
|
||||||
|
console.log("New connection !");
|
||||||
|
socket.emit("connected");
|
||||||
|
}
|
32
sockets/listCommand.js
Normal file
32
sockets/listCommand.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let commands = []
|
||||||
|
for (let c of await models.Command.findAll({
|
||||||
|
where: {
|
||||||
|
date: {
|
||||||
|
[models.Sequelize.Op.eq]: new Date()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
order: ["number"],
|
||||||
|
include: [models.Dish, models.Ingredient, models.Sauce, models.Drink, models.Dessert, "client", "pc", "sandwich"]
|
||||||
|
})) {
|
||||||
|
commands.push({
|
||||||
|
number: c.number,
|
||||||
|
sandwich: c.sandwich ? c.sandwich.username : null,
|
||||||
|
client: c.client ? c.client.firstName + " " + c.client.lastName : null,
|
||||||
|
dish: c.Dish ? c.Dish.name : null,
|
||||||
|
ingredients: c.Ingredients ? c.Ingredients.map(i => i.name) : null,
|
||||||
|
sauces: c.Sauces ? c.Sauces.map(s => s.name) : null,
|
||||||
|
drink: c.Drink ? c.Drink.name : null,
|
||||||
|
dessert: c.Dessert ? c.Dessert.name : null,
|
||||||
|
error: c.error,
|
||||||
|
give: c.give,
|
||||||
|
done: c.done,
|
||||||
|
WIP: c.WIP
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list command", commands);
|
||||||
|
}
|
||||||
|
}
|
15
sockets/listDessert.js
Normal file
15
sockets/listDessert.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let desserts = []
|
||||||
|
for (let i of await models.Dessert.findAll()) {
|
||||||
|
desserts.push({
|
||||||
|
id: i.id,
|
||||||
|
name: i.name,
|
||||||
|
price: i.price
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list dessert", desserts);
|
||||||
|
}
|
||||||
|
}
|
17
sockets/listDish.js
Normal file
17
sockets/listDish.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let dishes = []
|
||||||
|
for (let d of await models.Dish.findAll()) {
|
||||||
|
dishes.push({
|
||||||
|
id: d.id,
|
||||||
|
name: d.name,
|
||||||
|
price: d.price,
|
||||||
|
avoidIngredients: d.avoidIngredients,
|
||||||
|
avoidSauces: d.avoidSauces
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list dish", dishes);
|
||||||
|
}
|
||||||
|
}
|
15
sockets/listDrink.js
Normal file
15
sockets/listDrink.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let drinks = []
|
||||||
|
for (let i of await models.Drink.findAll()) {
|
||||||
|
drinks.push({
|
||||||
|
id: i.id,
|
||||||
|
name: i.name,
|
||||||
|
price: i.price
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list drink", drinks);
|
||||||
|
}
|
||||||
|
}
|
15
sockets/listIngredient.js
Normal file
15
sockets/listIngredient.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let ingredients = []
|
||||||
|
for (let i of await models.Ingredient.findAll()) {
|
||||||
|
ingredients.push({
|
||||||
|
id: i.id,
|
||||||
|
name: i.name,
|
||||||
|
price: i.price
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list ingredient", ingredients);
|
||||||
|
}
|
||||||
|
}
|
15
sockets/listSauce.js
Normal file
15
sockets/listSauce.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
const models = require("../models")
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return async () => {
|
||||||
|
let sauces = []
|
||||||
|
for (let d of await models.Sauce.findAll()) {
|
||||||
|
sauces.push({
|
||||||
|
id: d.id,
|
||||||
|
name: d.name,
|
||||||
|
price: d.price
|
||||||
|
});
|
||||||
|
}
|
||||||
|
socket.emit("list sauce", sauces);
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,11 +44,11 @@ block content
|
||||||
ul
|
ul
|
||||||
div#resume
|
div#resume
|
||||||
h1 Command 1
|
h1 Command 1
|
||||||
p
|
p#p-dish
|
||||||
p
|
p#p-ingredient
|
||||||
p
|
p#p-sauce
|
||||||
p
|
p#p-drink
|
||||||
p
|
p#p-dessert
|
||||||
input#user(list="user_list" type="text" placeholder="Username")
|
input#user(list="user_list" type="text" placeholder="Username")
|
||||||
datalist#user_list
|
datalist#user_list
|
||||||
button.validation(type="submit") Confirm
|
button.validation(type="submit") Confirm
|
||||||
|
|
Reference in a new issue