Project

General

Profile

« Previous | Next » 

Revision 56028

[Trunk | Library]: Create affiliations.service in connect folder to get affiliations from communities API.

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/affiliations/affiliation.service.ts
1
import {Injectable} from '@angular/core';
2
import {HttpClient} from '@angular/common/http';
3
import {BehaviorSubject, Observable} from 'rxjs';
4
import {Affiliation} from '../../utils/entities/CuratorInfo';
5
import {EnvProperties} from '../../utils/properties/env-properties';
6
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
7

  
8
@Injectable()
9
export class AffiliationService {
10

  
11
  private affiliationsSubject: BehaviorSubject<Affiliation[]> = new BehaviorSubject([]);
12

  
13
  constructor(private http: HttpClient) {
14
  }
15

  
16
  public initAffiliations(properties: EnvProperties, url: string): void {
17
    this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
18
    subscribe((affiliations) => {
19
      this.affiliationsSubject.next(affiliations);
20
    });
21
  }
22

  
23
  public get affiliations(): Observable<Affiliation[]> {
24
    return this.affiliationsSubject.asObservable();
25
  }
26

  
27
  // public updateAffiliations(affiliation: Affiliation) {
28
  //   const affiliations = this.affiliationsSubject.value;
29
  //   if (affiliations && affiliation) {
30
  //     affiliations.push(affiliation);
31
  //     this.affiliationsSubject.next(affiliations);
32
  //   }
33
  // }
34
  //
35
  // public updateAffiliation(url: string, affiliation: Affiliation) {
36
  //   return this.http.post<Affiliation>(url, affiliation, CustomOptions.getAuthOptions());
37
  // }
38

  
39
  public getAffiliation(properties: EnvProperties, url: string): Observable<Affiliation> {
40
    return this.http.get<Affiliation>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
41
  }
42

  
43
}

Also available in: Unified diff