diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index 322dd87..0d286aa 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -454,7 +454,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } public removeJsonPath(i: number, j: number) { - if(this.getJsonPath(i).enabled) { + if (this.getJsonPath(i).enabled) { this.getJsonPath(i).removeAt(j); } } @@ -475,7 +475,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV setTimeout(() => { if (this.indicator.defaultId === null) { this.getJsonPath(index).enable(); - if(dirty) { + if (dirty) { this.getJsonPath(index).markAsDirty(); } } @@ -542,67 +542,66 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV source: this.fb.control(source, Validators.required) } )); - for (let index = 0; index < this.numberIndicatorPaths.length; index++) { - if (this.numberIndicatorPaths.at(index).get('url').valid) { - this.validateJsonPath(index); - } - if (this.indicator.defaultId === null) { - this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { - this.numberIndicatorPaths.at(index).get('result').setValue(null); - if (this.numberIndicatorPaths.at(index).get('url').valid) { - let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(value))); - if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1) - || (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) { - // default profile - if (this.stakeholder.defaultId == null) { - this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly." - } else { - this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder." - } + let index = this.numberIndicatorPaths.length - 1; + if (this.numberIndicatorPaths.at(index).get('url').valid) { + this.validateJsonPath(index); + } + if (this.indicator.defaultId === null) { + this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { + this.numberIndicatorPaths.at(index).get('result').setValue(null); + if (this.numberIndicatorPaths.at(index).get('url').valid) { + let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(value))); + if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1) + || (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) { + // default profile + if (this.stakeholder.defaultId == null) { + this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly." } else { - this.urlParameterizedMessage = null; - } - if (this.indicator.indicatorPaths[index]) { - this.indicator.indicatorPaths[index] = indicatorPath; - } else { - this.indicator.indicatorPaths.push(indicatorPath); - } - if (indicatorPath.source) { - this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source); - } - if (indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length == 1) { - let paths = indicatorPath.jsonPath; - for (let i = 0; i < paths.length; i++) { - if (i == this.getJsonPath(index).length) { - this.getJsonPath(index).push(this.fb.control('', Validators.required)); - } - } - this.getJsonPath(index).setValue(paths) + this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder." } } else { this.urlParameterizedMessage = null; } - }) - ); - - this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => { if (this.indicator.indicatorPaths[index]) { - this.indicator.indicatorPaths[index].jsonPath = value; + this.indicator.indicatorPaths[index] = indicatorPath; + } else { + this.indicator.indicatorPaths.push(indicatorPath); } - this.numberIndicatorPaths.at(index).get('result').setValue(null); - }) - ); - this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => { - if (this.indicator.indicatorPaths[index]) { - this.indicator.indicatorPaths[index].source = value; + if (indicatorPath.source) { + this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source); } - }) - ); - } else { - this.numberIndicatorPaths.at(index).get('url').disable(); - this.numberIndicatorPaths.at(index).get('jsonPath').disable(); - this.numberIndicatorPaths.at(index).get('source').disable(); - } + if (indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length == 1) { + let paths = indicatorPath.jsonPath; + for (let i = 0; i < paths.length; i++) { + if (i == this.getJsonPath(index).length) { + this.getJsonPath(index).push(this.fb.control('', Validators.required)); + } + } + this.getJsonPath(index).setValue(paths) + } + } else { + this.urlParameterizedMessage = null; + } + }) + ); + + this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => { + if (this.indicator.indicatorPaths[index]) { + this.indicator.indicatorPaths[index].jsonPath = value; + } + this.numberIndicatorPaths.at(index).get('result').setValue(null); + }) + ); + this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => { + if (this.indicator.indicatorPaths[index]) { + this.indicator.indicatorPaths[index].source = value; + } + }) + ); + } else { + this.numberIndicatorPaths.at(index).get('url').disable(); + this.numberIndicatorPaths.at(index).get('jsonPath').disable(); + this.numberIndicatorPaths.at(index).get('source').disable(); } } @@ -613,41 +612,37 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV type: this.fb.control(type) } )); + let index = this.chartIndicatorPaths.length - 1; if (disableUrl) { - for (let index = 0; index < this.chartIndicatorPaths.length; index++) { - this.chartIndicatorPaths.at(index).get('url').disable(); - } + this.chartIndicatorPaths.at(index).get('url').disable(); } else { - for (let index = 0; index < this.chartIndicatorPaths.length; index++) { - this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { - if (this.chartIndicatorPaths.at(index).get('url').valid) { - let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(value), value, this.chartIndicatorPaths.at(index).get('type').value, this.stakeholder); - if (indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1) { - // default profile - if (this.stakeholder.defaultId == null) { - this.urlParameterizedMessage = "This chart couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly." - } else { - this.urlParameterizedMessage = "This chart couldn't be generated properly. Please make sure chart data is for the current stakeholder." - } - } else { - this.urlParameterizedMessage = null; - } - (this.chartIndicatorPaths.at(index) as FormGroup).get('type').setValue(indicatorPath.type); - let parameters = this.getParametersAsFormArray(indicatorPath); - (this.chartIndicatorPaths.at(index) as FormGroup).setControl('parameters', parameters); - if (!this.indicator.indicatorPaths[index]) { - this.indicator.indicatorPaths[index] = indicatorPath; - this.indicator.indicatorPaths[index].safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath); - } else { - indicatorPath.safeResourceUrl = this.indicator.indicatorPaths[index].safeResourceUrl; - this.indicator.indicatorPaths[index] = indicatorPath; - } + this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { + if (this.chartIndicatorPaths.at(index).get('url').valid) { + let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(value), value, this.chartIndicatorPaths.at(index).get('type').value, this.stakeholder); + if (indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1) { + // default profile + if (this.stakeholder.defaultId == null) { + this.urlParameterizedMessage = "This chart couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly." } else { - this.urlParameterizedMessage = null; + this.urlParameterizedMessage = "This chart couldn't be generated properly. Please make sure chart data is for the current stakeholder." } - }) - ); - } + } else { + this.urlParameterizedMessage = null; + } + (this.chartIndicatorPaths.at(index) as FormGroup).get('type').setValue(indicatorPath.type); + let parameters = this.getParametersAsFormArray(indicatorPath); + (this.chartIndicatorPaths.at(index) as FormGroup).setControl('parameters', parameters); + if (!this.indicator.indicatorPaths[index]) { + this.indicator.indicatorPaths[index] = indicatorPath; + this.indicator.indicatorPaths[index].safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath); + } else { + indicatorPath.safeResourceUrl = this.indicator.indicatorPaths[index].safeResourceUrl; + this.indicator.indicatorPaths[index] = indicatorPath; + } + } else { + this.urlParameterizedMessage = null; + } + })); } }