Selaa lähdekoodia

Update ingredients page to working

Lee Morgan 6 vuotta sitten
vanhempi
sitoutus
1bcbf8a3c9

+ 46 - 0
views/dashboardPage/Merchant.js

@@ -350,6 +350,52 @@ class Merchant{
 
         return dataList;
     }
+    /*
+    Groups all of the merchant's ingredients by their category
+    Return: [{
+        name: category name,
+        ingredients: [{
+            id: id of ingredient,
+            name: name of ingredient,
+            quantity: merchant's quantity of this ingredient,
+            unit: measurement unit
+        }]
+    }]
+    */
+    categorizeIngredients(){
+        let ingredientsByCategory = [];
+
+        for(let i = 0; i < this.ingredients.length; i++){
+            let categoryExists = false;
+            for(let j = 0; j < ingredientsByCategory.length; j++){
+                if(this.ingredients[i].ingredient.category === ingredientsByCategory[j].name){
+                    ingredientsByCategory[j].ingredients.push({
+                        id: this.ingredients[i].ingredient._id,
+                        name: this.ingredients[i].ingredient.name,
+                        quantity: this.ingredients[i].quantity,
+                        unit: this.ingredients[i].ingredient.unit
+                    });
+
+                    categoryExists = true;
+                    break;
+                }
+            }
+
+            if(!categoryExists){
+                ingredientsByCategory.push({
+                    name: this.ingredients[i].ingredient.category,
+                    ingredients: [{
+                        id: this.ingredients[i].ingredient._id,
+                        name: this.ingredients[i].ingredient.name,
+                        quantity: this.ingredients[i].quantity,
+                        unit: this.ingredients[i].ingredient.unit
+                    }]
+                });
+            }
+        }
+
+        return ingredientsByCategory;
+    }
 }
 
 class Order{

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

@@ -557,7 +557,7 @@ let ingredientDetailsComp = {
         for(let i = 1; i < 31; i++){
             let endDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i)
             let startDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i - 1);
-            quantities.push(ingredientSold(dateIndices(startDay, endDay), ingredient.id));
+            quantities.push(merchant.ingredientsSold(merchant.transactionIndices(startDay, endDay), ingredient.id));
         }
 
         let sum = 0;

+ 0 - 46
views/dashboardPage/controller.js

@@ -218,52 +218,6 @@ let ingredientSold = (dateRange,  id)=>{
     return total;
 }
 
-/*
-Groups all of the merchant's ingredients by their category
-Return:
-    Array of objects
-        name: Category name
-        ingredients: Array of objects
-            id: Id of ingredient
-            name: Name of ingredient
-            quantity:  Merchant's quantity of this ingredient
-            unit: Measurement unit
-*/
-let categorizeIngredients = (ingredients)=>{
-    let ingredientsByCategory = [];
-
-    for(let i = 0; i < ingredients.length; i++){
-        let categoryExists = false;
-        for(let j = 0; j < ingredientsByCategory.length; j++){
-            if(ingredients[i].ingredient.category === ingredientsByCategory[j].name){
-                ingredientsByCategory[j].ingredients.push({
-                    id: ingredients[i].ingredient._id,
-                    name: ingredients[i].ingredient.name,
-                    quantity: ingredients[i].quantity,
-                    unit: ingredients[i].ingredient.unit
-                });
-
-                categoryExists = true;
-                break;
-            }
-        }
-
-        if(!categoryExists){
-            ingredientsByCategory.push({
-                name: ingredients[i].ingredient.category,
-                ingredients: [{
-                    id: ingredients[i].ingredient._id,
-                    name: ingredients[i].ingredient.name,
-                    quantity: ingredients[i].quantity,
-                    unit: ingredients[i].ingredient.unit
-                }]
-            });
-        }
-    }
-
-    return ingredientsByCategory;
-}
-
 let unitizeIngredients = (ingredients)=>{
     let ingredientsByUnit = [];
 

+ 1 - 1
views/dashboardPage/ingredients.js

@@ -13,7 +13,7 @@ window.ingredientsStrandObj = {
     populateByProperty: function(property){
         let categories;
         if(property === "category"){
-            categories = categorizeIngredients(merchant.inventory);
+            categories = merchant.categorizeIngredients();
         }else if(property === "unit"){
             categories = unitizeIngredients(merchant.inventory);
         }