[develop | DONE | CHANGED]: indexInfo.service.ts: Added "lastIndexDateSubject" BehaviorSubject | newSearchPage.component.ts: In ngOninit, call "indexInfoService.lastIndexDate" get method instead of "indexInfoService.getLastIndexDate()", to get last index date from subject value.
This commit is contained in:
parent
b357ff2ae2
commit
137278522e
|
@ -218,7 +218,7 @@ export class NewSearchPageComponent implements OnInit, OnDestroy, OnChanges {
|
|||
}
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
|
||||
this.subscriptions.push(this.indexInfoService.lastIndexDate.subscribe(lastIndexUpdate => {
|
||||
if (lastIndexUpdate) {
|
||||
this.indexUpdateDate = new Date(lastIndexUpdate);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,34 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {EnvProperties} from './properties/env-properties';
|
||||
import {Observable, of} from "rxjs";
|
||||
import {BehaviorSubject, Observable, of} from "rxjs";
|
||||
import {catchError, map} from "rxjs/operators";
|
||||
import {properties} from "../../../environments/environment";
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root"
|
||||
})
|
||||
export class IndexInfoService {
|
||||
private lastIndexDateSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getLastIndexDate(properties: EnvProperties): Observable<any> {
|
||||
let url = properties.indexInfoAPI;
|
||||
return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => res['claim_load_date'])).pipe(catchError(err => {return of(null)}));
|
||||
get lastIndexDate(): Observable<any> {
|
||||
return this.lastIndexDateSubject.getValue() ? this.lastIndexDateSubject.asObservable() : this.getLastIndexDate();
|
||||
}
|
||||
|
||||
setLastIndexDate(value: any) {
|
||||
this.lastIndexDateSubject.next(value);
|
||||
}
|
||||
|
||||
getLastIndexDate(props: EnvProperties = properties): Observable<any> {
|
||||
let url = props.indexInfoAPI;
|
||||
return this.http.get((props.useLongCache)? (props.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => {
|
||||
this.setLastIndexDate(res['claim_load_date']);
|
||||
return res['claim_load_date'];
|
||||
})).pipe(catchError(err => {return of(null)}));
|
||||
}
|
||||
getStatsLastDate(properties: EnvProperties): Observable<any> {
|
||||
let url = properties.indexInfoAPI;
|
||||
|
|
Loading…
Reference in New Issue