Browse Source

[PROD-3727] [FIX] refactoring

pull/10981/head
mpetrov 2 years ago
parent
commit
58f677cd4f
  1. 2
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.html
  2. 20
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector.component.ts

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

@ -35,7 +35,7 @@
{{ 'gateway.rpc.withResponse' | translate }} {{ 'gateway.rpc.withResponse' | translate }}
</mat-slide-toggle> </mat-slide-toggle>
<mat-form-field *ngIf="isMQTTWithResponse.value"> <mat-form-field *ngIf="isMQTTWithResponse.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>

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

@ -159,7 +159,7 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
formGroup = this.fb.group({ formGroup = this.fb.group({
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: [null, [this.requiredOnWithResponse(), Validators.pattern(noLeadTrailSpacesRegex)]], responseTopicExpression: [{ value: null, disabled: true }, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]], responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]],
valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
}) })
@ -436,22 +436,12 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, C
} }
} }
private requiredOnWithResponse(): ValidatorFn {
return (control: UntypedFormControl) => {
const withResponse: boolean = this.isMQTTWithResponse?.value;
if (withResponse && !control.value) {
return { 'required': true };
}
return null;
};
}
private observeMQTTWithResponse(): void { private observeMQTTWithResponse(): void {
this.isMQTTWithResponse.valueChanges.pipe( this.isMQTTWithResponse.valueChanges.pipe(
tap(() => { tap((isActive: boolean) => {
this.commandForm.get('responseTopicExpression').updateValueAndValidity(); const responseControl = this.commandForm.get('responseTopicExpression');
isActive ? responseControl.enable() : responseControl.disable();
responseControl.updateValueAndValidity();
}), }),
takeUntil(this.destroy$), takeUntil(this.destroy$),
).subscribe(); ).subscribe();

Loading…
Cancel
Save