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

Hooked up choosing dates button with new data fetching function

Lee Morgan преди 6 години
родител
ревизия
51ab7ba370
променени са 4 файла, в които са добавени 23 реда и са изтрити 21 реда
  1. 1 1
      views/dataPage/data.ejs
  2. 7 5
      views/dataPage/fetchData.js
  3. 15 13
      views/dataPage/home.js
  4. 0 2
      views/shared/graphs.js

+ 1 - 1
views/dataPage/data.ejs

@@ -28,7 +28,7 @@
 
                 <input id="to" type="date">
 
-                <button id="dateSort" class="button">Submit</button>
+                <button id="dateSort" onclick="window.homeObj.newDates()" class="button">Submit</button>
             </div>
 
             <div class="buttonBox">

+ 7 - 5
views/dataPage/fetchData.js

@@ -1,4 +1,4 @@
-window.fetchData = function(from, to){
+window.fetchData = function(from, to, callback){
     retrieveDates = [];
 
     //Compares dates to dates already stored and makes a list of those needed
@@ -52,12 +52,10 @@ window.fetchData = function(from, to){
                             }
                             newIndex += 2;
                         }
-
-                        if(newIndex > 100 || oldIndex > 100){
-                            break;
-                        }
                     }
 
+                    data.dates = mergedDates;
+
                     for(let set of response.data){
                         if(set.transactions[0] < data.transactions[0]){
                             data.transactions = set.transactions.concat(data.transactions);
@@ -85,8 +83,12 @@ window.fetchData = function(from, to){
                             }
                         }
                     }
+
+                    callback();
                 }
             })
             .catch((err)=>{});
+    }else{
+        callback();
     }
 }

+ 15 - 13
views/dataPage/home.js

@@ -190,21 +190,23 @@ window.homeObj = {
             let startIndex = 0;
             let endIndex = data.transactions.length;
 
-            for(let i = 0; i < data.transactions.length; i++){
-                if(from < new Date(data.transactions[i].date)){
-                    startIndex = i;
-                    break;
+            window.fetchData(from, to, ()=>{
+                for(let i = 0; i < data.transactions.length; i++){
+                    if(from < new Date(data.transactions[i].date)){
+                        startIndex = i;
+                        break;
+                    }
                 }
-            }
-
-            for(let i = 0; i < data.transactions.length; i++){
-                if(to < new Date(data.transactions[i].date)){
-                    endIndex = i;
-                    break;
+    
+                for(let i = 0; i < data.transactions.length; i++){
+                    if(to < new Date(data.transactions[i].date)){
+                        endIndex = i;
+                        break;
+                    }
                 }
-            }
-
-            this.populate(data.transactions.slice(startIndex, endIndex));
+    
+                this.populate(data.transactions.slice(startIndex, endIndex));
+            });
         }
     }
 }

+ 0 - 2
views/shared/graphs.js

@@ -127,8 +127,6 @@ class LineGraph{
     }
 
     drawXAxis(){
-        console.log(this.data);
-
         this.context.beginPath();
         this.context.moveTo(this.left, this.bottom);
         this.context.lineTo(this.right, this.bottom);