Sfoglia il codice sorgente

Frontend updates ingredients on order removal

Lee Morgan 5 anni fa
parent
commit
9ef5c8c797

+ 8 - 4
views/dashboardPage/bundle.js

@@ -109,11 +109,10 @@ class Merchant{
     /*
     Updates all specified item in the merchant's inventory and updates the page
     If ingredient doesn't exist, add it
-    ingredients = {
+    ingredients = [{
         ingredient: Ingredient object,
         quantity: new quantity,
-        defaultUnit: the default unit to be displayed
-    }
+    }]
     remove = set true if removing
     isOrder = set true if this is coming from an order
     */
@@ -122,7 +121,7 @@ class Merchant{
             let isNew = true;
             for(let j = 0; j < this.ingredients.length; j++){
                 if(this.ingredients[j].ingredient === ingredients[i].ingredient){
-                    if(remove){
+                    if(remove && !isOrder){
                         this.ingredients.splice(j, 1);
                     }else if(!remove && isOrder){
                         this.ingredients[j].quantity += ingredients[i].quantity;
@@ -2361,7 +2360,12 @@ let orderDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
+                    for(let i = 0; i < order.ingredients.length; i++){
+                        order.ingredients[i].quantity = -order.ingredients[i].quantity;
+                    }
+
                     merchant.editOrders([order], true);
+                    merchant.editIngredients(order.ingredients, false, true);
                     banner.createNotification("ORDER REMOVED");
                 }
             })

+ 3 - 4
views/dashboardPage/js/Merchant.js

@@ -57,11 +57,10 @@ class Merchant{
     /*
     Updates all specified item in the merchant's inventory and updates the page
     If ingredient doesn't exist, add it
-    ingredients = {
+    ingredients = [{
         ingredient: Ingredient object,
         quantity: new quantity,
-        defaultUnit: the default unit to be displayed
-    }
+    }]
     remove = set true if removing
     isOrder = set true if this is coming from an order
     */
@@ -70,7 +69,7 @@ class Merchant{
             let isNew = true;
             for(let j = 0; j < this.ingredients.length; j++){
                 if(this.ingredients[j].ingredient === ingredients[i].ingredient){
-                    if(remove){
+                    if(remove && !isOrder){
                         this.ingredients.splice(j, 1);
                     }else if(!remove && isOrder){
                         this.ingredients[j].quantity += ingredients[i].quantity;

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

@@ -58,7 +58,12 @@ let orderDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
+                    for(let i = 0; i < order.ingredients.length; i++){
+                        order.ingredients[i].quantity = -order.ingredients[i].quantity;
+                    }
+
                     merchant.editOrders([order], true);
+                    merchant.editIngredients(order.ingredients, false, true);
                     banner.createNotification("ORDER REMOVED");
                 }
             })