2019-07-23 14:23:12 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
import {EnvProperties} from './properties/env-properties';
|
2024-02-07 20:36:47 +01:00
|
|
|
import {BehaviorSubject, Observable, of} from "rxjs";
|
2020-09-14 17:48:43 +02:00
|
|
|
import {catchError, map} from "rxjs/operators";
|
2024-02-07 20:36:47 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
|
2020-05-19 17:33:47 +02:00
|
|
|
@Injectable({
|
|
|
|
providedIn: "root"
|
|
|
|
})
|
2019-07-23 14:23:12 +02:00
|
|
|
export class IndexInfoService {
|
2024-02-07 20:36:47 +01:00
|
|
|
private lastIndexDateSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
}
|
|
|
|
|
2024-02-07 20:36:47 +01:00
|
|
|
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)}));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2020-11-27 11:42:30 +01:00
|
|
|
getStatsLastDate(properties: EnvProperties): Observable<any> {
|
|
|
|
let url = properties.indexInfoAPI;
|
|
|
|
return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => res['stats_update_date'])).pipe(catchError(err => {return of(null)}));
|
|
|
|
}
|
2021-05-19 15:07:43 +02:00
|
|
|
getLastOrcidUpdateDate(properties: EnvProperties): Observable<any> {
|
|
|
|
let url = properties.indexInfoAPI;
|
|
|
|
return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => res['orcid_update_date'])).pipe(catchError(err => {return of(null)}));
|
|
|
|
}
|
2023-10-26 08:48:11 +02:00
|
|
|
getDBLoadLastDate(properties: EnvProperties): Observable<any> {
|
|
|
|
let url = properties.indexInfoAPI;
|
|
|
|
return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url).pipe(map(res => res['db_load_date'])).pipe(catchError(err => {return of(null)}));
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|