From 0805ee5de2acf14c216d10ed5dad917512bbaff6 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Wed, 10 Jul 2024 14:59:29 +0300 Subject: [PATCH 1/2] Added 'With Response' to MQTT templates and removed Response Time when With Response = false --- ...teway-service-rpc-connector.component.html | 6 ++--- ...gateway-service-rpc-connector.component.ts | 23 ++++++++++++------- .../shared/pipe/key-value-not-empty.pipe.ts | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html index 3b590e3872..eb428bebdc 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html @@ -31,15 +31,15 @@ - + {{ 'gateway.rpc.withResponse' | translate }} - + {{ 'gateway.rpc.responseTopicExpression' | translate }} - + {{ 'gateway.rpc.responseTimeout' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts index c515cbc201..e35061a611 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts @@ -53,7 +53,7 @@ import { } from '@shared/components/dialog/json-object-edit-dialog.component'; import { jsonRequired } from '@shared/components/json-object-edit.component'; import { deepClone } from '@core/utils'; -import { takeUntil, tap } from "rxjs/operators"; +import { filter, takeUntil, tap } from "rxjs/operators"; import { Subject } from "rxjs"; @Component({ @@ -80,7 +80,6 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C saveTemplate: EventEmitter = new EventEmitter(); commandForm: FormGroup; - isMQTTWithResponse: FormControl; codesArray: Array = [1, 2, 3, 4, 5, 6, 15, 16]; ConnectorType = ConnectorType; modbusCommandTypes = Object.values(ModbusCommandTypes) as ModbusCommandTypes[]; @@ -135,7 +134,6 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C this.propagateChange({...this.commandForm.value, ...value}); } }); - this.isMQTTWithResponse = this.fb.control(false); this.observeMQTTWithResponse(); } @@ -153,9 +151,10 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], responseTopicExpression: [{ value: null, disabled: true }, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]], + responseTimeout: [{ value: null, disabled: true }, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]], valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - }) + withResponse: [false, []], + }); break; case ConnectorType.MODBUS: formGroup = this.fb.group({ @@ -407,10 +406,18 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C } private observeMQTTWithResponse(): void { - this.isMQTTWithResponse.valueChanges.pipe( + this.commandForm.get('withResponse').valueChanges.pipe( + filter(() => this.connectorType === ConnectorType.MQTT), tap((isActive: boolean) => { - const responseControl = this.commandForm.get('responseTopicExpression'); - isActive ? responseControl.enable() : responseControl.disable(); + const responseTopicControl = this.commandForm.get('responseTopicExpression'); + const responseTimeoutControl = this.commandForm.get('responseTimeout'); + if (isActive) { + responseTopicControl.enable(); + responseTimeoutControl.enable(); + } else { + responseTopicControl.disable(); + responseTimeoutControl.disable(); + } }), takeUntil(this.destroy$), ).subscribe(); diff --git a/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts b/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts index 94eeced50e..08afba9d81 100644 --- a/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts +++ b/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts @@ -62,6 +62,6 @@ export class KeyValueIsNotEmptyPipe implements PipeTransform { } private makeKeyValuePair(key: string, value: unknown): KeyValue { - return {key: key, value: value}; + return {key, value}; } } From 78136e2734da9754580654677d0d30d80efb93f6 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Wed, 10 Jul 2024 15:04:55 +0300 Subject: [PATCH 2/2] refactoring --- ...gateway-service-rpc-connector.component.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts index e35061a611..3027cafa8d 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts @@ -406,20 +406,21 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C } private observeMQTTWithResponse(): void { - this.commandForm.get('withResponse').valueChanges.pipe( - filter(() => this.connectorType === ConnectorType.MQTT), - tap((isActive: boolean) => { - const responseTopicControl = this.commandForm.get('responseTopicExpression'); - const responseTimeoutControl = this.commandForm.get('responseTimeout'); - if (isActive) { - responseTopicControl.enable(); - responseTimeoutControl.enable(); - } else { - responseTopicControl.disable(); - responseTimeoutControl.disable(); - } - }), - takeUntil(this.destroy$), - ).subscribe(); + if (this.connectorType === ConnectorType.MQTT) { + this.commandForm.get('withResponse').valueChanges.pipe( + tap((isActive: boolean) => { + const responseTopicControl = this.commandForm.get('responseTopicExpression'); + const responseTimeoutControl = this.commandForm.get('responseTimeout'); + if (isActive) { + responseTopicControl.enable(); + responseTimeoutControl.enable(); + } else { + responseTopicControl.disable(); + responseTimeoutControl.disable(); + } + }), + takeUntil(this.destroy$), + ).subscribe(); + } } }