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

Update the functions for updating a change in the merchant data

Lee Morgan 6 лет назад
Родитель
Сommit
e41bfe7023
3 измененных файлов с 70 добавлено и 22 удалено
  1. 35 11
      views/dashboardPage/bundle.js
  2. 8 11
      views/dashboardPage/js/Merchant.js
  3. 27 0
      views/dashboardPage/js/dashboard.js

+ 35 - 11
views/dashboardPage/bundle.js

@@ -136,9 +136,8 @@ class Merchant{
             }
         }
     
-        ingredientsStrandObj.populateByProperty("category");
-        addIngredientsComp.isPopulated = false;
-        closeSidebar();
+        controller.updateData("ingredient");
+        controller.closeSidebar();
     }
 
     /*
@@ -169,9 +168,8 @@ class Merchant{
             }
         }
 
-        transactionsStrandObj.isPopulated = false;
-        recipeBookStrandObj.populateRecipes();
-        closeSidebar();
+        controller.updateData("recipe");
+        controller.closeSidebar();
     }
 
     /*
@@ -201,8 +199,8 @@ class Merchant{
             }
         }
 
-        ordersStrandObj.populate();
-        closeSidebar();
+        controller.updateData("order");
+        controller.closeSidebar();
     }
 
     editTransactions(transaction, remove = false){
@@ -223,9 +221,8 @@ class Merchant{
             this.transactions.sort((a, b) => a.date > b.date ? 1 : -1);
         }
 
-        transactionsStrandObj.isPopulated = false;
-        transactionsStrandObj.display();
-        closeSidebar();
+        controller.updateData("transaction");
+        controller.closeSidebar();
     }
 
     /*
@@ -771,6 +768,7 @@ const recipeDetails = require("./recipeDetails.js");
 const transactionDetails = require("./transactionDetails.js");
 
 const Merchant = require("./Merchant.js");
+const { transaction } = require("./transactionDetails.js");
 
 merchant = new Merchant(data.merchant, data.transactions);
 
@@ -943,6 +941,32 @@ controller = {
         }
     
         return converted;
+    },
+
+    /*
+    Sets certain strands to repopulate everything the next time it is opened
+    Use for when any data is changed
+    item = whatever is being updated
+    */
+    updateData: function(item){
+        switch(item){
+            case "ingredient":
+                home.drawInventoryCheckCard();
+                ingredients.populateByProperty("category");
+                addIngredients.isPopulated = false;
+                break;
+            case "recipe":
+                transactions.isPopulated = false;
+                recipeBook.populateRecipes();
+                break;
+            case "order":
+                orders.populate();
+                break;
+            case "transaction":
+                transactions.isPopulated = false;
+                transaction.display();
+                break;
+        }
     }
 }
 

+ 8 - 11
views/dashboardPage/js/Merchant.js

@@ -89,9 +89,8 @@ class Merchant{
             }
         }
     
-        ingredientsStrandObj.populateByProperty("category");
-        addIngredientsComp.isPopulated = false;
-        closeSidebar();
+        controller.updateData("ingredient");
+        controller.closeSidebar();
     }
 
     /*
@@ -122,9 +121,8 @@ class Merchant{
             }
         }
 
-        transactionsStrandObj.isPopulated = false;
-        recipeBookStrandObj.populateRecipes();
-        closeSidebar();
+        controller.updateData("recipe");
+        controller.closeSidebar();
     }
 
     /*
@@ -154,8 +152,8 @@ class Merchant{
             }
         }
 
-        ordersStrandObj.populate();
-        closeSidebar();
+        controller.updateData("order");
+        controller.closeSidebar();
     }
 
     editTransactions(transaction, remove = false){
@@ -176,9 +174,8 @@ class Merchant{
             this.transactions.sort((a, b) => a.date > b.date ? 1 : -1);
         }
 
-        transactionsStrandObj.isPopulated = false;
-        transactionsStrandObj.display();
-        closeSidebar();
+        controller.updateData("transaction");
+        controller.closeSidebar();
     }
 
     /*

+ 27 - 0
views/dashboardPage/js/dashboard.js

@@ -15,6 +15,7 @@ const recipeDetails = require("./recipeDetails.js");
 const transactionDetails = require("./transactionDetails.js");
 
 const Merchant = require("./Merchant.js");
+const { transaction } = require("./transactionDetails.js");
 
 merchant = new Merchant(data.merchant, data.transactions);
 
@@ -187,6 +188,32 @@ controller = {
         }
     
         return converted;
+    },
+
+    /*
+    Sets certain strands to repopulate everything the next time it is opened
+    Use for when any data is changed
+    item = whatever is being updated
+    */
+    updateData: function(item){
+        switch(item){
+            case "ingredient":
+                home.drawInventoryCheckCard();
+                ingredients.populateByProperty("category");
+                addIngredients.isPopulated = false;
+                break;
+            case "recipe":
+                transactions.isPopulated = false;
+                recipeBook.populateRecipes();
+                break;
+            case "order":
+                orders.populate();
+                break;
+            case "transaction":
+                transactions.isPopulated = false;
+                transaction.display();
+                break;
+        }
     }
 }