[Monitor Dashboard | Trunk]: Add indicator path remove for loop

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@60234 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2021-01-14 10:02:55 +00:00
parent ecba49c727
commit 5db6152749
1 changed files with 81 additions and 86 deletions

View File

@ -454,7 +454,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} }
public removeJsonPath(i: number, j: number) { public removeJsonPath(i: number, j: number) {
if(this.getJsonPath(i).enabled) { if (this.getJsonPath(i).enabled) {
this.getJsonPath(i).removeAt(j); this.getJsonPath(i).removeAt(j);
} }
} }
@ -475,7 +475,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
setTimeout(() => { setTimeout(() => {
if (this.indicator.defaultId === null) { if (this.indicator.defaultId === null) {
this.getJsonPath(index).enable(); this.getJsonPath(index).enable();
if(dirty) { if (dirty) {
this.getJsonPath(index).markAsDirty(); this.getJsonPath(index).markAsDirty();
} }
} }
@ -542,67 +542,66 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
source: this.fb.control(source, Validators.required) source: this.fb.control(source, Validators.required)
} }
)); ));
for (let index = 0; index < this.numberIndicatorPaths.length; index++) { let index = this.numberIndicatorPaths.length - 1;
if (this.numberIndicatorPaths.at(index).get('url').valid) { if (this.numberIndicatorPaths.at(index).get('url').valid) {
this.validateJsonPath(index); this.validateJsonPath(index);
} }
if (this.indicator.defaultId === null) { if (this.indicator.defaultId === null) {
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
this.numberIndicatorPaths.at(index).get('result').setValue(null); this.numberIndicatorPaths.at(index).get('result').setValue(null);
if (this.numberIndicatorPaths.at(index).get('url').valid) { 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))); 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) 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)) { || (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) {
// default profile // default profile
if (this.stakeholder.defaultId == null) { 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." 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."
}
} else { } else {
this.urlParameterizedMessage = null; this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder."
}
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)
} }
} else { } else {
this.urlParameterizedMessage = null; this.urlParameterizedMessage = null;
} }
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) { 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); if (indicatorPath.source) {
}) this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
);
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.jsonPath.length > 1 && this.getJsonPath(index).length == 1) {
); let paths = indicatorPath.jsonPath;
} else { for (let i = 0; i < paths.length; i++) {
this.numberIndicatorPaths.at(index).get('url').disable(); if (i == this.getJsonPath(index).length) {
this.numberIndicatorPaths.at(index).get('jsonPath').disable(); this.getJsonPath(index).push(this.fb.control('', Validators.required));
this.numberIndicatorPaths.at(index).get('source').disable(); }
} }
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) type: this.fb.control(type)
} }
)); ));
let index = this.chartIndicatorPaths.length - 1;
if (disableUrl) { 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 { } else {
for (let index = 0; index < this.chartIndicatorPaths.length; index++) { this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { if (this.chartIndicatorPaths.at(index).get('url').valid) {
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);
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) {
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
// default profile if (this.stakeholder.defaultId == null) {
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."
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;
}
} else { } 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;
}
}));
} }
} }