[Trunk|Library]: 1. Add Curator Class and Service for curated by functionality.2. User Component: change main component default value to true.(It exists also on Angular7 branch).

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@55728 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-05-27 08:54:58 +00:00
parent d358607977
commit 3f189ff1b6
3 changed files with 66 additions and 1 deletions

View File

@ -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<Curator[]> = new BehaviorSubject([]);
constructor(private http: HttpClient) {
}
public initCurators(properties: EnvProperties, url: string): void {
this.http.get<Curator[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
subscribe((curators) => {
this.curatorsSubject.next(curators);
});
}
public get curators(): Observable<Curator[]> {
return this.curatorsSubject.asObservable();
}
public updateCurator(url: string, curator: Curator) {
this.http.post<Curator>(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<Curator> {
return this.http.get<Curator>((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
};
}
}

View File

@ -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,

View File

@ -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;
}