ソースを参照

Adding ingredients to recipes now displays the correct units to choose from.

Lee Morgan 5 年 前
コミット
c9ef50c640

+ 4 - 4
views/dashboardPage/ejs/sidebars/editRecipe.ejs

@@ -53,14 +53,14 @@
                 <input type="number" step="0.01" min="0" placeholder="QUANTITY">
 
                 <select>
-                    <optgroup label="MASS/WEIGHT">
+                    <optgroup label="MASS/WEIGHT" style="display:none">
                         <option type="mass" value="g">G</option>
                         <option type="mass" value="kg">KG</option>
                         <option type="mass" value="oz">OZ</option>
                         <option type="mass" value="lb">LB</option>
                     </optgroup>
         
-                    <optgroup label="VOLUME">
+                    <optgroup label="VOLUME" style="display:none">
                         <option type="volume" value="ml">ML</option>
                         <option type="volume" value="l">L</option>
                         <option type="volume" value="tsp">TSP</option>
@@ -72,7 +72,7 @@
                         <option type="volume" value="gal">GAL</option>
                     </optgroup>
         
-                    <optgroup label="LENGTH">
+                    <optgroup label="LENGTH" style="display:none">
                         <option type="length" value="mm">MM</option>
                         <option type="length" value="cm">CM</option>
                         <option type="length" value="m">M</option>
@@ -80,7 +80,7 @@
                         <option type="length" value="ft">FT</option>
                     </optgroup>
         
-                    <optgroup label="OTHER">
+                    <optgroup label="OTHER" style="display:none">
                         <option type="other" value="each">EACH</option>
                     </optgroup>
                 </select>

+ 15 - 1
views/dashboardPage/js/sidebars/editRecipe.js

@@ -85,6 +85,21 @@ module.exports = {
         newItem.ingredient = ingredient.ingredient;
         newItem.children[0].children[0].innerText = ingredient.ingredient.name;
         newItem.children[0].children[1].onclick = ()=>{this.removeIngredient(newItem)};
+
+        let select = newItem.children[1].children[1];
+        if(ingredient.ingredient.convert.toMass !== undefined) select.children[0].style.display = "block";
+        if(ingredient.ingredient.convert.toVolume !== undefined) select.children[1].style.display = "block";
+        if(ingredient.ingredient.convert.toLength !== undefined) select.children[2].style.display = "block";
+
+        switch(ingredient.ingredient.unitType){
+            case "mass": select.value = "g"; break;
+            case "volume": select.value = "ml"; break;
+            case "length": select.value = "mm"; break;
+            case "other":
+                select.value = "other";
+                select.children[3].style.display = "block";
+        }
+
         used.appendChild(newItem);
     },
 
@@ -129,7 +144,6 @@ module.exports = {
             });
         }
 
-
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";