Переглянути джерело

Update handling of state for updating a recipe.

Lee Morgan 5 роки тому
батько
коміт
e76108500d

+ 2 - 38
views/dashboardPage/bundle.js

@@ -379,43 +379,6 @@ class Merchant{
         recipeBookStrand.populateRecipes();
     }
 
-    /*
-    recipe = {
-        name: required,
-        price: required,
-        ingredients: [{
-            ingredient: id of ingredient,
-            quantity: quantity of ingredient
-        }]
-    }
-    */
-    updateRecipe(recipe){
-        for(let i = 0; i < this._recipes.length; i++){
-            if(this._recipes[i].id === recipe._id){
-                this._recipes[i].name = recipe.name;
-                this._recipes[i].price = recipe.price;
-                
-                this._recipes[i].removeIngredients();
-                for(let j = 0; j < recipe.ingredients.length; j++){
-                    for(let k = 0; k < this._ingredients.length; k++){
-                        if(this._ingredients[k].ingredient.id === recipe.ingredients[j].ingredient){
-                            this._recipes[i].addIngredient(
-                                this._ingredients[k].ingredient,
-                                recipe.ingredients[j].quantity
-                            );
-
-                            break;
-                        }
-                    }
-                }
-
-                break;
-            }
-        }
-
-        recipeBookStrand.isPopulated = false;
-    }
-
     get transactions(){
         return this._transactions;
     }
@@ -1728,7 +1691,8 @@ let editRecipe = {
                 if(typeof(response) === "string"){
                     controller.createBanner(response, "error");
                 }else{
-                    merchant.updateRecipe(response);
+                    merchant.removeRecipe(recipe)
+                    merchant.addRecipes([response]);
                     controller.openStrand("recipeBook");
                     controller.createBanner("RECIPE UPDATED", "success");
                 }

+ 0 - 37
views/dashboardPage/js/classes/Merchant.js

@@ -263,43 +263,6 @@ class Merchant{
         recipeBookStrand.populateRecipes();
     }
 
-    /*
-    recipe = {
-        name: required,
-        price: required,
-        ingredients: [{
-            ingredient: id of ingredient,
-            quantity: quantity of ingredient
-        }]
-    }
-    */
-    updateRecipe(recipe){
-        for(let i = 0; i < this._recipes.length; i++){
-            if(this._recipes[i].id === recipe._id){
-                this._recipes[i].name = recipe.name;
-                this._recipes[i].price = recipe.price;
-                
-                this._recipes[i].removeIngredients();
-                for(let j = 0; j < recipe.ingredients.length; j++){
-                    for(let k = 0; k < this._ingredients.length; k++){
-                        if(this._ingredients[k].ingredient.id === recipe.ingredients[j].ingredient){
-                            this._recipes[i].addIngredient(
-                                this._ingredients[k].ingredient,
-                                recipe.ingredients[j].quantity
-                            );
-
-                            break;
-                        }
-                    }
-                }
-
-                break;
-            }
-        }
-
-        recipeBookStrand.isPopulated = false;
-    }
-
     get transactions(){
         return this._transactions;
     }

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

@@ -113,7 +113,8 @@ let editRecipe = {
                 if(typeof(response) === "string"){
                     controller.createBanner(response, "error");
                 }else{
-                    merchant.updateRecipe(response);
+                    merchant.removeRecipe(recipe)
+                    merchant.addRecipes([response]);
                     controller.openStrand("recipeBook");
                     controller.createBanner("RECIPE UPDATED", "success");
                 }