Merge branch 'AD/bug-fix/aggregation-index' of github.com:ArtemDzhereleiko/thingsboard into AD/bug-fix/aggregation-index

This commit is contained in:
Vladyslav_Prykhodko 2023-01-30 16:17:12 +02:00
commit 0fe0a84d32

View File

@ -201,7 +201,7 @@ export class DataKeyConfigComponent extends PageComponent implements OnInit, Con
let newLabel = this.dataKeyFormGroup.get('name').value;
if (aggType !== AggregationType.NONE) {
const prefix = this.translate.instant(aggregationTranslations.get(aggType));
newLabel = prefix + ' ' + newLabel;
newLabel = this.genNextLabelWithAggregation(prefix + ' ' + newLabel);
}
this.dataKeyFormGroup.get('label').patchValue(newLabel);
}
@ -241,6 +241,30 @@ export class DataKeyConfigComponent extends PageComponent implements OnInit, Con
);
}
private genNextLabelWithAggregation(name: string): string {
let label = name;
let i = 1;
let matches = false;
const datasources = this.widget.config.datasources;
if (datasources) {
do {
matches = false;
datasources.forEach((datasource) => {
if (datasource && datasource?.dataKeys) {
datasource.dataKeys.forEach((dataKey) => {
if (dataKey.label === label) {
i++;
label = name + ' ' + i;
matches = true;
}
});
}
});
} while (matches);
}
return label;
}
registerOnChange(fn: any): void {
this.propagateChange = fn;
}