diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index 348d1e90..4283785c 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -6,6 +6,8 @@ import {map} from "rxjs/operators"; import {BehaviorSubject, from, Subscriber} from "rxjs"; import {properties} from "../../../../environments/environment"; import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {Stakeholder} from "../../monitor/entities/stakeholder"; +import {StringUtils} from "../../utils/string-utils.class"; @Injectable({providedIn: 'root'}) export class CommunityService { @@ -60,10 +62,6 @@ export class CommunityService { this.community.next(community); } - private formalize(element: any) { - return HelperFunctions.copy(element); - } - getCommunityByState(properties: EnvProperties, url: string) { return from(this.getCommunityByStateAsync(properties, url)); } @@ -74,11 +72,11 @@ export class CommunityService { } // TODO remove NEW from function names - getCommunityNew(communityId: string) { - if(!this.community.value || this.community.value.communityId !== communityId) { + getCommunityNew(communityId: string, refresh = false) { + if(!this.community.value || this.community.value.communityId !== communityId || refresh) { this.promise = new Promise((resolve, reject) => { this.sub = this.http.get(properties.communityAPI + communityId) - .pipe(map(community => this.formalize(this.parseCommunity(community)))).subscribe(community => { + .pipe(map(community => this.parseCommunity(community))).subscribe(community => { this.community.next(community); resolve(); }, @@ -97,10 +95,24 @@ export class CommunityService { return this.community.getValue(); } + private checkIsUpload(response: CommunityInfo | CommunityInfo[]): any | any[] { + if(Array.isArray(response)) { + response.forEach(value => { + value.isUpload = value.logoUrl && !StringUtils.isValidUrl(value.logoUrl); + }); + } else { + response.isUpload = response.logoUrl && !StringUtils.isValidUrl(response.logoUrl); + } + return response; + } + + updateCommunity(url: string, community: any) { //const headers = new Headers({'Content-Type': 'application/json'}); //const options = new RequestOptions({headers: headers}); - + if(!community.logoUrl) { + community.logoUrl = ''; + } const options = { headers: new HttpHeaders({ 'Content-Type': 'application/json', @@ -246,7 +258,7 @@ export class CommunityService { community.subjects[i] = subject; } } - return community; + return this.checkIsUpload(community); } } diff --git a/connect/community/communityInfo.ts b/connect/community/communityInfo.ts index 20595e7b..38ec9a22 100644 --- a/connect/community/communityInfo.ts +++ b/connect/community/communityInfo.ts @@ -11,6 +11,7 @@ export class CommunityInfo { subjects: string[]; status:string; zenodoCommunity:string; + isUpload: boolean; isSubscribed: boolean; isManager: boolean; }