diff --git a/monitor-admin/topic/indicators.component.ts b/monitor-admin/topic/indicators.component.ts
index 30343944..1abcfa4d 100644
--- a/monitor-admin/topic/indicators.component.ts
+++ b/monitor-admin/topic/indicators.component.ts
@@ -504,16 +504,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.numberIndicatorPaths.at(index).get('result').setValue(null);
if (this.numberIndicatorPaths.at(index).get('url').valid) {
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.indicatorUtils.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.indicatorUtils.numberSources.get(this.indicatorUtils.getNumberSource(value)));
- if (!this.isStakeholderParametersValid(indicatorPath)) {
- // 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."
- }
- } else {
- this.urlParameterizedMessage = null;
- }
this.checkForSchemaEnhancements(this.numberIndicatorPaths.at(index).get('url').value);
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
@@ -574,16 +564,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
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.indicatorUtils.getChartSource(value), value, this.chartIndicatorPaths.at(index).get('type').value, this.stakeholder);
- if (!this.isStakeholderParametersValid(indicatorPath)) {
- // 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.checkForSchemaEnhancements(this.chartIndicatorPaths.at(index).get('url').value);
(this.chartIndicatorPaths.at(index) as UntypedFormGroup).get('type').setValue(indicatorPath.type);
(this.chartIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', this.getParametersAsFormArray(indicatorPath));
@@ -601,12 +581,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}
}
- private isStakeholderParametersValid(indicatorPath: IndicatorPath) {
- return !((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));
-
- }
-
private getJsonPathAsFormArray(indicatorPath: IndicatorPath): UntypedFormArray {
let jsonPath = this.fb.array([]);
if (indicatorPath.jsonPath) {
@@ -1159,24 +1133,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}));
}
- // deleteNumberSectionOpen(section: Section, index: number) {
- // this.section = section;
- // this.index = index;
- // this.deleteNumberSectionModal.alertTitle = 'Delete Section';
- // this.deleteNumberSectionModal.cancelButtonText = 'No';
- // this.deleteNumberSectionModal.okButtonText = 'Yes';
- // this.deleteNumberSectionModal.open();
- // }
- //
- // deleteChartSectionOpen(section: Section, index: number) {
- // this.section = section;
- // this.index = index;
- // this.deleteChartSectionModal.alertTitle = 'Delete Section';
- // this.deleteChartSectionModal.cancelButtonText = 'No';
- // this.deleteChartSectionModal.okButtonText = 'Yes';
- // this.deleteChartSectionModal.open();
- // }
-
deleteSectionOpen(section: Section, index: number, type: IndicatorType, childrenAction: string = null) {
if (!this.editing && !section.defaultId) {
this.sectionTypeToDelete = type;
@@ -1256,11 +1212,20 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
return charts;
}
- importIndicatorsAndSave(charts: any[]) {
+ importIndicatorsAndSave(stakeholder: Stakeholder, charts: any[]) {
let sectionsToSave: Section[] = [];
let countIndicators = 0;
+ if(stakeholder.type !== this.stakeholder.type) {
+ UIkit.notification("The type of this profile is not the same with the file's one!", {
+ status: 'warning',
+ timeout: 6000,
+ pos: 'bottom-right'
+ });
+ this.editing = false;
+ this.importLoading = false;
+ return;
+ }
// name description additionalDescription, height, width, visibility
- let noValidParams = 0;
let duplicates = 0;
charts = this.migrateFromOldImportJsonFile(charts);
for (let chart of charts) {
@@ -1296,7 +1261,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}
if (chart.type == "chart") {
- indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.indicatorUtils.getChartSource(chart.url), chart.url, chart.type, this.stakeholder);
+ indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.indicatorUtils.getChartSource(chart.url), chart.url, chart.type, stakeholder);
for (let section of this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].charts) {
for (let chart of section.indicators) {
if (JSON.stringify(chart.indicatorPaths[0].chartObject) == JSON.stringify(indicatorPath.chartObject)) {
@@ -1304,10 +1269,9 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
exists = true;
}
}
-
}
} else if (chart.type == "number") {
- indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.indicatorUtils.getNumberSource(chart.url), chart.url, this.stakeholder,
+ indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.indicatorUtils.getNumberSource(chart.url), chart.url, stakeholder,
chart.jsonPath, this.indicatorUtils.numberSources.get(this.indicatorUtils.getNumberSource(chart.url)));
for (let section of this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers) {
for (let chart of section.indicators) {
@@ -1316,20 +1280,14 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
exists = true;
}
}
-
}
}
- if (!this.isStakeholderParametersValid(indicatorPath)) {
- noValidParams++;
- }
if (!exists) {
let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height, this.showVisibility?"RESTRICTED":this.stakeholderUtils.defaultValue(this.stakeholderUtils.visibilities), [indicatorPath]);
sectionsToSave[chart['sectionIndex']].indicators.push(i);
countIndicators++;
}
-
}
-
if (duplicates > 0) {
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
status: 'warning',
@@ -1337,19 +1295,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
pos: 'bottom-right'
});
}
- if (noValidParams > 0 && !(this.stakeholder.type == 'country')) {
- let noValidMessage = "Some indicators couldn't be generated properly. Please make sure chart data is for the current stakeholder.";
- if (this.stakeholder.defaultId == null) {
- noValidMessage = "Some indicators couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly.";
- }
- UIkit.notification(noValidMessage, {
- status: 'danger',
- timeout: 6000,
- pos: 'bottom-right'
- });
- this.editing = false;
- this.importLoading = false;
- } else if (sectionsToSave.length > 0 && countIndicators > 0) {
+ if (sectionsToSave.length > 0 && countIndicators > 0) {
this.saveIndicators(sectionsToSave.filter(section => !!section));
}
if (sectionsToSave.length == 0 || countIndicators == 0) {
@@ -1408,8 +1354,11 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
let topic = this.stakeholder ? this.stakeholder.topics[this.topicIndex] : null;
let category = topic ? topic.categories[this.categoryIndex] : null;
let subCategory = category ? category.subCategories[subcategoryIndex] : null;
-
- var jsonFileUrl = window.URL.createObjectURL(new Blob([JSON.stringify(indicators)], {type: 'application/json'}));
+ let json = {
+ stakeholder: this.stakeholder,
+ indicators: indicators
+ }
+ var jsonFileUrl = window.URL.createObjectURL(new Blob([JSON.stringify(json)], {type: 'application/json'}));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
a.setAttribute('style', 'display: none');
@@ -1456,11 +1405,17 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}
this.makeFileRequest(this.properties.utilsService + '/upload?type=json', [], this.filesToUpload).then(async (result: string) => {
-
- let json_result = JSON.parse(result);
-
+ let json = JSON.parse(result);
// validate file
- if (!json_result || json_result.length == 0) {
+ if(json && Array.isArray(json)) {
+ UIkit.notification("This file is not supported any more. Please export indicators and try again!", {
+ status: 'danger',
+ timeout: 6000,
+ pos: 'bottom-right'
+ });
+ this.editing = false;
+ this.importLoading = false;
+ } else if (!json || json?.indicators.length == 0) {
UIkit.notification("Importing file is empty", {
status: 'danger',
timeout: 6000,
@@ -1469,7 +1424,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.editing = false;
this.importLoading = false;
} else {
- this.importIndicatorsAndSave(json_result);
+ this.importIndicatorsAndSave(json.stakeholder, json.indicators);
}
}, (error) => {
console.error("Error importing files", error);