Revision 55998
Added by Konstantinos Triantafyllou almost 5 years ago
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/curators/curator.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {HttpClient} from '@angular/common/http'; |
3 |
import {BehaviorSubject, Observable} from 'rxjs';
|
|
3 |
import {Observable} from 'rxjs'; |
|
4 | 4 |
import {Curator} from '../../utils/entities/CuratorInfo'; |
5 | 5 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
6 | 6 |
import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; |
... | ... | |
8 | 8 |
@Injectable() |
9 | 9 |
export class CuratorService { |
10 | 10 |
|
11 |
private curatorsSubject: BehaviorSubject<Curator[]> = new BehaviorSubject([]); |
|
12 |
|
|
13 | 11 |
constructor(private http: HttpClient) { |
14 | 12 |
} |
15 | 13 |
|
16 |
public initCurators(properties: EnvProperties, url: string): void { |
|
17 |
this.http.get<Curator[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url). |
|
18 |
subscribe((curators) => { |
|
19 |
this.curatorsSubject.next(curators); |
|
20 |
}); |
|
14 |
public getCurators(properties: EnvProperties, url: string): Observable<Curator[]> { |
|
15 |
return this.http.get<Curator[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); |
|
21 | 16 |
} |
22 | 17 |
|
23 |
public get curators(): Observable<Curator[]> { |
|
24 |
return this.curatorsSubject.asObservable(); |
|
25 |
} |
|
26 |
|
|
27 |
public updateCurators(curator: Curator) { |
|
28 |
const curators = this.curatorsSubject.value; |
|
29 |
if (curators && curator) { |
|
30 |
curator._id = null; |
|
31 |
curators.push(curator); |
|
32 |
this.curatorsSubject.next(curators); |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 | 18 |
public updateCurator(url: string, curator: Curator) { |
37 | 19 |
return this.http.post<Curator>(url, curator, CustomOptions.getAuthOptions()); |
38 | 20 |
} |
Also available in: Unified diff
[Trunk|Library]: Remove subject from curators service.