From 5f70100118197d4ff1c70ce71b858da78d8a545e Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 14 Feb 2024 18:42:29 +0200 Subject: [PATCH] UI: Add value converter type to set value settings. --- .../config/basic/rpc/slider-basic-config.component.html | 3 ++- .../components/widget/lib/action/action-widget.models.ts | 4 ++++ .../components/widget/lib/rpc/slider-widget.models.ts | 2 +- .../action/set-value-action-settings-panel.component.html | 3 ++- .../action/set-value-action-settings-panel.component.ts | 6 ++++++ .../common/action/set-value-action-settings.component.ts | 8 ++++++++ .../control/slider-widget-settings.component.html | 3 ++- .../app/shared/models/action-widget-settings.models.ts | 1 + ui-ngx/src/assets/locale/locale.constant-en_US.json | 1 + 9 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html index 76c4ff9ea3..a8d84d4dc4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html @@ -23,7 +23,7 @@
widgets.slider.initial-value
widgets.slider.on-value-change { constructor(protected settings: ValueToDataSettings) { switch (settings.type) { + case ValueToDataType.VALUE: + break; case ValueToDataType.CONSTANT: this.constantValue = this.settings.constantValue; break; @@ -309,6 +311,8 @@ export class ValueToDataConverter { valueToData(value: V): any { switch (this.settings.type) { + case ValueToDataType.VALUE: + return value; case ValueToDataType.CONSTANT: return this.constantValue; case ValueToDataType.FUNCTION: diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/slider-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/slider-widget.models.ts index 78603bc058..c6fe1e290a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/slider-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/slider-widget.models.ts @@ -138,7 +138,7 @@ export const sliderWidgetDefaultSettings: SliderWidgetSettings = { key: 'state' }, valueToData: { - type: ValueToDataType.FUNCTION, + type: ValueToDataType.VALUE, constantValue: 0, valueToDataFunction: '/* Convert input integer value to RPC parameters or attribute/time-series value */\nreturn value;' } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html index b1fccafac0..4cf5857612 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html @@ -97,7 +97,8 @@
{{ (setValueSettingsFormGroup.get('action').value === setValueAction.EXECUTE_RPC ? 'widgets.value-action.parameters' : 'widgets.value-action.value') | translate }}
- {{ 'widgets.value-action.converter-constant' | translate }} + {{ 'widgets.value-action.converter-value' | translate }} + {{ 'widgets.value-action.converter-constant' | translate }} {{ 'widgets.value-action.converter-function' | translate }} {{ 'widgets.value-action.converter-none' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.ts index d718168b11..819ed2a3fc 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.ts @@ -32,6 +32,7 @@ import { TargetDevice, widgetType } from '@shared/models/widget.models'; import { AttributeScope, DataKeyType, telemetryTypeTranslationsShort } from '@shared/models/telemetry/telemetry.models'; import { IAliasController } from '@core/api/widget-api.models'; import { WidgetService } from '@core/http/widget.service'; +import { ValueType } from '@shared/models/constants'; @Component({ selector: 'tb-set-value-action-settings-panel', @@ -45,6 +46,9 @@ export class SetValueActionSettingsPanelComponent extends PageComponent implemen @Input() panelTitle: string; + @Input() + valueType = ValueType.BOOLEAN; + @Input() setValueSettings: SetValueSettings; @@ -79,6 +83,8 @@ export class SetValueActionSettingsPanelComponent extends PageComponent implemen functionScopeVariables = this.widgetService.getWidgetScopeVariables(); + ValueType = ValueType; + setValueSettingsFormGroup: UntypedFormGroup; constructor(private fb: UntypedFormBuilder, diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings.component.ts index fce1e23673..7b4c8e0428 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings.component.ts @@ -36,6 +36,7 @@ import { isDefinedAndNotNull } from '@core/utils'; import { SetValueActionSettingsPanelComponent } from '@home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component'; +import { ValueType } from '@shared/models/constants'; @Component({ selector: 'tb-set-value-action-settings', @@ -58,6 +59,9 @@ export class SetValueActionSettingsComponent implements OnInit, ControlValueAcce @Input() panelTitle: string; + @Input() + valueType = ValueType.BOOLEAN; + @Input() aliasController: IAliasController; @@ -114,6 +118,7 @@ export class SetValueActionSettingsComponent implements OnInit, ControlValueAcce const ctx: any = { setValueSettings: this.modelValue, panelTitle: this.panelTitle, + valueType: this.valueType, aliasController: this.aliasController, targetDevice: this.targetDevice, widgetType: this.widgetType @@ -137,6 +142,9 @@ export class SetValueActionSettingsComponent implements OnInit, ControlValueAcce private updateDisplayValue() { let value: any; switch (this.modelValue.valueToData.type) { + case ValueToDataType.VALUE: + value = 'value'; + break; case ValueToDataType.CONSTANT: value = this.modelValue.valueToData.constantValue; break; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html index 9ef4a603ec..0f3c3f11a3 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html @@ -22,7 +22,7 @@
widgets.slider.initial-value
widgets.slider.on-value-change ( ); export enum ValueToDataType { + VALUE = 'VALUE', CONSTANT = 'CONSTANT', FUNCTION = 'FUNCTION', NONE = 'NONE' diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 296c56c020..c71f33fca7 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -6638,6 +6638,7 @@ "converter-none": "None", "converter-function": "Function", "converter-constant": "Constant", + "converter-value": "Value", "parse-value-function": "Parse value function", "state-when-result-is": "'{{state}}' when result is", "parameters": "Parameters",