浏览代码

Update sub-ingredient add modal to display the correct unit for chioces.

Lee Morgan 5 年之前
父节点
当前提交
a9144d3d95

+ 11 - 10
views/dashboardPage/js/classes/Recipe.js

@@ -156,16 +156,17 @@ class Recipe{
         this._ingredientTotals = {};
         
         let traverseIngredient = (recipeIngredient, multiplier)=>{
-            let ingredient = recipeIngredient._ingredient;
-            for(let i = 0; i < ingredient.subIngredients.length; i++){
-                traverseIngredient(ingredient.subIngredients[i].ingredient, multiplier * ingredient.subIngredients[i].quantity);
-            }
-
-            if(this._ingredientTotals[ingredient.id] === undefined){
-                this._ingredientTotals[ingredient.id] = multiplier * recipeIngredient.baseUnitMultiplier;
-            }else{
-                this._ingredientTotals[ingredient.id] += multiplier * recipeIngredient.baseUnitMultiplier;
-            }
+            // console.log(recipeIngredient._ingredient);
+            // let ingredient = recipeIngredient._ingredient;
+            // for(let i = 0; i < ingredient.subIngredients.length; i++){
+            //     traverseIngredient(ingredient.subIngredients[i].ingredient, multiplier * ingredient.subIngredients[i].quantity);
+            // }
+
+            // if(this._ingredientTotals[ingredient.id] === undefined){
+            //     this._ingredientTotals[ingredient.id] = multiplier * recipeIngredient.baseUnitMultiplier;
+            // }else{
+            //     this._ingredientTotals[ingredient.id] += multiplier * recipeIngredient.baseUnitMultiplier;
+            // }
         }
 
         for(let i = 0; i < this._ingredients.length; i++){

+ 1 - 1
views/dashboardPage/js/dashboard.js

@@ -427,7 +427,7 @@ controller = {
 
     unitType(unit){
         if(["g", "kg", "oz", "lb"].includes(unit)) return "mass";
-        if(["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"].includes(unit)) return volume;
+        if(["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"].includes(unit)) return "volume";
         if(["mm", "cm", "m", "in", "ft"].includes(unit)) return "length";
         return "other";
     }

+ 29 - 15
views/dashboardPage/js/modal.js

@@ -171,6 +171,19 @@ let modal = {
         while(right.children.length > 0){
             right.removeChild(right.firstChild);
         }
+        
+        let createOptGroup = (container, group, options)=>{
+            let optGroup = document.createElement("optgroup")
+            optGroup.label = group;
+            container.appendChild(optGroup);
+
+            for(let i = 0; i < options.length; i++){
+                let option = document.createElement("option");
+                option.innerText = options[i].toUpperCase();
+                option.value = options[i];
+                optGroup.appendChild(option);
+            }
+        }
 
         let addIngredient = (button, ingredient)=>{
             button.parentElement.removeChild(button);
@@ -182,19 +195,6 @@ let modal = {
             div.ingredient = ingredient;
             right.appendChild(div);
 
-            let createOptGroup = (container, group, options)=>{
-                let optGroup = document.createElement("optgroup")
-                optGroup.label = group;
-                container.appendChild(optGroup);
-
-                for(let i = 0; i < options.length; i++){
-                    let option = document.createElement("option");
-                    option.innerText = options[i].toUpperCase();
-                    option.value = options[i];
-                    optGroup.appendChild(option);
-                }
-            }
-
             if(ingredient.convert.toMass !== undefined){
                 createOptGroup(div.children[1].children[1], "Mass", ["g", "kg", "oz", "lb"])
             }
@@ -204,6 +204,7 @@ let modal = {
             if(ingredient.convert.toLength !== undefined){
                 createOptGroup(div.children[1].children[1], "Length", ["mm", "cm", "m", "in", "ft"]);
             }
+            div.children[1].children[1].value = ingredient.unit;
         }
 
         let removeIngredient = (div, ingredient)=>{
@@ -222,11 +223,24 @@ let modal = {
             for(let j = 0; j < ingredient.subIngredients.length; j++){
                 if(merchant.inventory[i].ingredient === ingredient.subIngredients[j].ingredient){
                     let div = template.cloneNode(true);
-                    div.children[0].innerText = merchant.inventory[i].ingredient.name;
+                    div.children[0].children[0].innerText = merchant.inventory[i].ingredient.name;
+                    div.children[0].children[1].onclick = ()=>{removeIngredient(div, ingredient.subIngredients[j].ingredient)};
                     div.children[1].children[0].value = ingredient.subIngredients[j].quantity;
-                    div.children[1].children[1].onclick = ()=>{removeIngredient(div, ingredient.subIngredients[j].ingredient)};
                     div.ingredient = merchant.inventory[i].ingredient;
                     right.appendChild(div);
+
+                    let conversions = merchant.inventory[i].ingredient.convert;
+                    if(conversions.toMass !== undefined){
+                        createOptGroup(div.children[1].children[1], "Mass", ["g", "kg", "oz", "lb"]);
+                    }
+                    if(conversions.toVolume !== undefined){
+                        createOptGroup(div.children[1].children[1], "Volume", ["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"]);
+                    }
+                    if(conversions.toLength !== undefined){
+                        createOptGroup(div.children[1].children[1], "Length", ["mm", "cm", "m", "in", "ft"]);
+                    }
+                    div.children[1].children[1].value = merchant.inventory[i].ingredient.unit;
+
                     skip = true;
                     break;
                 }

+ 1 - 1
views/dashboardPage/js/sidebars/newIngredient.js

@@ -32,7 +32,7 @@ let newIngredient = {
             convertLength.style.display = "flex";
             document.getElementById("volumeConvertUnitLeft").innerText = select.value.toUpperCase();
             document.getElementById("lengthConvertUnitLeft").innerText = select.value.toUpperCase();
-        }else if(controller.unittype(select.value) === "volume"){
+        }else if(controller.unitType(select.value) === "volume"){
             convertMass.style.display = "flex";
             convertVolume.style.display = "none";
             convertLength.style.display = "flex";

+ 0 - 2
views/dashboardPage/js/strands/analytics.js

@@ -190,8 +190,6 @@ let analytics = {
             quantities.push(sum);
         }
 
-        console.log(quantities);
-
         //create and display the graph
         let trace = {
             x: dates,