export: add section information

import: sends a list of sections to save instead of a list of indicators
This commit is contained in:
argirok 2022-09-08 17:45:59 +03:00
parent 62dff971f3
commit a3b2d58dc9
1 changed files with 91 additions and 72 deletions

View File

@ -833,7 +833,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}));
}
saveIndicators(indicators: Indicator[]) {
saveIndicators(sections) {
this.editing = true;
let path = [
this.stakeholder._id,
@ -841,7 +841,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index]._id
];
this.subscriptions.push(this.stakeholderService.saveBulkElements(this.properties.monitorServiceAPIURL, indicators, path).subscribe(stakeholder => {
this.subscriptions.push(this.stakeholderService.saveBulkElements(this.properties.monitorServiceAPIURL, sections, path).subscribe(stakeholder => {
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].charts = stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].charts;
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers = stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers;
this.setCharts();
@ -1217,11 +1217,20 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
importIndicatorsAndSave(charts: any[]) {
let indicators: Indicator[] = [];
let sectionsToSave: Section[] = [];
let countIndicators = 0;
// name description additionalDescription, height, width, visibility
let noValidParams = 0;
let duplicates = 0;
for (let chart of charts) {
if(!chart['sectionIndex']){
chart['sectionIndex'] = chart['type'] == 'chart'?1:0;
}
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;
// validate indicators' schema from file
@ -1276,10 +1285,12 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
if (!exists) {
let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height, "RESTRICTED", [indicatorPath]);
indicators.push(i);
sectionsToSave[chart['sectionIndex']].indicators.push(i);
countIndicators ++ ;
}
}
if (duplicates > 0) {
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
status: 'warning',
@ -1299,10 +1310,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
this.editing = false;
this.importLoading = false;
} else if (indicators.length > 0) {
this.saveIndicators(indicators)
} else if (sectionsToSave.length > 0 && countIndicators >0) {
this.saveIndicators(sectionsToSave)
}
if (indicators.length == 0) {
if (sectionsToSave.length == 0 || countIndicators == 0) {
UIkit.notification(" No urls imported!", {
status: 'warning',
timeout: 6000,
@ -1317,34 +1328,42 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = true;
let indicators = [];
let index: number = 0;
let indexIndicator: number = 0;
this.numbers.forEach(section => {
section.indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(indicatorPath => {
// console.debug("export number: ", this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
indicators[index] = {
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.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath))
"url": this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)),
"sectionTitle" : section.title,
"sectionType": section.type,
"sectionIndex": index
};
index++;
indexIndicator++;
});
});
index ++ ;
});
this.charts.forEach(section => {
section.indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(indicatorPath => {
// console.debug("export chart: " + this.getUrlByStakeHolder(indicatorPath));
indicators[index] = {
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)
"url": this.getUrlByStakeHolder(indicatorPath),
"sectionTitle" : section.title,
"sectionType": section.type,
"sectionIndex": index
};
index++;
indexIndicator++;
});
});
index ++ ;
});
let topic = this.stakeholder ? this.stakeholder.topics[this.topicIndex] : null;