From 9662b263e4f48934a33e93e7d960c85b6c1ccb1d Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 9 May 2025 10:19:37 +0300 Subject: [PATCH] UI: Refactoring ValueFormatProcessor and fixed unit input component --- ui-ngx/src/app/core/services/unit.service.ts | 6 +- .../common/key/data-key-config.component.html | 2 +- .../components/unit-input.component.html | 8 +- .../shared/components/unit-input.component.ts | 74 ++++++------- ui-ngx/src/app/shared/models/unit.models.ts | 13 +++ .../shared/models/widget-settings.models.ts | 104 ++++++++++-------- 6 files changed, 111 insertions(+), 96 deletions(-) diff --git a/ui-ngx/src/app/core/services/unit.service.ts b/ui-ngx/src/app/core/services/unit.service.ts index 9e656907f3..026ac0f3fe 100644 --- a/ui-ngx/src/app/core/services/unit.service.ts +++ b/ui-ngx/src/app/core/services/unit.service.ts @@ -88,11 +88,11 @@ export class UnitService { return this.converter.getUnitConverter(unit as string, to); } - getTargetUnitSymbol(unit: TbUnitMapping): string { + getTargetUnitSymbol(unit: TbUnitMapping | string): string { if (isObject(unit)) { - return isNotEmptyStr(unit[this.currentUnitSystem]) ? unit[this.currentUnitSystem] : unit.from; + return isNotEmptyStr(unit[this.currentUnitSystem]) ? unit[this.currentUnitSystem] : (unit as TbUnitMapping).from; } - return null; + return typeof unit === 'string' ? unit : null; } convertUnitValue(value: number, unit: TbUnitMapping): number; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.html index 68a2b5b851..73c1865cc2 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.html @@ -49,7 +49,7 @@
widget-config.units-short
diff --git a/ui-ngx/src/app/shared/components/unit-input.component.html b/ui-ngx/src/app/shared/components/unit-input.component.html index e577db6395..e1ab29fab3 100644 --- a/ui-ngx/src/app/shared/components/unit-input.component.html +++ b/ui-ngx/src/app/shared/components/unit-input.component.html @@ -22,11 +22,11 @@ [class.!pointer-events-none]="disabled" (focusin)="onFocus()" [matAutocomplete]="unitsAutocomplete" - [matAutocompleteDisabled]="allowConverted"> + [matAutocompleteDisabled]="supportsUnitConversion">