diff --git a/src/app/monitor/monitor.component.ts b/src/app/monitor/monitor.component.ts index efc31e4..0f733ce 100644 --- a/src/app/monitor/monitor.component.ts +++ b/src/app/monitor/monitor.component.ts @@ -311,7 +311,7 @@ export class MonitorComponent implements OnInit, OnDestroy, IDeactivateComponent }); urls.forEach((indexes, pair) => { pair = JSON.parse(pair); - this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => { + this.statisticsService.getNumbers(pair[0], IndicatorUtils.getNumberUrl(this.stakeholder, pair[1])).subscribe(response => { indexes.forEach(([i, j]) => { let result = JSON.parse(JSON.stringify(response)); this.activeSubCategory.numbers[i].indicators[j].indicatorPaths[0].jsonPath.forEach(jsonPath => { diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index d780fcd..3724efd 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -408,6 +408,24 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV source: this.fb.control(source, Validators.required) } )); + + for(let index = 0; index < this.numberIndicatorPaths.length; index++) { + this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { + if (this.numberIndicatorPaths.at(index).get('url').valid) { + let indicatorPath: IndicatorPath = this.indicatorUtils.parseNumberIndicatortUrl(this.numberIndicatorPaths.at(index).get('source').value, value, this.stakeholder); + // if(indicatorPath.url.indexOf("index_id") ==-1 && indicatorPath.url.indexOf("index_name") ==-1 && (indicatorPath.url).indexOf("index_shortName") ==-1 ){ + // + // }else { + // this.urlParameterizedMessage = ""; + // } + if(value != indicatorPath.url) { + (this.numberIndicatorPaths.at(index) as FormGroup).get('url').setValue( indicatorPath.url); + } + this.indicator.indicatorPaths[index] = indicatorPath; + } + }) + ); + } } public addChartIndicatorPath(value: string = '', parameters: FormArray = new FormArray([]), disableUrl: boolean = false, type:string=null) { @@ -658,7 +676,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } public get isAdministrator(): boolean { - return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user) + return Session.isPortalAdministrator(this.user); + // return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user) } refreshIndicator() { diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 61c46ed..e161e9c 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -261,7 +261,20 @@ export class IndicatorUtils { } return indicatorPath.url + encodeURIComponent(replacedUrl); } + public static getNumberUrl(stakeholder:Stakeholder,url:string): string { + let replacedUrl = url; + if(url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){ + replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id)) + } + if(url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){ + replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name)) + } + if(url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){ + replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName)) + } + return replacedUrl; + } generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[]): Indicator { let indicator: Indicator = new Indicator(form.name, form.description, 'chart', form.width, form.isActive, form.isPublic, indicatorPaths, form.defaultId); @@ -277,7 +290,25 @@ export class IndicatorUtils { }); return indicator; } - + parseNumberIndicatortUrl(source: SourceType, url: string, stakeholder:Stakeholder): IndicatorPath { + let indicatorPath = new IndicatorPath(null, source, url, null, []); + try { + if (url.indexOf(encodeURIComponent(stakeholder.index_id)) !== -1) { + url = url.split(encodeURIComponent(stakeholder.index_id)).join(ChartHelper.prefix + "index_id" + ChartHelper.suffix); + } + if (url.indexOf(encodeURIComponent(stakeholder.index_name)) !== -1) { + url = url.split(encodeURIComponent(stakeholder.index_name)).join(ChartHelper.prefix + "index_name" + ChartHelper.suffix); + } + if (url.indexOf(encodeURIComponent(stakeholder.index_shortName)) !== -1) { + url = url.split(encodeURIComponent(stakeholder.index_shortName)).join(ChartHelper.prefix + "index_shortName" + ChartHelper.suffix); + } + indicatorPath.url = url; + } + catch(e){ + console.error(e); + } + return indicatorPath; + } generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath { let indicatorPath = new IndicatorPath(type, source, "", "", []); try { @@ -502,7 +533,7 @@ export class IndicatorUtils { } private extractDataTitle(obj, indicatorPath: IndicatorPath) { let index = 0; - if(obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){ + if(!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){ return; } for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {