export: add section information
import: sends a list of sections to save instead of a list of indicators
This commit is contained in:
parent
62dff971f3
commit
a3b2d58dc9
|
@ -833,7 +833,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
saveIndicators(indicators: Indicator[]) {
|
saveIndicators(sections) {
|
||||||
this.editing = true;
|
this.editing = true;
|
||||||
let path = [
|
let path = [
|
||||||
this.stakeholder._id,
|
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]._id,
|
||||||
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index]._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].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.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers = stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers;
|
||||||
this.setCharts();
|
this.setCharts();
|
||||||
|
@ -1216,70 +1216,81 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
||||||
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
|
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
importIndicatorsAndSave(charts: any[]) {
|
importIndicatorsAndSave(charts: any[]) {
|
||||||
let indicators: Indicator[] = [];
|
let sectionsToSave: Section[] = [];
|
||||||
|
let countIndicators = 0;
|
||||||
// name description additionalDescription, height, width, visibility
|
// name description additionalDescription, height, width, visibility
|
||||||
let noValidParams = 0;
|
let noValidParams = 0;
|
||||||
let duplicates = 0;
|
let duplicates = 0;
|
||||||
for (let chart of charts) {
|
for (let chart of charts) {
|
||||||
let exists = false;
|
if(!chart['sectionIndex']){
|
||||||
let indicatorPath;
|
chart['sectionIndex'] = chart['type'] == 'chart'?1:0;
|
||||||
// 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) {
|
|
||||||
invalid_file_message = "No jsonPath is specified for number indicator."
|
|
||||||
} else if (!chart.url) {
|
|
||||||
invalid_file_message = "No indicator url is specified.";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (invalid_file_message) {
|
|
||||||
UIkit.notification(invalid_file_message, {
|
|
||||||
status: 'danger',
|
|
||||||
timeout: 6000,
|
|
||||||
pos: 'bottom-right'
|
|
||||||
});
|
|
||||||
this.editing = false;
|
|
||||||
this.importLoading = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chart.type == "chart") {
|
|
||||||
indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(chart.url), chart.url, chart.type, this.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)) {
|
|
||||||
duplicates++;
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (chart.type == "number") {
|
if(!sectionsToSave[chart['sectionIndex']]){
|
||||||
indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(chart.url), chart.url, this.stakeholder,
|
let sectionToSave = new Section(chart['sectionType']?chart['sectionType']:chart['type'], chart['sectionTitle']);
|
||||||
chart.jsonPath, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(chart.url)));
|
sectionToSave.indicators = [];
|
||||||
for (let section of this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].numbers) {
|
sectionsToSave[chart['sectionIndex']] = sectionToSave;
|
||||||
for (let chart of section.indicators) {
|
|
||||||
if (JSON.stringify(chart.indicatorPaths[0].chartObject) == JSON.stringify(indicatorPath.chartObject)) {
|
|
||||||
duplicates++;
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
let exists = false;
|
||||||
if (!this.isStakeholderParametersValid(indicatorPath)) {
|
let indicatorPath;
|
||||||
noValidParams++;
|
// validate indicators' schema from file
|
||||||
}
|
let invalid_file_message = "";
|
||||||
if (!exists) {
|
if (!chart.type) {
|
||||||
let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height, "RESTRICTED", [indicatorPath]);
|
invalid_file_message = "No indicator type is specified. Type should be chart or number.";
|
||||||
indicators.push(i);
|
} 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) {
|
||||||
|
invalid_file_message = "No jsonPath is specified for number indicator."
|
||||||
|
} else if (!chart.url) {
|
||||||
|
invalid_file_message = "No indicator url is specified.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalid_file_message) {
|
||||||
|
UIkit.notification(invalid_file_message, {
|
||||||
|
status: 'danger',
|
||||||
|
timeout: 6000,
|
||||||
|
pos: 'bottom-right'
|
||||||
|
});
|
||||||
|
this.editing = false;
|
||||||
|
this.importLoading = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chart.type == "chart") {
|
||||||
|
indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(chart.url), chart.url, chart.type, this.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)) {
|
||||||
|
duplicates++;
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (chart.type == "number") {
|
||||||
|
indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(chart.url), chart.url, this.stakeholder,
|
||||||
|
chart.jsonPath, this.statisticsService.numberSources.get(this.statisticsService.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) {
|
||||||
|
if (JSON.stringify(chart.indicatorPaths[0].chartObject) == JSON.stringify(indicatorPath.chartObject)) {
|
||||||
|
duplicates++;
|
||||||
|
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, "RESTRICTED", [indicatorPath]);
|
||||||
|
sectionsToSave[chart['sectionIndex']].indicators.push(i);
|
||||||
|
countIndicators ++ ;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
if (duplicates > 0) {
|
if (duplicates > 0) {
|
||||||
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
|
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
|
||||||
status: 'warning',
|
status: 'warning',
|
||||||
|
@ -1299,10 +1310,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
||||||
});
|
});
|
||||||
this.editing = false;
|
this.editing = false;
|
||||||
this.importLoading = false;
|
this.importLoading = false;
|
||||||
} else if (indicators.length > 0) {
|
} else if (sectionsToSave.length > 0 && countIndicators >0) {
|
||||||
this.saveIndicators(indicators)
|
this.saveIndicators(sectionsToSave)
|
||||||
}
|
}
|
||||||
if (indicators.length == 0) {
|
if (sectionsToSave.length == 0 || countIndicators == 0) {
|
||||||
UIkit.notification(" No urls imported!", {
|
UIkit.notification(" No urls imported!", {
|
||||||
status: 'warning',
|
status: 'warning',
|
||||||
timeout: 6000,
|
timeout: 6000,
|
||||||
|
@ -1317,34 +1328,42 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
||||||
this.editing = true;
|
this.editing = true;
|
||||||
let indicators = [];
|
let indicators = [];
|
||||||
let index: number = 0;
|
let index: number = 0;
|
||||||
|
let indexIndicator: number = 0;
|
||||||
this.numbers.forEach(section => {
|
this.numbers.forEach(section => {
|
||||||
section.indicators.forEach(indicator => {
|
section.indicators.forEach(indicator => {
|
||||||
indicator.indicatorPaths.forEach(indicatorPath => {
|
indicator.indicatorPaths.forEach(indicatorPath => {
|
||||||
// console.debug("export number: ", this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
|
indicators[indexIndicator] = {
|
||||||
indicators[index] = {
|
|
||||||
"type": indicator.type, "name": indicator.name, "jsonPath": indicatorPath.jsonPath,
|
"type": indicator.type, "name": indicator.name, "jsonPath": indicatorPath.jsonPath,
|
||||||
"description": indicator.description, "additionalDescription": indicator.additionalDescription,
|
"description": indicator.description, "additionalDescription": indicator.additionalDescription,
|
||||||
"visibility": indicator.visibility, "width": indicator.width, "height": indicator.height,
|
"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 => {
|
this.charts.forEach(section => {
|
||||||
section.indicators.forEach(indicator => {
|
section.indicators.forEach(indicator => {
|
||||||
indicator.indicatorPaths.forEach(indicatorPath => {
|
indicator.indicatorPaths.forEach(indicatorPath => {
|
||||||
// console.debug("export chart: " + this.getUrlByStakeHolder(indicatorPath));
|
indicators[indexIndicator] = {
|
||||||
indicators[index] = {
|
|
||||||
"type": indicator.type, "name": indicator.name,
|
"type": indicator.type, "name": indicator.name,
|
||||||
"description": indicator.description, "additionalDescription": indicator.additionalDescription,
|
"description": indicator.description, "additionalDescription": indicator.additionalDescription,
|
||||||
"visibility": indicator.visibility, "width": indicator.width, "height": indicator.height,
|
"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;
|
let topic = this.stakeholder ? this.stakeholder.topics[this.topicIndex] : null;
|
||||||
|
|
Loading…
Reference in New Issue