From 76237337b2daf7ca5a85e97c631d39e48bf80869 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 9 May 2025 09:25:23 +0300 Subject: [PATCH] UI: Add new widhet type parameters supportsUnitConversion --- .../basic/cards/aggregated-data-key-row.component.html | 4 +++- .../basic/cards/aggregated-data-key-row.component.ts | 7 ++++++- .../widget/config/basic/common/data-key-row.component.html | 1 + .../widget/config/basic/common/data-key-row.component.ts | 7 ++++++- .../components/widget/config/datasource.component.html | 1 + .../home/components/widget/config/datasource.component.ts | 4 ++++ .../common/key/data-key-config-dialog.component.html | 1 + .../common/key/data-key-config-dialog.component.ts | 1 + .../lib/settings/common/key/data-key-config.component.html | 1 + .../lib/settings/common/key/data-key-config.component.ts | 4 ++++ .../widget/lib/settings/common/key/data-keys.component.ts | 7 ++++++- .../home/components/widget/widget-component.service.ts | 3 +++ .../home/components/widget/widget-config.component.html | 1 + ui-ngx/src/app/shared/models/widget.models.ts | 1 + 14 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.html b/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.html index 58df05162b..9b77abf74f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.html @@ -47,7 +47,9 @@ />
- +
diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.ts index d790b1d477..23b700ccbf 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/cards/aggregated-data-key-row.component.ts @@ -123,6 +123,10 @@ export class AggregatedDataKeyRowComponent implements ControlValueAccessor, OnIn return [DatasourceType.device, DatasourceType.entity].includes(this.datasourceType); } + get supportsUnitConversion(): boolean { + return this.widgetConfigComponent.modelValue?.typeParameters?.supportsUnitConversion ?? false; + } + private propagateChange = (_val: any) => {}; constructor(private fb: UntypedFormBuilder, @@ -222,7 +226,8 @@ export class AggregatedDataKeyRowComponent implements ControlValueAccessor, OnIn callbacks: this.callbacks, hideDataKeyName: true, hideDataKeyLabel: true, - hideDataKeyColor: true + hideDataKeyColor: true, + supportsUnitConversion: this.supportsUnitConversion } }).afterClosed().subscribe((updatedDataKey) => { if (updatedDataKey) { diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.html b/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.html index 2ed3afa3bf..ace382d228 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.html @@ -69,6 +69,7 @@
diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.ts index 7997e332d5..0b3b8107f6 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/common/data-key-row.component.ts @@ -225,6 +225,10 @@ export class DataKeyRowComponent implements ControlValueAccessor, OnInit, OnChan return this.hasAdditionalLatestDataKeys && this.keyRowFormGroup.get('latest').value === true; } + get supportsUnitConversion(): boolean { + return this.widgetConfigComponent.modelValue?.typeParameters?.supportsUnitConversion ?? false; + } + private propagateChange = (_val: any) => {}; constructor(private fb: UntypedFormBuilder, @@ -337,7 +341,8 @@ export class DataKeyRowComponent implements ControlValueAccessor, OnInit, OnChan hideDataKeyLabel: this.hideDataKeyLabel, hideDataKeyColor: this.hideDataKeyColor, hideDataKeyUnits: this.hideDataKeyUnits || !this.displayUnitsOrDigits, - hideDataKeyDecimals: this.hideDataKeyDecimals || !this.displayUnitsOrDigits + hideDataKeyDecimals: this.hideDataKeyDecimals || !this.displayUnitsOrDigits, + supportsUnitConversion: this.supportsUnitConversion } }).afterClosed().subscribe((updatedDataKey) => { if (updatedDataKey) { diff --git a/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.html b/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.html index f7bb0662e9..9059decca4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.html @@ -71,6 +71,7 @@ [hideDataKeyUnits]="hideDataKeyUnits" [hideDataKeyDecimals]="hideDataKeyDecimals" [maxDataKeys]="maxDataKeys" + [supportsUnitConversion]="supportsUnitConversion" [optDataKeys]="isDataKeysOptional(datasourceFormGroup.get('type').value)" [simpleDataKeysLabel]="!hasAdditionalLatestDataKeys" [aliasController]="aliasController" diff --git a/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.ts b/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.ts index 5a519c18d1..48b31439db 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/config/datasource.component.ts @@ -135,6 +135,10 @@ export class DatasourceComponent implements ControlValueAccessor, OnInit, Valida return this.widgetConfigComponent.modelValue?.dataKeySettingsFunction; } + public get supportsUnitConversion(): boolean { + return this.widgetConfigComponent.modelValue?.typeParameters?.supportsUnitConversion ?? false; + } + public get dashboard(): Dashboard { return this.widgetConfigComponent.dashboard; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.html index 49f578079b..de54ff86d4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.html @@ -50,6 +50,7 @@ [hideDataKeyColor]="data.hideDataKeyColor" [hideDataKeyUnits]="data.hideDataKeyUnits" [hideDataKeyDecimals]="data.hideDataKeyDecimals" + [supportsUnitConversion]="data.supportsUnitConversion" formControlName="dataKey"> diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.ts index 2b11c62632..829402a53f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config-dialog.component.ts @@ -56,6 +56,7 @@ export interface DataKeyConfigDialogData { hideDataKeyColor?: boolean; hideDataKeyUnits?: boolean; hideDataKeyDecimals?: boolean; + supportsUnitConversion?: boolean } @Component({ 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 0af5159846..68a2b5b851 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,6 +49,7 @@
widget-config.units-short
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.ts index c85a8f0ba6..c7b65bfc83 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-key-config.component.ts @@ -153,6 +153,10 @@ export class DataKeyConfigComponent extends PageComponent implements OnInit, Con @coerceBoolean() hideDataKeyDecimals = false; + @Input() + @coerceBoolean() + supportsUnitConversion = false; + @ViewChild('keyInput') keyInput: ElementRef; @ViewChild('funcBodyEdit', {static: false}) funcBodyEdit: JsFuncComponent; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-keys.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-keys.component.ts index a9be1fd352..a1c388845f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-keys.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/key/data-keys.component.ts @@ -169,6 +169,10 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, OnChange @coerceBoolean() simpleDataKeysLabel = false; + @Input() + @coerceBoolean() + supportsUnitConversion = false; + @Input() aliasController: IAliasController; @@ -610,7 +614,8 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, OnChange hideDataKeyLabel: this.hideDataKeyLabel, hideDataKeyColor: this.hideDataKeyColor, hideDataKeyUnits: this.hideDataKeyUnits, - hideDataKeyDecimals: this.hideDataKeyDecimals + hideDataKeyDecimals: this.hideDataKeyDecimals, + supportsUnitConversion: this.supportsUnitConversion } }).afterClosed().subscribe((updatedDataKey) => { if (updatedDataKey) { diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts b/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts index c0f37b3a37..c8b9eb963b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts @@ -662,6 +662,9 @@ export class WidgetComponentService { if (isUndefined(result.typeParameters.targetDeviceOptional)) { result.typeParameters.targetDeviceOptional = false; } + if (isUndefined(result.typeParameters.supportsUnitConversion)) { + result.typeParameters.supportsUnitConversion = false; + } if (isDefinedAndNotNull(result.typeParameters.additionalWidgetActionTypes)) { if (Array.isArray(result.typeParameters.additionalWidgetActionTypes)) { result.typeParameters.additionalWidgetActionTypes = result.typeParameters.additionalWidgetActionTypes.filter(type => WidgetActionType[type]); diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html index efa1dffe0b..77764ba408 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html @@ -291,6 +291,7 @@
widget-config.units-by-default
diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index 21d7927d16..221358d8c8 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -196,6 +196,7 @@ export interface WidgetTypeParameters { dataKeySettingsFunction?: DataKeySettingsFunction; displayRpcMessageToast?: boolean; targetDeviceOptional?: boolean; + supportsUnitConversion?: boolean; additionalWidgetActionTypes?: WidgetActionType[]; }