Преглед на файлове

Remove all references in various places to the different strands

Lee Morgan преди 6 години
родител
ревизия
e19b0841b3

+ 53 - 33
views/dashboardPage/bundle.js

@@ -984,6 +984,11 @@ controller = {
                 transactions.isPopulated = false;
                 transaction.display();
                 break;
+            case "unit":
+                home.isPopulated = false;
+                ingredients.populateByProperty("category");
+                document.getElementById("ingredientStock").innerText = `${this.ingredient.ingredient.convert(this.ingredient.quantity).toFixed(2)} ${this.ingredient.ingredient.unit.toUpperCase()}`;
+                break;
         }
     }
 }
@@ -1216,7 +1221,7 @@ module.exports = {
 module.exports = {
     ingredient: {},
 
-    display: function(merchant, ingredient){
+    display: function(ingredient){
         this.ingredient = ingredient;
 
         document.getElementById("editIngBtn").onclick = ()=>{this.edit()};
@@ -1337,39 +1342,42 @@ module.exports = {
     },
 
     editSubmit: function(){
-        this.ingredient.quantity = Number(document.getElementById("ingredientInput").value);
+        this.ingredient.quantity = controller.convertToMain(
+            this.ingredient.ingredient.unit,
+            Number(document.getElementById("ingredientInput").value)
+        );
+        
         let data = [{
             id: this.ingredient.ingredient.id,
-            quantity: this.ingredient.quantity
+            quantity: controller.convertToMain(this.ingredient.ingredient.unit, this.ingredient.quantity)
         }];
 
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        if(validator.ingredientQuantity(data[0].quantity)){
-            fetch("/merchant/ingredients/update", {
-                method: "PUT",
-                headers: {
-                    "Content-Type": "application/json;charset=utf-8"
-                },
-                body: JSON.stringify(data)
+        fetch("/merchant/ingredients/update", {
+            method: "PUT",
+            headers: {
+                "Content-Type": "application/json;charset=utf-8"
+            },
+            body: JSON.stringify(data)
+        })
+            .then((response) => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    banner.createError(response);
+                }else{
+                    merchant.editIngredients([this.ingredient]);
+                    banner.createNotification("INGREDIENT UPDATED");
+                }
             })
-                .then((response) => response.json())
-                .then((response)=>{
-                    if(typeof(response) === "string"){
-                        banner.createError(response);
-                    }else{
-                        merchant.editIngredients([this.ingredient]);
-                        banner.createNotification("INGREDIENT UPDATED");
-                    }
-                })
-                .catch((err)=>{
-                    banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
-                })
-                .finally(()=>{
-                    loader.style.display = "none";
-                });
-        }
+            .catch((err)=>{
+                console.log(err);
+                banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
     },
 
     changeUnit: function(newActive, unit){
@@ -1382,9 +1390,7 @@ module.exports = {
 
         newActive.classList.add("unitActive");
 
-        homeStrandObj.isPopulated = false;
-        ingredientsStrandObj.populateByProperty("category");
-        document.getElementById("ingredientStock").innerText = `${this.ingredient.ingredient.convert(this.ingredient.quantity).toFixed(2)} ${this.ingredient.ingredient.unit.toUpperCase()}`;
+        controller.updateData("unit");
     },
 
     changeUnitDefault: function(){
@@ -1419,15 +1425,19 @@ module.exports = {
     isPopulated: false,
     ingredients: [],
 
-    display: function(merchant){
+    display: function(){
         if(!this.isPopulated){
-            this.populateByProperty("category", merchant);
+            this.populateByProperty("category");
+
+            document.getElementById("ingredientSearch").oninput = ()=>{this.search()};
+            document.getElementById("ingredientClearButton").onclick = ()=>{this.clearSorting()};
+            document.getElementById("ingredientSelect").onchange = ()=>{this.sort()};
 
             this.isPopulated = true;
         }
     },
 
-    populateByProperty: function(property, merchant){
+    populateByProperty: function(property){
         let categories;
         if(property === "category"){
             categories = merchant.categorizeIngredients();
@@ -1510,7 +1520,9 @@ module.exports = {
         this.displayIngredientsOnly(matchingIngredients);
     },
 
-    sort: function(sortType){
+    sort: function(){
+        let sortType = document.getElementById("ingredientSelect");
+        
         if(sortType === ""){
             return;
         }
@@ -2053,6 +2065,8 @@ module.exports = {
                         }
                         merchant.editOrders(newOrders);
 
+                        document.getElementById("orderSubmitForm").onsubmit = ()=>{this.submitFilter()};
+
                         this.isFetched = true;
                     }
                 })
@@ -2208,6 +2222,10 @@ module.exports = {
         if(!this.isPopulated){
             this.populateRecipes();
 
+            document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate()};
+            document.getElementById("recipeSearch").oninput = ()=>{this.search()};
+            document.getElementById("recipeClearButton").onclick = ()=>{this.clearSorting()};
+
             this.isPopulated = true;
         }
     },
@@ -2622,6 +2640,8 @@ module.exports = {
                 i++;
             }
 
+            document.getElementById("transFormSubmit").onsubmit = ()=>{this.submitFilter()};
+
             this.isPopulated = true;
         }
     },

+ 8 - 8
views/dashboardPage/dashboard.ejs

@@ -159,10 +159,10 @@
                             <circle cx="11" cy="11" r="8"></circle>
                             <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
                         </svg>
-                        <input id="ingredientSearch" type="text" placeholder="FILTER" oninput="ingredientsStrandObj.search()">
+                        <input id="ingredientSearch" type="text" placeholder="FILTER">
                     </div>
 
-                    <button id="ingredientClearButton" class="clearButton" onclick="ingredientsStrandObj.clearSorting()" style="display: none;">
+                    <button id="ingredientClearButton" class="clearButton" style="display: none;">
                         <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                             <circle cx="12" cy="12" r="10"></circle>
                             <line x1="15" y1="9" x2="9" y2="15"></line>
@@ -170,7 +170,7 @@
                         </svg>
                     </button>
 
-                    <select id="ingredientSelect" class="mobileHide" onchange="ingredientsStrandObj.sort(this.value)">Sort Bys:
+                    <select id="ingredientSelect" class="mobileHide">Sort By:
                         <option value="" selected disabled>Sort By:</option>
                         <option value="_name">Ingredient</option>
                         <option value="category">Category</option>
@@ -214,7 +214,7 @@
                     <% if(merchant.pos === "none"){ %>
                         <button class="button mobileHide" onclick="controller.openSidebar('newRecipe')">NEW</button>
                     <% }else if(merchant.pos === "clover"){ %>
-                        <button class="button mobileHide" onclick="recipeBookStrandObj.posUpdate()">UPDATE</button>
+                        <button id="posUpdateRecipe" class="button mobileHide">UPDATE</button>
                     <% } %>
                 </div>
 
@@ -224,10 +224,10 @@
                             <circle cx="11" cy="11" r="8"></circle>
                             <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
                         </svg>
-                        <input id="recipeSearch" type="text" placeholder="FILTER" oninput="recipeBookStrandObj.search()">
+                        <input id="recipeSearch" type="text" placeholder="FILTER">
                     </div>
 
-                    <button id="recipeClearButton" class="clearButton" onclick="recipeBookStrandObj.clearSorting()" style="display: none;">
+                    <button id="recipeClearButton" class="clearButton" style="display: none;">
                         <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                             <circle cx="12" cy="12" r="10"></circle>
                             <line x1="15" y1="9" x2="9" y2="15"></line>
@@ -253,7 +253,7 @@
                     <button class="button mobileHide" onclick="controller.openSidebar('newOrder')">NEW</button>
                 </div>
 
-                <form onsubmit="ordersStrandObj.submitFilter()" class="filterForm">
+                <form id="orderSubmitForm" class="filterForm">
                     <h2>Search</h2>
                     <div>
                         <div class="dropdown">
@@ -312,7 +312,7 @@
                     <button class="button mobileHide" onclick="controller.openSidebar('newTransaction')">NEW</button>
                 </div>
 
-                <form onsubmit="transactionsStrandObj.submitFilter()" class="filterForm">
+                <form id="transFormSubmit" class="filterForm">
                     <h2>Search</h2>
                     <div>
                         <div class="dropdown">

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

@@ -231,6 +231,11 @@ controller = {
                 transactions.isPopulated = false;
                 transaction.display();
                 break;
+            case "unit":
+                home.isPopulated = false;
+                ingredients.populateByProperty("category");
+                document.getElementById("ingredientStock").innerText = `${this.ingredient.ingredient.convert(this.ingredient.quantity).toFixed(2)} ${this.ingredient.ingredient.unit.toUpperCase()}`;
+                break;
         }
     }
 }

+ 30 - 29
views/dashboardPage/js/ingredientDetails.js

@@ -1,7 +1,7 @@
 module.exports = {
     ingredient: {},
 
-    display: function(merchant, ingredient){
+    display: function(ingredient){
         this.ingredient = ingredient;
 
         document.getElementById("editIngBtn").onclick = ()=>{this.edit()};
@@ -122,39 +122,42 @@ module.exports = {
     },
 
     editSubmit: function(){
-        this.ingredient.quantity = Number(document.getElementById("ingredientInput").value);
+        this.ingredient.quantity = controller.convertToMain(
+            this.ingredient.ingredient.unit,
+            Number(document.getElementById("ingredientInput").value)
+        );
+        
         let data = [{
             id: this.ingredient.ingredient.id,
-            quantity: this.ingredient.quantity
+            quantity: controller.convertToMain(this.ingredient.ingredient.unit, this.ingredient.quantity)
         }];
 
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        if(validator.ingredientQuantity(data[0].quantity)){
-            fetch("/merchant/ingredients/update", {
-                method: "PUT",
-                headers: {
-                    "Content-Type": "application/json;charset=utf-8"
-                },
-                body: JSON.stringify(data)
+        fetch("/merchant/ingredients/update", {
+            method: "PUT",
+            headers: {
+                "Content-Type": "application/json;charset=utf-8"
+            },
+            body: JSON.stringify(data)
+        })
+            .then((response) => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    banner.createError(response);
+                }else{
+                    merchant.editIngredients([this.ingredient]);
+                    banner.createNotification("INGREDIENT UPDATED");
+                }
             })
-                .then((response) => response.json())
-                .then((response)=>{
-                    if(typeof(response) === "string"){
-                        banner.createError(response);
-                    }else{
-                        merchant.editIngredients([this.ingredient]);
-                        banner.createNotification("INGREDIENT UPDATED");
-                    }
-                })
-                .catch((err)=>{
-                    banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
-                })
-                .finally(()=>{
-                    loader.style.display = "none";
-                });
-        }
+            .catch((err)=>{
+                console.log(err);
+                banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
     },
 
     changeUnit: function(newActive, unit){
@@ -167,9 +170,7 @@ module.exports = {
 
         newActive.classList.add("unitActive");
 
-        homeStrandObj.isPopulated = false;
-        ingredientsStrandObj.populateByProperty("category");
-        document.getElementById("ingredientStock").innerText = `${this.ingredient.ingredient.convert(this.ingredient.quantity).toFixed(2)} ${this.ingredient.ingredient.unit.toUpperCase()}`;
+        controller.updateData("unit");
     },
 
     changeUnitDefault: function(){

+ 10 - 4
views/dashboardPage/js/ingredients.js

@@ -2,15 +2,19 @@ module.exports = {
     isPopulated: false,
     ingredients: [],
 
-    display: function(merchant){
+    display: function(){
         if(!this.isPopulated){
-            this.populateByProperty("category", merchant);
+            this.populateByProperty("category");
+
+            document.getElementById("ingredientSearch").oninput = ()=>{this.search()};
+            document.getElementById("ingredientClearButton").onclick = ()=>{this.clearSorting()};
+            document.getElementById("ingredientSelect").onchange = ()=>{this.sort()};
 
             this.isPopulated = true;
         }
     },
 
-    populateByProperty: function(property, merchant){
+    populateByProperty: function(property){
         let categories;
         if(property === "category"){
             categories = merchant.categorizeIngredients();
@@ -93,7 +97,9 @@ module.exports = {
         this.displayIngredientsOnly(matchingIngredients);
     },
 
-    sort: function(sortType){
+    sort: function(){
+        let sortType = document.getElementById("ingredientSelect");
+        
         if(sortType === ""){
             return;
         }

+ 2 - 0
views/dashboardPage/js/orders.js

@@ -29,6 +29,8 @@ module.exports = {
                         }
                         merchant.editOrders(newOrders);
 
+                        document.getElementById("orderSubmitForm").onsubmit = ()=>{this.submitFilter()};
+
                         this.isFetched = true;
                     }
                 })

+ 4 - 0
views/dashboardPage/js/recipeBook.js

@@ -6,6 +6,10 @@ module.exports = {
         if(!this.isPopulated){
             this.populateRecipes();
 
+            document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate()};
+            document.getElementById("recipeSearch").oninput = ()=>{this.search()};
+            document.getElementById("recipeClearButton").onclick = ()=>{this.clearSorting()};
+
             this.isPopulated = true;
         }
     },

+ 2 - 0
views/dashboardPage/js/transactions.js

@@ -65,6 +65,8 @@ module.exports = {
                 i++;
             }
 
+            document.getElementById("transFormSubmit").onsubmit = ()=>{this.submitFilter()};
+
             this.isPopulated = true;
         }
     },