Browse Source

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

pull/8010/head
Vladyslav_Prykhodko 3 years ago
parent
commit
0fe0a84d32
  1. 26
      ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts

26
ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts

@ -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;
}

Loading…
Cancel
Save