fix import indicators with no numbers - create separate method to migrate from old json format.

This commit is contained in:
argirok 2022-09-19 16:38:36 +03:00
parent 22b22f4afa
commit c0f76eb601
2 changed files with 20 additions and 5 deletions

@ -1 +1 @@
Subproject commit bdce56aff9e458d4d24da9a9a0fca28e100372ad
Subproject commit 876b51d4205c7941862b5455f0763df7a66ffcd1

View File

@ -1201,6 +1201,24 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
private checkForSchemaEnhancements(url: string) {
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
}
migrateFromOldImportJsonFile(charts){
// first section contains numbers
// second contains charts
let hasNumbers = false;
for (let chart of charts) {
if (chart['type'] == 'number') {
hasNumbers = true;
break;
}
}
let chartsSection = (hasNumbers?1:0); // no numbers: first sections contains charts
for (let chart of charts) {
if (chart['sectionIndex'] == null) {
chart['sectionIndex'] = chart['type'] == 'chart' ? chartsSection : 0;
}
}
return charts;
}
importIndicatorsAndSave(charts: any[]) {
let sectionsToSave: Section[] = [];
@ -1208,10 +1226,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
// name description additionalDescription, height, width, visibility
let noValidParams = 0;
let duplicates = 0;
charts = this.migrateFromOldImportJsonFile(charts);
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 = [];
@ -1297,7 +1313,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = false;
this.importLoading = false;
} else if (sectionsToSave.length > 0 && countIndicators > 0) {
sectionsToSave = sectionsToSave.filter(section => !!section);
this.saveIndicators(sectionsToSave)
}
if (sectionsToSave.length == 0 || countIndicators == 0) {