Просмотр исходного кода

Update the data structure for recipe ingredients.
Calculate the multiplier for recipe ingredients.

Lee Morgan 5 лет назад
Родитель
Сommit
ea442cb042
2 измененных файлов с 16 добавлено и 4 удалено
  1. 10 0
      views/dashboardPage/js/classes/Ingredient.js
  2. 6 4
      views/dashboardPage/js/modal.js

+ 10 - 0
views/dashboardPage/js/classes/Ingredient.js

@@ -147,6 +147,16 @@ class Ingredient{
 
         return (quantity === 0) ? 0 : totalCost / quantity;
     }
+
+    /*
+    Used when the unit on an ingredient does not match the RecipeIngredient unit
+    Calculates the multiplier from RecipeIngredient quantity, to ingredient base unit (unit type)
+    */
+    calculateRecipeMultiplier(recipeQuantity, ingredientQuantity){
+        let unitToBase = controller.baseUnit(ingredientQuantity, this._unit);
+
+        return unitToBase / recipeQuantity;
+    }
 }
 
 module.exports = Ingredient;

+ 6 - 4
views/dashboardPage/js/modal.js

@@ -1,5 +1,7 @@
 const Merchant = require("./classes/Merchant.js");
 
+const newRecipe = require("./sidebars/newRecipe.js");
+
 let modal = {
     feedback: function(){
         let form = document.getElementById("modalFeedback");
@@ -314,11 +316,11 @@ let modal = {
                     return;
                 }
 
-                console.log(data.mismatchUnits[i].ingredient.unit);
-                let base = controller.baseUnit(inputRight, data.mismatchUnits[i].ingredient.unit);
-                console.log(base);
-                console.log(inputLeft / base);
+                data.mismatchUnits[i].newIngredient.baseUnitMultiplier = data.mismatchUnits[i].ingredient.calculateRecipeMultiplier(inputLeft, inputRight);
             }
+
+            controller.closeModal();
+            newRecipe.submit(data.recipe);
         }
     }
 };