diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html index a31fe4ff94..f72a2c18af 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html @@ -24,7 +24,7 @@ -
{{ valueTitle(keyControl.get('value').value) }}
+
{{ valueTitle(keyControl.get(keyControl.get('type').value).value) }}
@@ -54,13 +54,24 @@
gateway.value
- + + + + + + true + false + + warning diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss index 687025e729..770f17cac6 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss @@ -18,9 +18,6 @@ .title-container { max-width: 11vw; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap } .key-panel { diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts index 32d0b2bddb..8e1c6fdb57 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts @@ -18,6 +18,7 @@ import { Component, forwardRef, OnDestroy, OnInit } from '@angular/core'; import { AbstractControl, ControlValueAccessor, + FormGroup, NG_VALIDATORS, NG_VALUE_ACCESSOR, UntypedFormArray, @@ -28,6 +29,7 @@ import { } from '@angular/forms'; import { isDefinedAndNotNull } from '@core/utils'; import { + integerRegex, MappingDataKey, MappingValueType, mappingValueTypesMap, @@ -58,6 +60,7 @@ export class TypeValuePanelComponent implements ControlValueAccessor, Validator, valueTypeKeys: MappingValueType[] = Object.values(MappingValueType); valueTypes = mappingValueTypesMap; valueListFormArray: UntypedFormArray; + readonly MappingValueType = MappingValueType; private destroy$ = new Subject(); private propagateChange = (v: any) => {}; @@ -84,12 +87,26 @@ export class TypeValuePanelComponent implements ControlValueAccessor, Validator, addKey(): void { const dataKeyFormGroup = this.fb.group({ - type: [MappingValueType.STRING, []], - value: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] + type: [MappingValueType.STRING], + string: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + integer: [{value: 0, disabled: true}, [Validators.required, Validators.pattern(integerRegex)]], + double: [{value: 0, disabled: true}, [Validators.required]], + boolean: [{value: false, disabled: true}, [Validators.required]], }); + this.observeTypeChange(dataKeyFormGroup); this.valueListFormArray.push(dataKeyFormGroup); } + private observeTypeChange(dataKeyFormGroup: FormGroup): void { + dataKeyFormGroup.get('type').valueChanges + .pipe(takeUntil(this.destroy$)) + .subscribe(type => { + dataKeyFormGroup.disable({emitEvent: false}); + dataKeyFormGroup.get('type').enable({emitEvent: false}); + dataKeyFormGroup.get(type).enable({emitEvent: false}); + }) + } + deleteKey($event: Event, index: number): void { if ($event) { $event.stopPropagation(); @@ -116,10 +133,17 @@ export class TypeValuePanelComponent implements ControlValueAccessor, Validator, writeValue(deviceInfoArray: Array): void { for (const deviceInfo of deviceInfoArray) { - const dataKeyFormGroup = this.fb.group({ - type: [deviceInfo.type, []], - value: [deviceInfo.value, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] - }); + const config = { + type: [deviceInfo.type], + string: [{value: '', disabled: true}, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + integer: [{value: 0, disabled: true}, [Validators.required, Validators.pattern(integerRegex)]], + double: [{value: 0, disabled: true}, [Validators.required]], + boolean: [{value: false, disabled: true}, [Validators.required]], + }; + config[deviceInfo.type][0] = {value: deviceInfo.value, disabled: false}; + + const dataKeyFormGroup = this.fb.group(config); + this.observeTypeChange(dataKeyFormGroup); this.valueListFormArray.push(dataKeyFormGroup); } } @@ -131,6 +155,6 @@ export class TypeValuePanelComponent implements ControlValueAccessor, Validator, } private updateView(value: any): void { - this.propagateChange(value); + this.propagateChange(value.map(({type, ...config}) => ({type, value: config[type]}))); } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts index 8df3994ea2..3f3f39f2bc 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts @@ -19,6 +19,7 @@ import { Observable } from 'rxjs'; import { ValueTypeData } from '@shared/models/constants'; export const noLeadTrailSpacesRegex = /^(?! )[\S\s]*(?