diff --git a/connect/curators/curator.service.ts b/connect/curators/curator.service.ts new file mode 100644 index 00000000..cb016368 --- /dev/null +++ b/connect/curators/curator.service.ts @@ -0,0 +1,48 @@ +import {Injectable} from "@angular/core"; +import {HttpClient, HttpHeaders} from "@angular/common/http"; +import {BehaviorSubject, Observable} from "rxjs"; +import {Curator} from "../../utils/entities/CuratorInfo"; +import {EnvProperties} from "../../utils/properties/env-properties"; +import {COOKIE} from "../../login/utils/helper.class"; + +@Injectable() +export class CuratorService { + + private curatorsSubject: BehaviorSubject = new BehaviorSubject([]); + + constructor(private http: HttpClient) { + } + + public initCurators(properties: EnvProperties, url: string): void { + this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url). + subscribe((curators) => { + this.curatorsSubject.next(curators); + }); + } + + public get curators(): Observable { + return this.curatorsSubject.asObservable(); + } + + public updateCurator(url: string, curator: Curator) { + this.http.post(url, {curator: curator}, this.getAuthOptions()).subscribe((res) => { + let curators = this.curatorsSubject.value; + curator.id = null; + curators.push(curator); + this.curatorsSubject.next(curators); + }); + } + + public getCurator(properties: EnvProperties, url: string): Observable { + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); + } + + // TODO remove and use CustomOptions.getAuthOptions() + private getAuthOptions(): any { + const httpOptions = { + headers: new HttpHeaders({ + 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id), + }), withCredentials: true + }; + } +} diff --git a/login/user.component.ts b/login/user.component.ts index 42436767..3f3dc3e1 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -25,7 +25,7 @@ export class UserComponent { public routerHelper:RouterHelper = new RouterHelper(); public loginUrl; properties:EnvProperties; - @Input() mainComponent = false; + @Input() mainComponent = true; constructor( private router: Router, private route: ActivatedRoute, diff --git a/utils/entities/CuratorInfo.ts b/utils/entities/CuratorInfo.ts new file mode 100644 index 00000000..ec2ee2bc --- /dev/null +++ b/utils/entities/CuratorInfo.ts @@ -0,0 +1,17 @@ +export class Curator { + + id: string = null; + email: string; + name: string; + surname: string; + affiliations: Affiliation[]; + photo: string; + bio: string; +} + +export class Affiliation { + + name: string; + logoUrl: string; + websiteUrl: string; +}