diff --git a/monitor-admin/topic/indicators.component.html b/monitor-admin/topic/indicators.component.html index 2b0a57c3..69abb1dd 100644 --- a/monitor-admin/topic/indicators.component.html +++ b/monitor-admin/topic/indicators.component.html @@ -339,7 +339,6 @@
-
{{ urlParameterizedMessage }}
-
{{ urlParameterizedMessage }}
diff --git a/monitor-admin/topic/indicators.component.ts b/monitor-admin/topic/indicators.component.ts index 42e85ddc..9be745ae 100644 --- a/monitor-admin/topic/indicators.component.ts +++ b/monitor-admin/topic/indicators.component.ts @@ -97,7 +97,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple public sectionTypeToDelete: string; public sectionChildrenActionOnDelete: string; public indicatorChildrenActionOnDelete: string; - public urlParameterizedMessage = null; private notification: Notification; @ViewChild('editNumberNotify', {static: true}) editNumberNotify: NotifyFormComponent; @ViewChild('editChartNotify', {static: true}) editChartNotify: NotifyFormComponent; @@ -210,11 +209,11 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.reorderIndicators(section._id, 'number', callback(list)); })); this.subscriptions.push(UIkit.util.on(document, 'added', '#number-' + section._id, (list): void => { - this.to.next({id: section._id, indicators: callback(list)}); + this.to.next({id: section._id, indicators: callback(list)}); })); this.subscriptions.push(UIkit.util.on(document, 'removed', '#number-' + section._id, (list): void => { let sub = this.to.asObservable().subscribe(to => { - if(to) { + if (to) { let from: SectionInfo = {id: section._id, indicators: callback(list)}; this.moveIndicator({target: list.detail[1].id, from: from, to: to}); setTimeout(() => { @@ -232,7 +231,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple //callback(list, "chart", 'added'); })); this.subscriptions.push(UIkit.util.on(document, 'removed', '#chart-' + section._id, (list): void => { - // callback(list, "chart", 'removed'); + // callback(list, "chart", 'removed'); })); }); } @@ -331,8 +330,8 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple get charts(): Section[] { if (this.stakeholder.topics[this.topicIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) { + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) { return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts; } else { return []; @@ -341,8 +340,8 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple get numbers(): Section[] { if (this.stakeholder.topics[this.topicIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) { + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) { return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers; } else { return []; @@ -359,9 +358,9 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple get canEdit() { return this.stakeholder && - this.stakeholder.topics[this.topicIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && - this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex] && !this.loading; + this.stakeholder.topics[this.topicIndex] && + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] && + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex] && !this.loading; } public get numberIndicatorPaths(): UntypedFormArray { @@ -373,7 +372,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } public getActiveIndicatorPath(indicator: Indicator) { - if(indicator.activePath) { + if (indicator.activePath) { return indicator.indicatorPaths[indicator.activePath]; } else { return indicator.indicatorPaths[0]; @@ -476,7 +475,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } public getParameters(index: number, type: IndicatorType = 'chart'): UntypedFormArray { - if(type === 'chart') { + if (type === 'chart') { return this.chartIndicatorPaths.at(index).get('parameters') as UntypedFormArray; } else { return this.numberIndicatorPaths.at(index).get('parameters') as UntypedFormArray; @@ -489,7 +488,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple private getSecureUrlByStakeHolder(indicatorPath: IndicatorPath) { return this.sanitizer.bypassSecurityTrustResourceUrl( - this.indicatorUtils.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath))); + this.indicatorUtils.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath))); } private getUrlByStakeHolder(indicatorPath: IndicatorPath) { @@ -501,13 +500,13 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple jsonPath.push(this.fb.control('', Validators.required)); } this.numberIndicatorPaths.push(this.fb.group({ - url: this.fb.control(url, [Validators.required, StringUtils.urlValidator()]), - jsonPath: jsonPath, - result: this.fb.control(0, Validators.required), - source: this.fb.control(source, Validators.required), - parameters: parameters, - format: this.fb.control(format, Validators.required) - } + url: this.fb.control(url, [Validators.required, StringUtils.urlValidator()]), + jsonPath: jsonPath, + result: this.fb.control(0, Validators.required), + source: this.fb.control(source, Validators.required), + parameters: parameters, + format: this.fb.control(format, Validators.required) + } )); let index = this.numberIndicatorPaths.length - 1; if (this.numberIndicatorPaths.at(index).get('url').valid) { @@ -515,45 +514,43 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } 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.indicatorUtils.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.indicatorUtils.numberSources.get(this.indicatorUtils.getNumberSource(value))); - 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); - } - (this.numberIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', this.getParametersAsFormArray(indicatorPath)); - 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.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.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); + } + (this.numberIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', this.getParametersAsFormArray(indicatorPath)); + 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.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); - }) + 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; - } - }) + if (this.indicator.indicatorPaths[index]) { + this.indicator.indicatorPaths[index].source = value; + } + }) ); } else { this.numberIndicatorPaths.at(index).get('url').disable(); @@ -564,10 +561,10 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple public addChartIndicatorPath(value: string = '', parameters: UntypedFormArray = new UntypedFormArray([]), disableUrl: boolean = false, type: string = null) { this.chartIndicatorPaths.push(this.fb.group({ - url: this.fb.control(value, [Validators.required, StringUtils.urlValidator()]), - parameters: parameters, - type: this.fb.control(type) - } + url: this.fb.control(value, [Validators.required, StringUtils.urlValidator()]), + parameters: parameters, + type: this.fb.control(type) + } )); let index = this.chartIndicatorPaths.length - 1; if (disableUrl) { @@ -585,8 +582,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple indicatorPath.safeResourceUrl = this.indicator.indicatorPaths[index].safeResourceUrl; this.indicator.indicatorPaths[index] = indicatorPath; } - } else { - this.urlParameterizedMessage = null; } })); } @@ -596,9 +591,9 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.numberIndicatorPaths.removeAt(index); this.indicator.indicatorPaths.splice(index, 1); this.transitionGroup.init(); - if(this.indicator.activePath === index) { + if (this.indicator.activePath === index) { this.activeNumberIndicatorPath(Math.max(0, index - 1)); - } else if(this.indicator.activePath > index) { + } else if (this.indicator.activePath > index) { this.activeNumberIndicatorPath(this.indicator.activePath - 1); } this.numberIndicatorFb.markAsDirty(); @@ -608,9 +603,9 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.chartIndicatorPaths.removeAt(index); this.indicator.indicatorPaths.splice(index, 1); this.transitionGroup.init(); - if(this.indicator.activePath === index) { + if (this.indicator.activePath === index) { this.activeChartIndicatorPath(Math.max(0, index - 1)); - } else if(this.indicator.activePath > index) { + } else if (this.indicator.activePath > index) { this.activeChartIndicatorPath(this.indicator.activePath - 1); } this.chartIndicatorFb.markAsDirty(); @@ -622,12 +617,12 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.transitionGroup.init(); let a = indicatorPaths.at(index); let b = indicatorPaths.at(newIndex); - indicatorPaths.setControl(index , b); - indicatorPaths.setControl(newIndex , a); - HelperFunctions.swap(this.indicator.indicatorPaths, index , newIndex); - if(this.indicator.activePath === index) { + indicatorPaths.setControl(index, b); + indicatorPaths.setControl(newIndex, a); + HelperFunctions.swap(this.indicator.indicatorPaths, index, newIndex); + if (this.indicator.activePath === index) { this.indicator.activePath = newIndex; - } else if(this.indicator.activePath === newIndex) { + } else if (this.indicator.activePath === newIndex) { this.indicator.activePath = index; } form.markAsDirty(); @@ -635,7 +630,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple public activeNumberIndicatorPath(index: number) { let paths = this.numberIndicatorPaths; - if(index == paths.length) { + if (index == paths.length) { this.addNumberIndicatorPath(); this.transitionGroup.init(); } @@ -644,7 +639,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple public activeChartIndicatorPath(index: number) { let paths = this.chartIndicatorPaths; - if(index == paths.length) { + if (index == paths.length) { this.addChartIndicatorPath(); this.transitionGroup.init(); } @@ -684,7 +679,21 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } public editNumberIndicatorOpen(section: Section, id = null) { - this.urlParameterizedMessage = null; + this.editNumberModal.cancelButtonText = 'Cancel'; + this.editNumberModal.okButtonLeft = false; + this.editNumberModal.alertMessage = false; + if (this.index === -1) { + this.editNumberModal.alertTitle = 'Create a new number indicator'; + this.editNumberModal.okButtonText = 'Save'; + this.notification = NotificationUtils.createIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); + this.editNumberNotify.reset(this.notification.message); + } else { + this.editNumberModal.alertTitle = 'Edit number indicator\'s information'; + this.editNumberModal.okButtonText = 'Save Changes'; + this.notification = NotificationUtils.editIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); + this.editNumberNotify.reset(this.notification.message); + } + this.editNumberModal.stayOpen = true; this.section = section; this.index = (id) ? section.indicators.findIndex(value => value._id === id) : -1; if (this.index !== -1) { @@ -726,26 +735,26 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.numberIndicatorFb.get('description').disable(); }, 0); } - this.editNumberModal.cancelButtonText = 'Cancel'; - this.editNumberModal.okButtonLeft = false; - this.editNumberModal.alertMessage = false; - if (this.index === -1) { - this.editNumberModal.alertTitle = 'Create a new number indicator'; - this.editNumberModal.okButtonText = 'Save'; - this.notification = NotificationUtils.createIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); - this.editNumberNotify.reset(this.notification.message); - } else { - this.editNumberModal.alertTitle = 'Edit number indicator\'s information'; - this.editNumberModal.okButtonText = 'Save Changes'; - this.notification = NotificationUtils.editIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); - this.editNumberNotify.reset(this.notification.message); - } - this.editNumberModal.stayOpen = true; this.editNumberModal.open(); } public editChartIndicatorOpen(section: Section, id = null) { - this.urlParameterizedMessage = null; + this.editChartModal.cancelButtonText = 'Cancel'; + this.editChartModal.okButtonLeft = false; + this.editChartModal.alertMessage = false; + if (this.index === -1) { + this.editChartModal.alertTitle = 'Create a new chart indicator'; + this.editChartModal.okButtonText = 'Save'; + this.notification = NotificationUtils.createIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); + this.editChartNotify.reset(this.notification.message); + } else { + this.editChartModal.alertTitle = 'Edit chart indicator\'s information'; + this.editChartModal.okButtonText = 'Save Changes'; + this.notification = NotificationUtils.editIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); + ; + this.editChartNotify.reset(this.notification.message); + } + this.editChartModal.stayOpen = true; this.urlSubscriptions.forEach(value => { if (value instanceof Subscriber) { value.unsubscribe(); @@ -769,7 +778,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple }); this.indicator.indicatorPaths.forEach(indicatorPath => { this.addChartIndicatorPath(this.getUrlByStakeHolder(indicatorPath), - this.getParametersAsFormArray(indicatorPath), this.indicator.defaultId !== null, indicatorPath.type); + this.getParametersAsFormArray(indicatorPath), this.indicator.defaultId !== null, indicatorPath.type); indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath); }); } else { @@ -792,22 +801,6 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.chartIndicatorFb.get('description').disable(); }, 0); } - this.editChartModal.cancelButtonText = 'Cancel'; - this.editChartModal.okButtonLeft = false; - this.editChartModal.alertMessage = false; - if (this.index === -1) { - this.editChartModal.alertTitle = 'Create a new chart indicator'; - this.editChartModal.okButtonText = 'Save'; - this.notification = NotificationUtils.createIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); - this.editChartNotify.reset(this.notification.message); - } else { - this.editChartModal.alertTitle = 'Edit chart indicator\'s information'; - this.editChartModal.okButtonText = 'Save Changes'; - this.notification = NotificationUtils.editIndicator(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name); - ; - this.editChartNotify.reset(this.notification.message); - } - this.editChartModal.stayOpen = true; this.editChartModal.open(); } @@ -907,7 +900,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.setCharts(); this.setNumbers(); this.initReorder(); - if(properties.notificationsAPIURL) { + if (properties.notificationsAPIURL) { this.notification = NotificationUtils.importIndicators(this.user.fullname, this.stakeholder.alias); this.notification.entity = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index]._id; this.notification.name = this.user.firstname; @@ -999,7 +992,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple hasDifference(index: number, type: IndicatorType = 'chart'): boolean { let hasDifference = false; - if(type === 'chart') { + if (type === 'chart') { this.chartIndicatorPaths.at(index).value.parameters.forEach(parameter => { if (parameter.value !== this.indicator.indicatorPaths[index].parameters[parameter.key]) { hasDifference = true; @@ -1008,7 +1001,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple }); return hasDifference || this.indicator.indicatorPaths[index].safeResourceUrl.toString() !== this.getSecureUrlByStakeHolder(this.indicator.indicatorPaths[index]).toString(); - } else if(type === 'number') { + } else if (type === 'number') { let indicatorPath = this.numberIndicatorPaths.at(index).value; indicatorPath.parameters.forEach(parameter => { if (parameter.value !== this.indicator.indicatorPaths[index].parameters[parameter.key]) { @@ -1029,12 +1022,12 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } refreshIndicator(type: IndicatorType = 'chart') { - if(type === 'chart') { + if (type === 'chart') { this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart'); this.indicator.indicatorPaths.forEach(indicatorPath => { indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath); }); - } else if(type === 'number') { + } else if (type === 'number') { this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, 'number'); this.indicator.indicatorPaths.forEach((indicatorPath, index) => { this.validateJsonPath(index); @@ -1293,6 +1286,11 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple if (chart['sectionIndex'] == null) { chart['sectionIndex'] = chart['type'] == 'chart' ? chartsSection : 0; } + if (chart.url && chart.jsonPath) { + chart.indicatorPaths = [{url: chart.url, jsonPath: chart.jsonPath}]; + } else if(chart.url) { + chart.indicatorPaths = [{url: chart.url}]; + } } return charts; } @@ -1300,7 +1298,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple importIndicatorsAndSave(stakeholder: Stakeholder, charts: any[]) { let sectionsToSave: Section[] = []; let countIndicators = 0; - if(stakeholder.type !== this.stakeholder.type) { + 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, @@ -1313,23 +1311,25 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple let duplicates = 0; charts = this.migrateFromOldImportJsonFile(charts); for (let chart of charts) { - chart.visibility = this.showVisibility?chart.visibility:this.stakeholderUtils.defaultValue(this.stakeholderUtils.visibilities); + chart.visibility = this.showVisibility ? chart.visibility : this.stakeholderUtils.defaultValue(this.stakeholderUtils.visibilities); if (!sectionsToSave[chart['sectionIndex']]) { let sectionToSave = new Section(chart['sectionType'] ? chart['sectionType'] : chart['type'], chart['sectionTitle']); sectionToSave.indicators = []; sectionsToSave[chart['sectionIndex']] = sectionToSave; } let exists = false; - let indicatorPath; + let indicatorPaths: IndicatorPath[] = []; // validate indicators' schema from file let invalid_file_message; if (!chart.type) { invalid_file_message = "No indicator type is specified. Type should be chart or number."; } else if (chart.type != "chart" && chart.type != "number") { invalid_file_message = "Invalid indicator type. Type should be chart or number."; - } else if (chart.type == "number" && !chart.jsonPath) { + } else if (chart.indicatorPaths.length === 0) { + invalid_file_message = "No indicator paths are specified." + } else if (chart.type == "number" && chart.indicatorPaths.filter(path => !path.jsonPath).length > 0) { invalid_file_message = "No jsonPath is specified for number indicator." - } else if (!chart.url) { + } else if (chart.indicatorPaths.filter(path => !path.url).length > 0) { invalid_file_message = "No indicator url is specified."; } @@ -1344,33 +1344,38 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple } if (chart.type == "chart") { - indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.indicatorUtils.getChartSource(chart.url), chart.url, chart.type, stakeholder); + indicatorPaths = chart.indicatorPaths.map(path => this.indicatorUtils.generateIndicatorByChartUrl(this.indicatorUtils.getChartSource(path.url), path.url, chart.type, stakeholder)); this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].charts.forEach((section: Section) => { section.indicators.forEach(indicator => { indicator.indicatorPaths.forEach(path => { - if (JSON.stringify(path.chartObject) == JSON.stringify(indicatorPath.chartObject)) { - duplicates++; + let size = indicatorPaths.length; + indicatorPaths = indicatorPaths.filter(indicatorPath => JSON.stringify(path.chartObject) !== JSON.stringify(indicatorPath.chartObject)) + if (indicatorPaths.length < size) { + duplicates = duplicates + (size - indicatorPaths.length); exists = true; } }); }); }); } else if (chart.type == "number") { - indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.indicatorUtils.getNumberSource(chart.url), chart.url, stakeholder, - chart.jsonPath, this.indicatorUtils.numberSources.get(this.indicatorUtils.getNumberSource(chart.url))); + indicatorPaths = chart.indicatorPaths.map(path => + this.indicatorUtils.generateIndicatorByNumberUrl(this.indicatorUtils.getNumberSource(path.url), path.url, + stakeholder, path.jsonPath, this.indicatorUtils.numberSources.get(this.indicatorUtils.getNumberSource(path.url)))); this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers.forEach((section: Section) => { section.indicators.forEach(indicator => { indicator.indicatorPaths.forEach(path => { - if (JSON.stringify(path.chartObject) == JSON.stringify(indicatorPath.chartObject)) { - duplicates++; + let size = indicatorPaths.length; + indicatorPaths = indicatorPaths.filter(indicatorPath => JSON.stringify(path.chartObject) !== JSON.stringify(indicatorPath.chartObject)) + if (indicatorPaths.length < size) { + duplicates = duplicates + (size - indicatorPaths.length); exists = true; } }); }); }); } - 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]); + if (indicatorPaths.length > 0) { + 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), indicatorPaths); sectionsToSave[chart['sectionIndex']].indicators.push(i); countIndicators++; } @@ -1402,36 +1407,41 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple let indexIndicator: number = 0; this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[subcategoryIndex].numbers.forEach(section => { section.indicators.forEach(indicator => { - indicator.indicatorPaths.forEach(indicatorPath => { - indicators[indexIndicator] = { - "type": indicator.type, "name": indicator.name, "jsonPath": indicatorPath.jsonPath, - "description": indicator.description, "additionalDescription": indicator.additionalDescription, - "visibility": indicator.visibility, "width": indicator.width, "height": indicator.height, - "url": this.indicatorUtils.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), - "sectionTitle": section.title, - "sectionType": section.type, - "sectionIndex": index - }; - indexIndicator++; - }); + indicators[indexIndicator] = { + "indicatorPaths": indicator.indicatorPaths.map(path => { + return { + jsonPath: path.jsonPath, + url: this.indicatorUtils.getNumberUrl(path.source, this.indicatorUtils.getFullUrl(this.stakeholder, path)) + } + }), + "type": indicator.type, "name": indicator.name, + "description": indicator.description, "additionalDescription": indicator.additionalDescription, + "visibility": indicator.visibility, "width": indicator.width, "height": indicator.height, + "sectionTitle": section.title, + "sectionType": section.type, + "sectionIndex": index + }; + indexIndicator++; }); index++; }); this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[subcategoryIndex].charts.forEach(section => { section.indicators.forEach(indicator => { - indicator.indicatorPaths.forEach(indicatorPath => { - indicators[indexIndicator] = { - "type": indicator.type, "name": indicator.name, - "description": indicator.description, "additionalDescription": indicator.additionalDescription, - "visibility": indicator.visibility, "width": indicator.width, "height": indicator.height, - "url": this.getUrlByStakeHolder(indicatorPath), - "sectionTitle": section.title, - "sectionType": section.type, - "sectionIndex": index - }; - indexIndicator++; - }); + indicators[indexIndicator] = { + "indicatorPaths": indicator.indicatorPaths.map(path => { + return { + url: this.getUrlByStakeHolder(path) + } + }), + "type": indicator.type, "name": indicator.name, + "description": indicator.description, "additionalDescription": indicator.additionalDescription, + "visibility": indicator.visibility, "width": indicator.width, "height": indicator.height, + "sectionTitle": section.title, + "sectionType": section.type, + "sectionIndex": index + }; + indexIndicator++; }); index++; @@ -1491,7 +1501,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple this.makeFileRequest(this.properties.utilsService + '/upload?type=json', [], this.filesToUpload).then(async (result: string) => { let json = JSON.parse(result); // validate file - if(json && Array.isArray(json)) { + if (json && Array.isArray(json)) { UIkit.notification("This file is not supported any more. Please export indicators and try again!", { status: 'danger', timeout: 6000,