diff --git a/connect/affiliations/affiliation.service.ts b/connect/affiliations/affiliation.service.ts index 751cd7fc..cd7d522a 100644 --- a/connect/affiliations/affiliation.service.ts +++ b/connect/affiliations/affiliation.service.ts @@ -2,35 +2,38 @@ import {Injectable} from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {BehaviorSubject, Observable} from 'rxjs'; import {Affiliation} from '../../utils/entities/CuratorInfo'; -import {EnvProperties} from '../../utils/properties/env-properties'; +import {properties} from "../../../../environments/environment"; @Injectable() export class AffiliationService { - + private affiliationsSubject: BehaviorSubject = new BehaviorSubject([]); - + constructor(private http: HttpClient) { } - - public initAffiliations(properties: EnvProperties, url: string): void { - this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url). - subscribe((affiliations) => { - this.affiliationsSubject.next(affiliations); - }); + + public initAffiliations(communityId: string): void { + let url = properties.communityAPI + communityId + "/organizations"; + this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe((affiliations) => { + this.affiliationsSubject.next(affiliations); + }, + error => { + this.affiliationsSubject.error(error); + }); } - + public get affiliations(): Observable { return this.affiliationsSubject.asObservable(); } - + public updateAffiliation(url: string, affiliation: Affiliation) { - let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'}); + let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'}); return this.http.post(url, JSON.stringify(affiliation), {headers: headers}); } - + public deleteAffiliation(url: string, id: string) { - let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'}); - return this.http.request('delete', url, { body: id, headers: headers}) + let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'}); + return this.http.request('delete', url, {body: id, headers: headers}) } - + } diff --git a/connect/communities/communities.service.ts b/connect/communities/communities.service.ts index b2613fd6..9fff177f 100644 --- a/connect/communities/communities.service.ts +++ b/connect/communities/communities.service.ts @@ -12,12 +12,14 @@ export class CommunitiesService { public communities: BehaviorSubject = null; constructor(private http: HttpClient) { - this.communities = new BehaviorSubject(null); + this.communities = new BehaviorSubject([]); } updateCommunities(properties: EnvProperties, url: string) { this.getCommunities(properties, url).subscribe(res => { - this.communities.next(res); + this.communities.next(res); + }, error => { + this.communities.error(error); }) } @@ -27,7 +29,6 @@ export class CommunitiesService { getCommunities(properties: EnvProperties, url: string) { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - //.map(res => res.json()) .pipe(map(res => this.parseCommunities(res))); } diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index 6f76e882..d60091f7 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -22,7 +22,7 @@ export class CommunityService { resolve(); }, error => { - this.community.next(null); + this.community.error(error); resolve(); }) }); @@ -46,7 +46,6 @@ export class CommunityService { */ getCommunity(properties: EnvProperties, url: string) { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - //.map(res => res.json()) .pipe(map(res => this.parseCommunity(res))); } diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 1c0dedbb..8d85468c 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -18,29 +18,20 @@ export class UserManagementService { constructor(private http: HttpClient, private router: Router) { this.promise = new Promise((resolve => { - if(true) { - const token = COOKIE.getCookie('AccessToken'); - if (!token) { - this.getUserInfoSubject.next(null); - resolve(); - } else { - this.http.get(properties.userInfoUrl + token).pipe(map(userInfo => { - return this.parseUserInfo(userInfo); - })).pipe(timeout(3000), catchError(() => { - return of(null); - })).subscribe(user => { - this.getUserInfoSubject.next(user); - resolve(); - }); - } - } else { - if(!COOKIE.getCookie('AccessToken')) { - this.getUserInfoSubject.next(null); - resolve(); - } else { - this.updateUserInfo(resolve); - } - } + const token = COOKIE.getCookie('AccessToken'); + if (!token) { + this.getUserInfoSubject.next(null); + resolve(); + } else { + this.http.get(properties.userInfoUrl + token).pipe(map(userInfo => { + return this.parseUserInfo(userInfo); + })).pipe(timeout(3000), catchError(() => { + return of(null); + })).subscribe(user => { + this.getUserInfoSubject.next(user); + resolve(); + }); + } })); this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { @@ -53,7 +44,7 @@ export class UserManagementService { } public getUserInfo(subject: boolean = true): Observable { - if(subject) { + if (subject) { return this.getUserInfoSubject.asObservable(); } else { return from(this.getUserInfoAsync()); @@ -67,7 +58,7 @@ export class UserManagementService { return of(null); })).subscribe(user => { this.getUserInfoSubject.next(user); - if(resolve) { + if (resolve) { resolve(); } }); diff --git a/utils/configuration/configuration.service.ts b/utils/configuration/configuration.service.ts index 9c624b23..f308c330 100644 --- a/utils/configuration/configuration.service.ts +++ b/utils/configuration/configuration.service.ts @@ -49,7 +49,7 @@ export class ConfigurationService { resolve(); }, error => { - this.communityInformation.next(null); + this.communityInformation.error(error); resolve(); }); })); diff --git a/utils/staticAutoComplete/ISVocabularies.service.ts b/utils/staticAutoComplete/ISVocabularies.service.ts index 17b6b2dd..d4f6d6e5 100644 --- a/utils/staticAutoComplete/ISVocabularies.service.ts +++ b/utils/staticAutoComplete/ISVocabularies.service.ts @@ -82,6 +82,9 @@ export class ISVocabulariesService { vocabularyRes => { this.vocabularies.get(vocabularyName).next(vocabularyRes); resolve(); + }, error => { + this.vocabularies.get(vocabularyName).next(null); + resolve(); } ); }); diff --git a/utils/staticAutoComplete/staticAutoComplete.component.ts b/utils/staticAutoComplete/staticAutoComplete.component.ts index 6f02c98d..c1e18331 100644 --- a/utils/staticAutoComplete/staticAutoComplete.component.ts +++ b/utils/staticAutoComplete/staticAutoComplete.component.ts @@ -100,14 +100,13 @@ export class StaticAutoCompleteComponent implements OnChanges{ // this.afterListFetchedActions(); this.sub = this._vocabulariesService.getVocabularyByType(this.vocabularyId, this.entityName, this.properties).subscribe( data => { - this.list = (this.vocabularyId=="type" && this.entityName == "result" && data.length == 2)?data[0].concat(data[1]):data; - this.afterListFetchedActions(); - - }, - err => { - //console.log(err); - this.handleError("Error getting vocabulary with id: "+this.vocabularyId+" for "+this.entityName, err); - this.warningMessage = "An Error occured..." + if(data) { + this.list = (this.vocabularyId == "type" && this.entityName == "result" && data.length == 2) ? data[0].concat(data[1]) : data; + this.afterListFetchedActions(); + } else { + this.handleError("Error getting vocabulary with id: "+this.vocabularyId+" for "+this.entityName); + this.warningMessage = "An Error occurred..." + } } ); }else if(this.fieldName && this.entityName){ @@ -308,7 +307,7 @@ export class StaticAutoCompleteComponent implements OnChanges{ } } - private handleError(message: string, error) { + private handleError(message: string, error = null) { console.error("Static Autocomplete (component): "+message, error); } } diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index 4f7b72ba..593045bb 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -16,6 +16,8 @@ export class SubscribeService { let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/"; this.http.get(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => { this.isSubscribedSubject.next(isSubscribed); + }, error => { + this.isSubscribedSubject.error(error); }); }