[Library | Trunk]: Add on error for some subjects calls.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59245 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-08-11 12:16:50 +00:00
parent aa54f9460e
commit 07783fa92e
8 changed files with 54 additions and 56 deletions

View File

@ -2,7 +2,7 @@ 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 {
@ -12,10 +12,13 @@ export class AffiliationService {
constructor(private http: HttpClient) {
}
public initAffiliations(properties: EnvProperties, url: string): void {
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
subscribe((affiliations) => {
public initAffiliations(communityId: string): void {
let url = properties.communityAPI + communityId + "/organizations";
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe((affiliations) => {
this.affiliationsSubject.next(affiliations);
},
error => {
this.affiliationsSubject.error(error);
});
}
@ -24,13 +27,13 @@ export class AffiliationService {
}
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<Affiliation>(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})
}
}

View File

@ -12,12 +12,14 @@ export class CommunitiesService {
public communities: BehaviorSubject<CommunityInfo[]> = 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);
}, 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 => <any> res.json())
.pipe(map(res => this.parseCommunities(res)));
}

View File

@ -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 => <any> res.json())
.pipe(map(res => this.parseCommunity(res)));
}

View File

@ -18,7 +18,6 @@ export class UserManagementService {
constructor(private http: HttpClient,
private router: Router) {
this.promise = new Promise<any>((resolve => {
if(true) {
const token = COOKIE.getCookie('AccessToken');
if (!token) {
this.getUserInfoSubject.next(null);
@ -33,14 +32,6 @@ export class UserManagementService {
resolve();
});
}
} else {
if(!COOKIE.getCookie('AccessToken')) {
this.getUserInfoSubject.next(null);
resolve();
} else {
this.updateUserInfo(resolve);
}
}
}));
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
@ -53,7 +44,7 @@ export class UserManagementService {
}
public getUserInfo(subject: boolean = true): Observable<User> {
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();
}
});

View File

@ -49,7 +49,7 @@ export class ConfigurationService {
resolve();
},
error => {
this.communityInformation.next(null);
this.communityInformation.error(error);
resolve();
});
}));

View File

@ -82,6 +82,9 @@ export class ISVocabulariesService {
vocabularyRes => {
this.vocabularies.get(vocabularyName).next(vocabularyRes);
resolve();
}, error => {
this.vocabularies.get(vocabularyName).next(null);
resolve();
}
);
});

View File

@ -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;
if(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..."
} 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);
}
}

View File

@ -16,6 +16,8 @@ export class SubscribeService {
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
this.isSubscribedSubject.next(isSubscribed);
}, error => {
this.isSubscribedSubject.error(error);
});
}