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

Analytics mostly update when a new transaction is created

Lee Morgan 5 лет назад
Родитель
Сommit
807304b448

+ 14 - 2
views/dashboardPage/bundle.js

@@ -523,6 +523,7 @@ class Transaction{
 module.exports = Transaction;
 },{}],6:[function(require,module,exports){
 let analytics = {
+    newData: false,
     dateChange: false,
     transactions: [],
     ingredient: {},
@@ -531,12 +532,12 @@ let analytics = {
     display: function(Transaction){
         document.getElementById("analDateBtn").onclick = ()=>{this.changeDates(Transaction)};
 
-        if(this.transactions.length === 0){
+        if(this.transactions.length === 0 || this.newData === true){
             let startDate = new Date();
             startDate.setMonth(startDate.getMonth() - 1);
             const dateIndices = controller.transactionIndices(merchant.transactions, startDate);
 
-            this.transactions = merchant.transactions.slice(dateIndices[0], dateIndices[1]);
+            this.transactions = merchant.transactions.slice(dateIndices[0], dateIndices[1] + 1);
         }
 
         let slider = document.getElementById("analSlider");
@@ -665,6 +666,11 @@ let analytics = {
                     }
                 }
             }
+
+            if(i === this.transactions.length - 1){
+                quantities.push(this.ingredient.ingredient.convert(currentQuantity));
+                dates.push(currentDate);
+            }
         }
 
         let trace = {
@@ -741,6 +747,11 @@ let analytics = {
                     quantity += recipe.quantity;
                 }
             }
+
+            if(i === this.transactions.length - 1){
+                quantities.push(quantity);
+                dates.push(currentDate);
+            }
         }
 
         const trace = {
@@ -1073,6 +1084,7 @@ controller = {
             case "transaction":
                 transactions.isPopulated = false;
                 transactions.display(Transaction);
+                analytics.newData = true;
                 break;
         }
     },

+ 13 - 2
views/dashboardPage/js/analytics.js

@@ -1,4 +1,5 @@
 let analytics = {
+    newData: false,
     dateChange: false,
     transactions: [],
     ingredient: {},
@@ -7,12 +8,12 @@ let analytics = {
     display: function(Transaction){
         document.getElementById("analDateBtn").onclick = ()=>{this.changeDates(Transaction)};
 
-        if(this.transactions.length === 0){
+        if(this.transactions.length === 0 || this.newData === true){
             let startDate = new Date();
             startDate.setMonth(startDate.getMonth() - 1);
             const dateIndices = controller.transactionIndices(merchant.transactions, startDate);
 
-            this.transactions = merchant.transactions.slice(dateIndices[0], dateIndices[1]);
+            this.transactions = merchant.transactions.slice(dateIndices[0], dateIndices[1] + 1);
         }
 
         let slider = document.getElementById("analSlider");
@@ -141,6 +142,11 @@ let analytics = {
                     }
                 }
             }
+
+            if(i === this.transactions.length - 1){
+                quantities.push(this.ingredient.ingredient.convert(currentQuantity));
+                dates.push(currentDate);
+            }
         }
 
         let trace = {
@@ -217,6 +223,11 @@ let analytics = {
                     quantity += recipe.quantity;
                 }
             }
+
+            if(i === this.transactions.length - 1){
+                quantities.push(quantity);
+                dates.push(currentDate);
+            }
         }
 
         const trace = {

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

@@ -240,6 +240,7 @@ controller = {
             case "transaction":
                 transactions.isPopulated = false;
                 transactions.display(Transaction);
+                analytics.newData = true;
                 break;
         }
     },