|
@ -1,7 +1,7 @@ |
|
|
import { Injectable } from '@angular/core'; |
|
|
import { Injectable } from '@angular/core'; |
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
import { Observable, of } from 'rxjs'; |
|
|
import { Observable, of } from 'rxjs'; |
|
|
import { map, catchError } from 'rxjs/operators'; |
|
|
import { map, catchError, last } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
@Injectable({ |
|
|
@Injectable({ |
|
|
providedIn: 'root' |
|
|
providedIn: 'root' |
|
@ -9,13 +9,32 @@ import { map, catchError } from 'rxjs/operators'; |
|
|
export class LogsService { |
|
|
export class LogsService { |
|
|
constructor(private httpClient: HttpClient) {} |
|
|
constructor(private httpClient: HttpClient) {} |
|
|
|
|
|
|
|
|
getLogs(): Observable<Array<Object>> { |
|
|
previousData: Array<Object> | undefined = undefined; |
|
|
return this.httpClient.get('http://192.168.100.4:4000/logs').pipe( |
|
|
|
|
|
|
|
|
getLogs(): Promise<Array<Object>> { |
|
|
|
|
|
return this.httpClient |
|
|
|
|
|
.get('http://192.168.100.4:3000/logs') |
|
|
|
|
|
.pipe( |
|
|
map((body: any) => { |
|
|
map((body: any) => { |
|
|
console.log(body); |
|
|
|
|
|
return body; |
|
|
return body; |
|
|
}), |
|
|
}), |
|
|
catchError(() => of('Error, could not load logs')) |
|
|
catchError(() => of('Error, could not load logs')) |
|
|
); |
|
|
) |
|
|
|
|
|
.toPromise(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getUpdates(): Promise<Array<Object>> { |
|
|
|
|
|
if (!this.previousData) { |
|
|
|
|
|
let data = await this.getLogs(); |
|
|
|
|
|
this.previousData = data; |
|
|
|
|
|
return data; |
|
|
|
|
|
} else { |
|
|
|
|
|
let latestData = await this.getLogs(); |
|
|
|
|
|
let changes = latestData.filter(function(e) { |
|
|
|
|
|
return this.indexOf(e) < 0; |
|
|
|
|
|
}, this.previousData); |
|
|
|
|
|
this.previousData = latestData; |
|
|
|
|
|
return changes; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|