From e7be9989132a4e5ab7bf16dce8e69c8419428df0 Mon Sep 17 00:00:00 2001 From: William Nolin Date: Fri, 16 Aug 2019 18:33:10 -0400 Subject: [PATCH] =?UTF-8?q?Finalisation=20des=20unit=C3=A9es=20de=20volume?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- recipes.mv.db | Bin 24576 -> 28672 bytes src/main/resources/static/js/main.js | 35 +++--- .../resources/templates/recipe/explore.html | 109 ++++++++++-------- workdir/recipes.mv.db | Bin 32768 -> 36864 bytes 4 files changed, 81 insertions(+), 63 deletions(-) diff --git a/recipes.mv.db b/recipes.mv.db index 6895fe6ff88eee09fc03f9130d82967115ae2f7f..98b5a167e630b2773ecaf62f8ded05c7ea80da73 100644 GIT binary patch delta 1489 zcmb`G&1=(O9LJw*eX|r)oak1Htt*pBT9Z6&k_J0e6g}8=o#4TXq}^B8J_wV zi0k7`(4*%P|A1aSDLYJ14;~6mka-Y~;*#`9vvnzoddZW+lV6_i_w#u=eX8?`n!hD+ zv{I?78&Y<--YGvq63Z|Qt*$?;ZAeOPYkpxy$S)Kb?`Lt<4fi#RphlV2R)(tX_% z;n~0bHXfK#1l%sAmLOe~Hzmks8CsVgpr*vrje5N$ahhr#h7nYjfpn`}H4g_N%R`2T zbQ?9A<$6srN67Ju$uIyQ1~StW1wg6~K>DM-PNU~%qyAX{A|E2}jDGxmgen@(Qq_|} z7m%&N*LUr$q3!Ltn7=CPX#{|8A^Hl;fsoxpT7k|BkKeB3@k}We3|Kokh}qKRGdigY zk~%rMf@%`PPYTf$ZelofLbzmL!ngIHxz!>W$$9 z@o;ZhUf4#apmDn?OuKlD=b1*{sx8|5uSkImu3wPsz z3yLs`>Vj}JQCQhDMU!!_xQz9<5C19#@0lJswpsPCCUjjIPr{ESK^gBPyzC~)nZL>B zEdvrDU}H^R0pQY(2iEhxULgH`mxdaOyhw-X`+HOMs!$F;eD=I&(i<^ delta 1651 zcmbtUId2m|6rRP-W!abn5I70Jv4cs(CfWM}6bFMK61gzqlrZb@1fnE1%Ei%;25Qhy zp&&#<#UW&V0F-nzP=JsqK!O4!8blMp?06eDe7FK;mG9h$?d;Xblksu0sSuL-&c~@!4Zv@Q3V9!NQLR@8Xs0r+NT3w8Tfs zC^fvrMzqygb7+y#!9*;cSfIIC}D4WZSj-Ae_IR&>Te?~}z=|$|0cSg?QeY<<` zfv(onYD}U#F+6zu(6OPxqeBN1JsxJG7v4=E?-9uDIBhpn=X|iYZ8QJjL*?+}uEVtA z1g$thzQ3jwZ&Xw3#%pRCA22$aRx82hjcp@j@|}C`(a|QBK>S6zg}YV*K72wh|`mcXqbpuqPHVa253^iz?7rmT)GpntOiM1vpO=*O%+E} zq1Wb~5EqIIbErU93Cenv0?h>mWif8Lhcvtv$zUuvlH!q&{z9@9pM}LU+xTRv { - e.innerText = unitSelect.value; + e.innerText = newUnit; // Modifie la quantitée const quantityElem = e.parentElement.parentElement.querySelector(quantitiesSelector); const originalQuantity = parseInt(quantityElem.dataset.quantityml); - switch (unitSelect.value) { - case "L": - quantityElem.innerText = originalQuantity / lTomL; - break; - case "gal": - quantityElem.innerText = originalQuantity / galTomL; - break; - default: - quantityElem.innerText = originalQuantity; - break; - } - - // Arrondi à deux décimaux - quantityElem.innerText = Math.round(quantityElem.innerText * 100) / 100; + quantityElem.innerText = convertMlToUnit(newUnit, originalQuantity); }); +} + +// Convertit une quantité en millilitres vers une autre unité de volume +function convertMlToUnit(unit, quantity) { + let newQuantity = unit === "L" ? quantity / lTomL : unit === "gal" ? quantity / galTomL : quantity; + return round(newQuantity); +} + +// Convertit une quantité d'une autre unité vers des millilitres +function convertUnitToMl(unit, quantity) { + let newQuantity = unit === "L" ? quantity * lTomL : unit === "gal" ? quantity * galTomL : quantity; + return round(newQuantity); +} + +function round(x) { + return Math.round(x * 100) / 100; } \ No newline at end of file diff --git a/src/main/resources/templates/recipe/explore.html b/src/main/resources/templates/recipe/explore.html index ef4895d..c10aa02 100644 --- a/src/main/resources/templates/recipe/explore.html +++ b/src/main/resources/templates/recipe/explore.html @@ -55,7 +55,8 @@
- @@ -151,10 +152,9 @@ Produit Type Quantité - - + Unités

- -

mL

- + +

mL

+
@@ -237,36 +238,40 @@ }); document.querySelectorAll(".quantityCustomizer").forEach((e) => { - // Modifie les quantités de tous les produits e.addEventListener("change", () => { const value = e.valueAsNumber; const oldValue = e.defaultValue; + const currentUnit = document.querySelector("#unitsSelect").value; - const mixID = e.dataset.mixid; + // Modifie les quantités de tous les produits + // Les 3 parentElement récupèrent la table dans laquelle le produit se trouve + // TODO simplifier ? + e.parentElement.parentElement.parentElement.querySelectorAll(".quantityCustomizer").forEach((elem) => { + const defaultValue = elem.defaultValue; + const newValue = (defaultValue * value) / oldValue; - document.querySelectorAll(".quantityCustomizer").forEach((elem) => { - if (elem.dataset.mixid === mixID) { - const defaultValue = elem.defaultValue; - const newValue = (defaultValue * value) / oldValue; + elem.value = round(newValue); - elem.value = Math.round(newValue * 100) / 100; - } + // Recalcule la quantité en millilitres de chaque produit + elem.dataset.quantityml = convertUnitToMl(currentUnit, newValue); }); }); }); - const mixes = document.querySelectorAll(".mixes"); - let maxWidth = 0; - mixes.forEach((e) => { - const width = e.style.width; - - if (width > maxWidth) { - maxWidth = width; - } - }); - mixes.forEach((e) => { - e.style.width = maxWidth; - }); + // Fait que toutes les tables de mélange soit de la même largeur + // TODO Voir si nécessaire, semble être fait par défault + // const mixes = document.querySelectorAll(".mixes"); + // let maxWidth = 0; + // mixes.forEach((e) => { + // const width = e.style.width; + // + // if (width > maxWidth) { + // maxWidth = width; + // } + // }); + // mixes.forEach((e) => { + // e.style.width = maxWidth; + // }); document.querySelector("#formSubmit").addEventListener("click", () => { let formData = {}; @@ -296,20 +301,12 @@ formData[mixID] = {}; } - formData[mixID][materialID] = e.value; + formData[mixID][materialID] = e.dataset.quantityml; }); - document.querySelectorAll(".notEnough").forEach(e => { - e.classList.remove("notEnough"); - }); + clearNotEnoughClasses(); - sendPost(formData, "/inventory/use", r => { - const splitReason = r.split("-"); - const mixID = splitReason[0]; - const materialID = splitReason[1]; - - document.querySelector(`#recipe-${mixID}`).querySelector(`#material-${materialID}`).classList.add("notEnough"); - }); + sendPost(formData, "/inventory/use", r => displayNotEnoughReason(r)); }); document.querySelectorAll(".useMixSubmit").forEach(e => { @@ -324,24 +321,40 @@ formData[mixID] = {}; } - formData[mixID][materialID] = elem.value; + formData[mixID][materialID] = elem.dataset.quantityml; }); - document.querySelectorAll(".notEnough").forEach(elem => { - elem.classList.remove("notEnough"); - }); + clearNotEnoughClasses(); - sendPost(formData, "/inventory/use", r => { - const splitReason = r.split("-"); - const mixID = splitReason[0]; - const materialID = splitReason[1]; - - document.querySelector(`#recipe-${mixID}`).querySelector(`#material-${materialID}`).classList.add("notEnough"); - }); + sendPost(formData, "/inventory/use", r => displayNotEnoughReason(r)); }); }); })(); + function changeCustomizersUnits(unitSelect) { + const unit = unitSelect.value; + + document.querySelectorAll(".quantityCustomizer").forEach(e => { + const originalValue = e.dataset.quantityml; + + e.value = convertMlToUnit(unit, originalValue); + }); + } + + function clearNotEnoughClasses() { + document.querySelectorAll(".notEnough").forEach(elem => { + elem.classList.remove("notEnough"); + }); + } + + function displayNotEnoughReason(reason) { + const splitReason = reason.split("-"); + const mixID = splitReason[0]; + const materialID = splitReason[1]; + + document.querySelector(`#recipe-${mixID}`).querySelector(`#material-${materialID}`).classList.add("notEnough"); + } + function sendPost(data, url, errorCallback) { const successP = document.querySelector(".success"); const errorP = document.querySelector(".error"); diff --git a/workdir/recipes.mv.db b/workdir/recipes.mv.db index 7346774d0c45e927860f6821c728784e8eae8745..13c74c161cec6bcc98e7031a44fbcf28a77b2293 100644 GIT binary patch delta 4153 zcmc(iUu+ab9LM+e*q&BuDFWr_U0aAP*j&r*-gIwgOM8{V^$^MxG=*5A?w?sWDRVuN-KuWz=BdAfI41#EkiN*)t@I`%=IJ3KVvs)-_w4s;W&i!tF zJF_?Q{rtXjAG>ny0mt+di9r4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