Преглед изворни кода

Update Ingredient class data inputs.
Remove a bunch of functions that will no longer be used from the ingredient class.

Lee Morgan пре 5 година
родитељ
комит
ec410f9be5

+ 2 - 84
views/dashboardPage/js/classes/Ingredient.js

@@ -1,9 +1,8 @@
 class SubIngredient{
-    constructor(id, ingredient, quantity, unit, parent){
+    constructor(id, ingredient, quantity, parent){
         this.id = id;
         this._ingredient = ingredient;
         this.quantity = quantity;
-        this.unit = unit;
         this.parent = parent;
     }
 
@@ -18,15 +17,13 @@ class SubIngredient{
 }
 
 class Ingredient{
-    constructor(id, name, category, unitType, unit, subIngredients, convert, parent, unitSize = undefined){
+    constructor(id, name, category, unit, subIngredients, convert, parent){
         this._id = id;
         this._name = name;
         this._category = category;
-        this._unitType = unitType;
         this._unit = unit;
         this._subIngredients = [];
         this._parent = parent;
-        this._unitSize = unitSize;
         this._convert = convert;
 
         for(let i = 0; i < subIngredients.length; i++){
@@ -34,7 +31,6 @@ class Ingredient{
                 subIngredients[i]._id,
                 subIngredients[i].ingredient,
                 subIngredients[i].quantity,
-                subIngredients[i].unit,
                 this
             ));
         }
@@ -64,14 +60,6 @@ class Ingredient{
         this._category = category;
     }
 
-    get unitType(){
-        return this._unitType;
-    }
-
-    set unitType(unitType){
-        this._unitType = unitType;
-    }
-
     get unit(){
         return this._unit;
     }
@@ -80,46 +68,10 @@ class Ingredient{
         this._unit = unit;
     }
 
-    get specialUnit(){
-        return this._specialUnit;
-    }
-
     get convert(){
         return this._convert;
     }
 
-    get unitSize(){
-        switch(this._unit){
-            case "g":return this._unitSize; 
-            case "kg": return this._unitSize / 1000;
-            case "oz": return this._unitSize / 28.3495;
-            case "lb": return this._unitSize / 453.5924;
-            case "ml": return this._unitSize * 1000;
-            case "l": return this._unitSize;
-            case "tsp": return this._unitSize * 202.8842;
-            case "tbsp": return this._unitSize * 67.6278;
-            case "ozfl": return this._unitSize * 33.8141;
-            case "cup": return this._unitSize * 4.1667;
-            case "pt": return this._unitSize * 2.1134;
-            case "qt": return this._unitSize * 1.0567;
-            case "gal": return this._unitSize / 3.7854;
-            case "mm": return this._unitSize * 1000;
-            case "cm": return this._unitSize * 100;
-            case "m": return this._unitSize;
-            case "in": return this._unitSize * 39.3701;
-            case "ft": return this._unitSize * 3.2808;
-            default: return this._unitSize;
-        }
-    }
-
-    set unitSize(unitSize){
-        if(unitSize < 0){
-            return false;
-        }
-
-        this._unitSize = unitSize;
-    }
-
     get subIngredients(){
         return this._subIngredients;
     }
@@ -139,30 +91,6 @@ class Ingredient{
         this.addIngredients(ingredients);
     }
 
-    getBaseUnitSize(){
-        return this._unitSize;
-    }
-
-    getNameAndUnit(){
-        return `${this._name} (${this._unit.toUpperCase()})`;
-    }
-
-    /*
-    Show matching unit types for this ingredient
-    return = [String]
-    */
-    getPotentialUnits(){
-        let mass = ["g", "kg", "oz", "lb"];
-        let volume = ["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"];
-        let length = ["mm", "cm", "m", "in", "ft"];
-
-        if(mass.includes(this._unit)) return mass;
-        if(volume.includes(this._unit)) return volume;
-        if(length.includes(this._unit)) return length;
-        if(this._unit === "bottle") return volume;
-        return [];
-    }
-
     getUnitCost(){
         let totalCost = 0;
         let quantity = 0;
@@ -181,16 +109,6 @@ 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;

+ 5 - 9
views/dashboardPage/js/classes/Merchant.js

@@ -101,12 +101,10 @@ class Merchant{
                 ingredients[i].ingredient._id,
                 ingredients[i].ingredient.name,
                 ingredients[i].ingredient.category,
-                ingredients[i].ingredient.unitType,
-                ingredients[i].defaultUnit,
+                ingredients[i].unit,
                 ingredients[i].ingredient.ingredients,
                 ingredients[i].ingredient.convert,
-                this,
-                ingredients[i].ingredient.unitSize,
+                this
             );
 
             const merchantIngredient = new MerchantIngredient(
@@ -245,18 +243,16 @@ class Merchant{
         for(let i = 0; i < ingredients.length; i++){
             let ingredient = ingredients[i].ingredient;
             let quantity = ingredients[i].quantity;
-            let defaultUnit = ingredients[i].defaultUnit;
+            let unit = ingredients[i].unit;
 
             const createdIngredient = new Ingredient(
                 ingredient._id,
                 ingredient.name,
                 ingredient.category,
-                ingredient.unitType,
-                defaultUnit,
+                unit,
                 ingredient.ingredients,
                 ingredient.convert,
-                this,
-                ingredient.unitSize
+                this
             );
 
             const merchantIngredient = new MerchantIngredient(createdIngredient, quantity, this);