diff --git a/monitor/entities/stakeholder.ts b/monitor/entities/stakeholder.ts index 474456c4..49c8e755 100644 --- a/monitor/entities/stakeholder.ts +++ b/monitor/entities/stakeholder.ts @@ -1,6 +1,6 @@ import {SafeResourceUrl} from "@angular/platform-browser"; -import {properties} from "../../../../environments/environment"; import {Session, User} from "../../login/utils/helper.class"; +import {StringUtils} from "../../utils/string-utils.class"; export const ChartHelper = { prefix: "((__", @@ -52,6 +52,17 @@ export class Stakeholder { this.description = description; this.topics = []; } + + static checkIsUpload(response: Stakeholder | Stakeholder[]): 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; + } } export class StakeholderInfo extends Stakeholder { diff --git a/monitor/monitor-indicator-stakeholder-base.component.ts b/monitor/monitor-indicator-stakeholder-base.component.ts index 9a7a3648..ee7bb511 100644 --- a/monitor/monitor-indicator-stakeholder-base.component.ts +++ b/monitor/monitor-indicator-stakeholder-base.component.ts @@ -208,6 +208,8 @@ export abstract class MonitorIndicatorStakeholderBaseComponent extends Indicator } protected setIndicators() { + this.activeSubCategory.numbers = this.activeSubCategory.numbers.filter(section => section.indicators.length > 0); + this.activeSubCategory.charts = this.activeSubCategory.charts.filter(section => section.indicators.length > 0); this.periodFilter.selectedFromAndToValues = (this.periodFilter.selectedFromValue || this.periodFilter.selectedToValue ? ((this.periodFilter.selectedFromValue && !this.periodFilter.selectedToValue ? "From " : "") + (!this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? "Until " : "") + (this.periodFilter.selectedFromValue ? this.periodFilter.selectedFromValue : "") + (this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? " - " : "") + (this.periodFilter.selectedToValue ? this.periodFilter.selectedToValue : "")) : ""); //clear numbers when filters change diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts index 37fd7a3c..3f0f3a11 100644 --- a/monitor/services/stakeholder.service.ts +++ b/monitor/services/stakeholder.service.ts @@ -6,7 +6,6 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class"; import {map} from "rxjs/operators"; import {properties} from "../../../../environments/environment"; import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; -import {StringUtils} from "../../utils/string-utils.class"; export interface Reorder { action: 'moved' | 'added' | 'removed', @@ -41,7 +40,7 @@ export class StakeholderService { if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias || shouldUpdate) { this.promise = new Promise((resolve, reject) => { this.sub = this.http.get(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => { - return this.formalize(this.checkIsUpload(stakeholder)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder)); })).subscribe(stakeholder => { this.stakeholderSubject.next(stakeholder); resolve(); @@ -53,23 +52,24 @@ export class StakeholderService { } return from(this.getStakeholderAsync()); } - getResearcherStakeholder( orcid, name, results, shouldUpdate: boolean = false): Observable { + + getResearcherStakeholder(orcid, name, results, shouldUpdate: boolean = false): Observable { if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== orcid || shouldUpdate) { this.promise = new Promise((resolve, reject) => { this.sub = this.http.get(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent("researcher"), CustomOptions.registryOptions()).pipe(map(stakeholder => { - return this.formalize(this.checkIsUpload(stakeholder)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder)); })).subscribe(stakeholder => { stakeholder.index_id = orcid; stakeholder.index_name = name; stakeholder.name = name; stakeholder.alias = orcid; - if(results <7 && stakeholder.topics[0]?.categories[0]?.subCategories[0]){ - stakeholder.topics[0].categories[0].subCategories[0].charts=[]; // keep only numbers - charts wont show much anyway + if (results < 7 && stakeholder.topics[0]?.categories[0]?.subCategories[0]) { + stakeholder.topics[0].categories[0].subCategories[0].charts = []; // keep only numbers - charts wont show much anyway } this.stakeholderSubject.next(stakeholder); resolve(); }, error => { - let stakeholder = new Stakeholder(null,"researcher", orcid,name,name,orcid,"PUBLIC", null, null,""); + let stakeholder = new Stakeholder(null, "researcher", orcid, name, name, orcid, "PUBLIC", null, null, ""); this.stakeholderSubject.next(stakeholder); resolve(); }); @@ -89,25 +89,25 @@ export class StakeholderService { getAlias(url: string): Observable { return this.http.get(url + '/stakeholder/alias', CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(stakeholders); + return HelperFunctions.copy(stakeholders); })); } getStakeholders(url: string, type: string = null, defaultId: string = null): Observable<(Stakeholder & StakeholderInfo)[]> { return this.http.get(url + '/stakeholder' + ((type) ? ('?type=' + type) : '') + ((!type && defaultId) ? ('?defaultId=' + defaultId) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(this.checkIsUpload(stakeholders)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders)); })); } getMyStakeholders(url: string, type: string = null): Observable<(Stakeholder & StakeholderInfo)[]> { return this.http.get(url + '/my-stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(this.checkIsUpload(stakeholders)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders)); })); } getDefaultStakeholders(url: string, type: string = null): Observable { return this.http.get(url + '/stakeholder/default' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { - return this.formalize(this.checkIsUpload(stakeholders)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders)); })); } @@ -116,7 +116,7 @@ export class StakeholderService { stakeholder.alias = stakeholder.alias.slice(1); } return this.http.post(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => { - return this.formalize(this.checkIsUpload(stakeholder)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder)); })); } @@ -130,11 +130,11 @@ export class StakeholderService { } path = HelperFunctions.encodeArray(path); return this.http.post(url + ((path.length > 0) ? '/' : '') + path.join('/') + - '/save', element, CustomOptions.registryOptions()).pipe(map(element => { + '/save', element, CustomOptions.registryOptions()).pipe(map(element => { if (path.length === 0) { - return this.formalize(this.checkIsUpload(element)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(element)); } else { - return this.formalize(element); + return HelperFunctions.copy(element); } })); } @@ -142,11 +142,11 @@ export class StakeholderService { saveBulkElements(url: string, indicators, path: string[] = []): Observable { path = HelperFunctions.encodeArray(path); return this.http.post(url + ((path.length > 0) ? '/' : '') + path.join('/') + - '/save-bulk', indicators, CustomOptions.registryOptions()).pipe(map(element => { + '/save-bulk', indicators, CustomOptions.registryOptions()).pipe(map(element => { if (path.length === 0) { - return this.formalize(this.checkIsUpload(element)); + return HelperFunctions.copy(Stakeholder.checkIsUpload(element)); } else { - return this.formalize(element); + return HelperFunctions.copy(element); } })); } @@ -154,8 +154,8 @@ export class StakeholderService { saveSection(url: string, element: any, path: string[] = [], index: number = -1): Observable
{ path = HelperFunctions.encodeArray(path); return this.http.post
(url + ((path.length > 0) ? '/' : '') + path.join('/') + - '/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => { - return this.formalize(element); + '/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => { + return HelperFunctions.copy(element); })); } @@ -176,7 +176,7 @@ export class StakeholderService { reorderIndicators(url: string, path: string[], reorder: Reorder, type: string = 'chart'): Observable { path = HelperFunctions.encodeArray(path); return this.http.post(url + '/' + path.join('/') + '/' + type + '/reorder', reorder, CustomOptions.registryOptions()).pipe(map(indicators => { - return this.formalize(indicators); + return HelperFunctions.copy(indicators); })); } @@ -187,19 +187,4 @@ export class StakeholderService { setStakeholder(stakeholder: Stakeholder) { this.stakeholderSubject.next(stakeholder); } - - private checkIsUpload(response: Stakeholder | Stakeholder[]): 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; - } - - private formalize(element: any) { - return HelperFunctions.copy(element); - } }