[Trunk | Library]: Create affiliations.service in connect folder to get affiliations from communities API.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@56028 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
c94bfdb928
commit
d8552c8a08
|
@ -0,0 +1,43 @@
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
|
import {Affiliation} from '../../utils/entities/CuratorInfo';
|
||||||
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||||
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AffiliationService {
|
||||||
|
|
||||||
|
private affiliationsSubject: BehaviorSubject<Affiliation[]> = new BehaviorSubject([]);
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public initAffiliations(properties: EnvProperties, url: string): void {
|
||||||
|
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
|
||||||
|
subscribe((affiliations) => {
|
||||||
|
this.affiliationsSubject.next(affiliations);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public get affiliations(): Observable<Affiliation[]> {
|
||||||
|
return this.affiliationsSubject.asObservable();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public updateAffiliations(affiliation: Affiliation) {
|
||||||
|
// const affiliations = this.affiliationsSubject.value;
|
||||||
|
// if (affiliations && affiliation) {
|
||||||
|
// affiliations.push(affiliation);
|
||||||
|
// this.affiliationsSubject.next(affiliations);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public updateAffiliation(url: string, affiliation: Affiliation) {
|
||||||
|
// return this.http.post<Affiliation>(url, affiliation, CustomOptions.getAuthOptions());
|
||||||
|
// }
|
||||||
|
|
||||||
|
public getAffiliation(properties: EnvProperties, url: string): Observable<Affiliation> {
|
||||||
|
return this.http.get<Affiliation>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue