();
+
+ functionScopeVariables = this.widgetService.getWidgetScopeVariables();
+
+ panelTitle: string;
+
+ behaviorFormGroup: UntypedFormGroup;
+
+ constructor(private fb: UntypedFormBuilder,
+ private widgetService: WidgetService) {
+ }
+
+ ngOnInit(): void {
+ this.panelTitle = this.isAdd ? 'scada.behavior.add-behavior' : 'scada.behavior.behavior-settings';
+ this.behaviorFormGroup = this.fb.group(
+ {
+ id: [this.behavior.id, [Validators.required]],
+ name: [this.behavior.name, [Validators.required]],
+ hint: [this.behavior.hint, []],
+ type: [this.behavior.type, [Validators.required]],
+ valueType: [this.behavior.valueType, [Validators.required]],
+ defaultValue: [this.behavior.defaultValue, [Validators.required]],
+ trueLabel: [this.behavior.trueLabel, []],
+ falseLabel: [this.behavior.falseLabel, []],
+ stateLabel: [this.behavior.stateLabel, []],
+ valueToDataType: [this.behavior.valueToDataType, [Validators.required]],
+ constantValue: [this.behavior.constantValue, [Validators.required]],
+ valueToDataFunction: [this.behavior.valueToDataFunction, [Validators.required]]
+ }
+ );
+ merge(this.behaviorFormGroup.get('type').valueChanges,
+ this.behaviorFormGroup.get('valueType').valueChanges,
+ this.behaviorFormGroup.get('valueToDataType').valueChanges).subscribe(() => {
+ this.updateValidators();
+ });
+ this.updateValidators();
+ }
+
+ cancel() {
+ this.popover?.hide();
+ }
+
+ applyBehaviorSettings() {
+ const behavior = this.behaviorFormGroup.getRawValue();
+ this.behaviorSettingsApplied.emit(behavior);
+ }
+
+ private updateValidators() {
+ const type: IotSvgBehaviorType = this.behaviorFormGroup.get('type').value;
+ const valueType: ValueType = this.behaviorFormGroup.get('valueType').value;
+ let valueToDataType: ValueToDataType = this.behaviorFormGroup.get('valueToDataType').value;
+ this.behaviorFormGroup.disable({emitEvent: false});
+ this.behaviorFormGroup.get('id').enable({emitEvent: false});
+ this.behaviorFormGroup.get('name').enable({emitEvent: false});
+ this.behaviorFormGroup.get('type').enable({emitEvent: false});
+ this.behaviorFormGroup.get('hint').enable({emitEvent: false});
+ switch (type) {
+ case IotSvgBehaviorType.value:
+ this.behaviorFormGroup.get('valueType').enable({emitEvent: false});
+ this.behaviorFormGroup.get('defaultValue').enable({emitEvent: false});
+ if (valueType === ValueType.BOOLEAN) {
+ this.behaviorFormGroup.get('trueLabel').enable({emitEvent: false});
+ this.behaviorFormGroup.get('falseLabel').enable({emitEvent: false});
+ this.behaviorFormGroup.get('stateLabel').enable({emitEvent: false});
+ }
+ break;
+ case IotSvgBehaviorType.action:
+ if (valueType === ValueType.BOOLEAN && valueToDataType === ValueToDataType.VALUE) {
+ this.behaviorFormGroup.patchValue({valueToDataType: ValueToDataType.CONSTANT}, {emitEvent: false});
+ valueToDataType = ValueToDataType.CONSTANT;
+ } else if (valueType !== ValueType.BOOLEAN && valueToDataType === ValueToDataType.CONSTANT) {
+ this.behaviorFormGroup.patchValue({valueToDataType: ValueToDataType.VALUE}, {emitEvent: false});
+ valueToDataType = ValueToDataType.VALUE;
+ }
+ this.behaviorFormGroup.get('valueType').enable({emitEvent: false});
+ this.behaviorFormGroup.get('valueToDataType').enable({emitEvent: false});
+ if (valueToDataType === ValueToDataType.CONSTANT) {
+ this.behaviorFormGroup.get('constantValue').enable({emitEvent: false});
+ } else if (valueToDataType === ValueToDataType.FUNCTION) {
+ this.behaviorFormGroup.get('valueToDataFunction').enable({emitEvent: false});
+ }
+ break;
+ case IotSvgBehaviorType.widgetAction:
+ break;
+ }
+ }
+}
diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-behavior-row.component.html b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-behavior-row.component.html
index 5b9c4d2cf9..766cce736b 100644
--- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-behavior-row.component.html
+++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-behavior-row.component.html
@@ -32,7 +32,8 @@