From 31aab818bf326f2ab0f85dae273e748694b5e54b Mon Sep 17 00:00:00 2001 From: Conor McNamara Date: Tue, 28 Mar 2023 18:51:06 +0100 Subject: [PATCH] Request data on frontend with a loop --- src/pages/InsightsPage.vue | 4 ++-- src/pages/MapPage.vue | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/pages/InsightsPage.vue b/src/pages/InsightsPage.vue index 3b7d4da..3425ffb 100644 --- a/src/pages/InsightsPage.vue +++ b/src/pages/InsightsPage.vue @@ -11,7 +11,7 @@

Total number of trains: {{ this.insights["totalNumTrains"] }}

@@ -23,7 +23,7 @@

Total number of stations: {{ this.insights["totalNumStations"] }}

diff --git a/src/pages/MapPage.vue b/src/pages/MapPage.vue index 59eb804..0e632ea 100644 --- a/src/pages/MapPage.vue +++ b/src/pages/MapPage.vue @@ -81,9 +81,9 @@
Red
Late Train
Green
-
Early/On Time Train
+
Early/On-Time Train
Black
-
Terminated/Not Yet Running Train
+
Terminated/Not-Yet Running Train
@@ -185,6 +185,7 @@ export default { publicMessages: [], isPaused: false, readyToDisplayMap: false, + isFirstGET: true, store, searchinput: "", @@ -218,6 +219,7 @@ export default { created() { this.readyToDisplayMap = false + this.isFirstGET = true let host = window.location.hostname if (host === '127.0.0.1' || host === 'localhost') { this.postTrainAndStationData(); @@ -226,7 +228,7 @@ export default { this.getTrainAndStationData(); } // request new data every 60 seconds - // window.setInterval(this.getTrainAndStationData, 60000); + window.setInterval(this.getTrainAndStationData, 60000); }, methods: { @@ -421,6 +423,9 @@ export default { "numTrainStations": 0, "numDartStations": 0 }; + + // fill showTrains with the default value - true + if (this.isFirstGET) this.showTrains = new Array(response.data.length).fill(true) // create an array of coordinates and hashmap with the key-values {index: JSON obj} for (var i=0; i { if (!response.data) throw new Error("Error fetching station from the database"); + // fill showStations with the default value - true + if (this.isFirstGET) this.showStations = new Array(response.data.length).fill(true) + for (var i=0; i