Browse Source

UI: Add value converter type to set value settings.

pull/10195/head
Igor Kulikov 2 years ago
parent
commit
5f70100118
  1. 3
      ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html
  2. 4
      ui-ngx/src/app/modules/home/components/widget/lib/action/action-widget.models.ts
  3. 2
      ui-ngx/src/app/modules/home/components/widget/lib/rpc/slider-widget.models.ts
  4. 3
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html
  5. 6
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.ts
  6. 8
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings.component.ts
  7. 3
      ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html
  8. 1
      ui-ngx/src/app/shared/models/action-widget-settings.models.ts
  9. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

3
ui-ngx/src/app/modules/home/components/widget/config/basic/rpc/slider-basic-config.component.html

@ -23,7 +23,7 @@
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.initial-value-hint' | translate}}" translate>widgets.slider.initial-value</div>
<tb-get-value-action-settings fxFlex
panelTitle="widgets.slider.initial-value"
[valueType]="valueType.INTEGER"
[valueType]="valueType.DOUBLE"
[aliasController]="aliasController"
[targetDevice]="targetDevice"
[widgetType]="widgetType"
@ -33,6 +33,7 @@
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.on-value-change-hint' | translate}}" translate>widgets.slider.on-value-change</div>
<tb-set-value-action-settings fxFlex
panelTitle="widgets.slider.on-value-change"
[valueType]="valueType.DOUBLE"
[aliasController]="aliasController"
[targetDevice]="targetDevice"
[widgetType]="widgetType"

4
ui-ngx/src/app/modules/home/components/widget/lib/action/action-widget.models.ts

@ -292,6 +292,8 @@ export class ValueToDataConverter<V> {
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<V> {
valueToData(value: V): any {
switch (this.settings.type) {
case ValueToDataType.VALUE:
return value;
case ValueToDataType.CONSTANT:
return this.constantValue;
case ValueToDataType.FUNCTION:

2
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;'
}

3
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/set-value-action-settings-panel.component.html

@ -97,7 +97,8 @@
<div class="fixed-title-width">{{ (setValueSettingsFormGroup.get('action').value === setValueAction.EXECUTE_RPC ?
'widgets.value-action.parameters' : 'widgets.value-action.value') | translate }}</div>
<tb-toggle-select fxFlex formControlName="type">
<tb-toggle-option [value]="valueToDataType.CONSTANT">{{ 'widgets.value-action.converter-constant' | translate }}</tb-toggle-option>
<tb-toggle-option [value]="valueToDataType.VALUE">{{ 'widgets.value-action.converter-value' | translate }}</tb-toggle-option>
<tb-toggle-option *ngIf="valueType === ValueType.BOOLEAN" [value]="valueToDataType.CONSTANT">{{ 'widgets.value-action.converter-constant' | translate }}</tb-toggle-option>
<tb-toggle-option [value]="valueToDataType.FUNCTION">{{ 'widgets.value-action.converter-function' | translate }}</tb-toggle-option>
<tb-toggle-option *ngIf="setValueSettingsFormGroup.get('action').value === setValueAction.EXECUTE_RPC"
[value]="valueToDataType.NONE">{{ 'widgets.value-action.converter-none' | translate }}</tb-toggle-option>

6
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,

8
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;

3
ui-ngx/src/app/modules/home/components/widget/lib/settings/control/slider-widget-settings.component.html

@ -22,7 +22,7 @@
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.initial-value-hint' | translate}}" translate>widgets.slider.initial-value</div>
<tb-get-value-action-settings fxFlex
panelTitle="widgets.slider.initial-value"
[valueType]="valueType.INTEGER"
[valueType]="valueType.DOUBLE"
[aliasController]="aliasController"
[targetDevice]="targetDevice"
[widgetType]="widgetType"
@ -32,6 +32,7 @@
<div class="fixed-title-width" tb-hint-tooltip-icon="{{'widgets.slider.on-value-change-hint' | translate}}" translate>widgets.slider.on-value-change</div>
<tb-set-value-action-settings fxFlex
panelTitle="widgets.slider.on-value-change"
[valueType]="valueType.DOUBLE"
[aliasController]="aliasController"
[targetDevice]="targetDevice"
[widgetType]="widgetType"

1
ui-ngx/src/app/shared/models/action-widget-settings.models.ts

@ -111,6 +111,7 @@ export const setValueActionTranslations = new Map<SetValueAction, string>(
);
export enum ValueToDataType {
VALUE = 'VALUE',
CONSTANT = 'CONSTANT',
FUNCTION = 'FUNCTION',
NONE = 'NONE'

1
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",

Loading…
Cancel
Save