Browse Source

fix: Navigating to page wouldn't load previous data

master
Konstantinos Kamaropoulos 5 years ago
parent
commit
e46be96b57
  1. 2
      src/app/chart/chart.component.ts
  2. 6
      src/app/logs.service.ts
  3. 10
      src/app/map/map.component.ts

2
src/app/chart/chart.component.ts

@ -31,7 +31,7 @@ export class ChartComponent implements OnInit {
dataConfig: Array<Object> = []; dataConfig: Array<Object> = [];
async ngOnInit() { async ngOnInit() {
let data = await this.logsService.getUpdates(); let data = await this.logsService.getLogsFirstRun();
for (const key in data[0]['sensorReadings']) { for (const key in data[0]['sensorReadings']) {
if (data[0]['sensorReadings'].hasOwnProperty(key)) { if (data[0]['sensorReadings'].hasOwnProperty(key)) {
const element = data[0]['sensorReadings'][key]; const element = data[0]['sensorReadings'][key];

6
src/app/logs.service.ts

@ -23,6 +23,12 @@ export class LogsService {
.toPromise(); .toPromise();
} }
async getLogsFirstRun(): Promise<Array<Object>> {
let data = await this.getLogs();
this.previousData = data;
return data;
}
async getUpdates(): Promise<Array<Object>> { async getUpdates(): Promise<Array<Object>> {
let prevData = this.previousData; let prevData = this.previousData;
if (!this.previousData) { if (!this.previousData) {

10
src/app/map/map.component.ts

@ -38,8 +38,16 @@ export class MapComponent implements OnInit {
// Add map controls // Add map controls
// this.map.addControl(new mapboxgl.NavigationControl()); // this.map.addControl(new mapboxgl.NavigationControl());
var firstRun: Boolean = true;
this.sub = interval(1000).subscribe(async val => { this.sub = interval(1000).subscribe(async val => {
let data = await this.logsService.getUpdates(); let data: Array<Object>;
if (firstRun) {
data = await this.logsService.getLogsFirstRun();
firstRun = false;
} else {
data = await this.logsService.getUpdates();
}
for (let log of data) { for (let log of data) {
if (log['gps_data']['status'] == 'A') { if (log['gps_data']['status'] == 'A') {
let html = let html =

Loading…
Cancel
Save