Browse Source

Added 'With Response' to MQTT templates and removed Response Time when With Response = false

pull/11185/head
mpetrov 2 years ago
parent
commit
0805ee5de2
  1. 6
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html
  2. 23
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts
  3. 2
      ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts

6
ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html

@ -31,15 +31,15 @@
<input matInput formControlName="requestTopicExpression" <input matInput formControlName="requestTopicExpression"
placeholder="sensor/${deviceName}/request/${methodName}/${requestId}"/> placeholder="sensor/${deviceName}/request/${methodName}/${requestId}"/>
</mat-form-field> </mat-form-field>
<mat-slide-toggle class="margin" (click)="$event.stopPropagation()" [formControl]="isMQTTWithResponse"> <mat-slide-toggle class="margin" (click)="$event.stopPropagation()" formControlName="withResponse">
{{ 'gateway.rpc.withResponse' | translate }} {{ 'gateway.rpc.withResponse' | translate }}
</mat-slide-toggle> </mat-slide-toggle>
<mat-form-field *ngIf="isMQTTWithResponse.value"> <mat-form-field *ngIf="commandForm.get('withResponse')?.value">
<mat-label>{{ 'gateway.rpc.responseTopicExpression' | translate }}</mat-label> <mat-label>{{ 'gateway.rpc.responseTopicExpression' | translate }}</mat-label>
<input matInput formControlName="responseTopicExpression" <input matInput formControlName="responseTopicExpression"
placeholder="sensor/${deviceName}/response/${methodName}/${requestId}"/> placeholder="sensor/${deviceName}/response/${methodName}/${requestId}"/>
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="isMQTTWithResponse.value"> <mat-form-field *ngIf="commandForm.get('withResponse')?.value">
<mat-label>{{ 'gateway.rpc.responseTimeout' | translate }}</mat-label> <mat-label>{{ 'gateway.rpc.responseTimeout' | translate }}</mat-label>
<input matInput formControlName="responseTimeout" type="number" <input matInput formControlName="responseTimeout" type="number"
placeholder="10000" min="10" step="1"/> placeholder="10000" min="10" step="1"/>

23
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'; } from '@shared/components/dialog/json-object-edit-dialog.component';
import { jsonRequired } from '@shared/components/json-object-edit.component'; import { jsonRequired } from '@shared/components/json-object-edit.component';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { takeUntil, tap } from "rxjs/operators"; import { filter, takeUntil, tap } from "rxjs/operators";
import { Subject } from "rxjs"; import { Subject } from "rxjs";
@Component({ @Component({
@ -80,7 +80,6 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
saveTemplate: EventEmitter<RPCTemplateConfig> = new EventEmitter(); saveTemplate: EventEmitter<RPCTemplateConfig> = new EventEmitter();
commandForm: FormGroup; commandForm: FormGroup;
isMQTTWithResponse: FormControl;
codesArray: Array<number> = [1, 2, 3, 4, 5, 6, 15, 16]; codesArray: Array<number> = [1, 2, 3, 4, 5, 6, 15, 16];
ConnectorType = ConnectorType; ConnectorType = ConnectorType;
modbusCommandTypes = Object.values(ModbusCommandTypes) as ModbusCommandTypes[]; modbusCommandTypes = Object.values(ModbusCommandTypes) as ModbusCommandTypes[];
@ -135,7 +134,6 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
this.propagateChange({...this.commandForm.value, ...value}); this.propagateChange({...this.commandForm.value, ...value});
} }
}); });
this.isMQTTWithResponse = this.fb.control(false);
this.observeMQTTWithResponse(); this.observeMQTTWithResponse();
} }
@ -153,9 +151,10 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
responseTopicExpression: [{ value: null, disabled: true }, [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)]], valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
}) withResponse: [false, []],
});
break; break;
case ConnectorType.MODBUS: case ConnectorType.MODBUS:
formGroup = this.fb.group({ formGroup = this.fb.group({
@ -407,10 +406,18 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
} }
private observeMQTTWithResponse(): void { private observeMQTTWithResponse(): void {
this.isMQTTWithResponse.valueChanges.pipe( this.commandForm.get('withResponse').valueChanges.pipe(
filter(() => this.connectorType === ConnectorType.MQTT),
tap((isActive: boolean) => { tap((isActive: boolean) => {
const responseControl = this.commandForm.get('responseTopicExpression'); const responseTopicControl = this.commandForm.get('responseTopicExpression');
isActive ? responseControl.enable() : responseControl.disable(); const responseTimeoutControl = this.commandForm.get('responseTimeout');
if (isActive) {
responseTopicControl.enable();
responseTimeoutControl.enable();
} else {
responseTopicControl.disable();
responseTimeoutControl.disable();
}
}), }),
takeUntil(this.destroy$), takeUntil(this.destroy$),
).subscribe(); ).subscribe();

2
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<string, unknown> { private makeKeyValuePair(key: string, value: unknown): KeyValue<string, unknown> {
return {key: key, value: value}; return {key, value};
} }
} }

Loading…
Cancel
Save