[Library | Trunk]: Community Service check logoUrl if isUpload

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60436 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-02-16 10:25:23 +00:00
parent ed5f31cb7b
commit e8b37fc533
2 changed files with 22 additions and 9 deletions

View File

@ -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<any>((resolve, reject) => {
this.sub = this.http.get<CommunityInfo>(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);
}
}

View File

@ -11,6 +11,7 @@ export class CommunityInfo {
subjects: string[];
status:string;
zenodoCommunity:string;
isUpload: boolean;
isSubscribed: boolean;
isManager: boolean;
}