refactoring

This commit is contained in:
mpetrov 2024-07-25 16:31:58 +03:00
parent 2ff3d0bafc
commit 2837edbbd1
5 changed files with 24 additions and 16 deletions

View File

@ -34,7 +34,7 @@
</tb-toggle-select> </tb-toggle-select>
</div> </div>
<div class="tb-form-panel no-border no-padding padding-top"> <div class="tb-form-panel no-border no-padding padding-top">
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial" <div *ngIf="protocolType !== ModbusProtocolType.Serial"
class="tb-form-row column-xs" class="tb-form-row column-xs"
fxLayoutAlign="space-between center" fxLayoutAlign="space-between center"
> >
@ -54,7 +54,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial else serialPort" <div *ngIf="protocolType !== ModbusProtocolType.Serial else serialPort"
class="tb-form-row column-xs" class="tb-form-row column-xs"
fxLayoutAlign="space-between center" fxLayoutAlign="space-between center"
> >
@ -102,7 +102,7 @@
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
<mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="method"> <mat-select formControlName="method">
<mat-option *ngFor="let method of slaveConfigFormGroup.get('type').value === ModbusProtocolType.Serial ? modbusSerialMethodTypes : modbusMethodTypes" <mat-option *ngFor="let method of protocolType === ModbusProtocolType.Serial ? modbusSerialMethodTypes : modbusMethodTypes"
[value]="method">{{ ModbusMethodLabelsMap.get(method) }}</mat-option> [value]="method">{{ ModbusMethodLabelsMap.get(method) }}</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
@ -168,7 +168,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value === ModbusProtocolType.Serial" class="tb-form-row column-xs" fxLayoutAlign="space-between center"> <div *ngIf="protocolType === ModbusProtocolType.Serial" class="tb-form-row column-xs" fxLayoutAlign="space-between center">
<div class="fixed-title-width" translate>gateway.baudrate</div> <div class="fixed-title-width" translate>gateway.baudrate</div>
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
<mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
@ -196,7 +196,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial" class="tb-form-panel stroked tb-slide-toggle"> <div *ngIf="protocolType !== ModbusProtocolType.Serial" class="tb-form-panel stroked tb-slide-toggle">
<mat-expansion-panel class="tb-settings" [expanded]="showSecurityControl.value"> <mat-expansion-panel class="tb-settings" [expanded]="showSecurityControl.value">
<mat-expansion-panel-header fxLayout="row wrap"> <mat-expansion-panel-header fxLayout="row wrap">
<mat-panel-title> <mat-panel-title>

View File

@ -134,6 +134,10 @@ export class ModbusSlaveConfigComponent implements ControlValueAccessor, Validat
return this.slaveConfigFormGroup.get('sendDataToThingsBoard').value; return this.slaveConfigFormGroup.get('sendDataToThingsBoard').value;
} }
get protocolType(): ModbusProtocolType {
return this.slaveConfigFormGroup.get('type').value;
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next();
this.destroy$.complete(); this.destroy$.complete();
@ -207,7 +211,7 @@ export class ModbusSlaveConfigComponent implements ControlValueAccessor, Validat
this.showSecurityControl.disable({emitEvent: false}); this.showSecurityControl.disable({emitEvent: false});
this.slaveConfigFormGroup.get('sendDataToThingsBoard').enable({emitEvent: false}); this.slaveConfigFormGroup.get('sendDataToThingsBoard').enable({emitEvent: false});
} }
this.updateEnablingByProtocol(this.slaveConfigFormGroup.get('type').value); this.updateEnablingByProtocol(this.protocolType);
this.updateSecurityEnable(this.showSecurityControl.value); this.updateSecurityEnable(this.showSecurityControl.value);
} }
@ -218,7 +222,7 @@ export class ModbusSlaveConfigComponent implements ControlValueAccessor, Validat
} }
private updateSecurityEnable(securityEnabled: boolean): void { private updateSecurityEnable(securityEnabled: boolean): void {
if (securityEnabled && this.isSlaveEnabled) { if (securityEnabled && this.isSlaveEnabled && this.protocolType !== ModbusProtocolType.Serial) {
this.slaveConfigFormGroup.get('security').enable({emitEvent: false}); this.slaveConfigFormGroup.get('security').enable({emitEvent: false});
} else { } else {
this.slaveConfigFormGroup.get('security').disable({emitEvent: false}); this.slaveConfigFormGroup.get('security').disable({emitEvent: false});

View File

@ -53,7 +53,7 @@
</tb-toggle-select> </tb-toggle-select>
</div> </div>
<div class="tb-form-panel no-border no-padding padding-top"> <div class="tb-form-panel no-border no-padding padding-top">
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial" <div *ngIf="protocolType !== ModbusProtocolType.Serial"
class="tb-form-row column-xs" class="tb-form-row column-xs"
fxLayoutAlign="space-between center" fxLayoutAlign="space-between center"
> >
@ -73,7 +73,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial else serialPort" <div *ngIf="protocolType !== ModbusProtocolType.Serial else serialPort"
class="tb-form-row column-xs" class="tb-form-row column-xs"
fxLayoutAlign="space-between center" fxLayoutAlign="space-between center"
> >
@ -122,14 +122,14 @@
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
<mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="method"> <mat-select formControlName="method">
<mat-option *ngFor="let method of slaveConfigFormGroup.get('type').value === ModbusProtocolType.Serial ? modbusSerialMethodTypes : modbusMethodTypes" <mat-option *ngFor="let method of protocolType === ModbusProtocolType.Serial ? modbusSerialMethodTypes : modbusMethodTypes"
[value]="method">{{ ModbusMethodLabelsMap.get(method) }}</mat-option> [value]="method">{{ ModbusMethodLabelsMap.get(method) }}</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
</div> </div>
<ng-container *ngIf="this.slaveConfigFormGroup.get('type').value === ModbusProtocolType.Serial"> <ng-container *ngIf="protocolType === ModbusProtocolType.Serial">
<div class="tb-form-row column-xs" fxLayoutAlign="space-between center"> <div class="tb-form-row column-xs" fxLayoutAlign="space-between center">
<div class="fixed-title-width" translate>gateway.baudrate</div> <div class="fixed-title-width" translate>gateway.baudrate</div>
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
@ -260,7 +260,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial" class="tb-form-row column-xs" fxLayoutAlign="space-between center"> <div *ngIf="protocolType !== ModbusProtocolType.Serial" class="tb-form-row column-xs" fxLayoutAlign="space-between center">
<div class="fixed-title-width" translate>gateway.word-order</div> <div class="fixed-title-width" translate>gateway.word-order</div>
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
<mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
@ -270,7 +270,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div *ngIf="this.slaveConfigFormGroup.get('type').value !== ModbusProtocolType.Serial" class="tb-form-panel stroked tb-slide-toggle"> <div *ngIf="protocolType !== ModbusProtocolType.Serial" class="tb-form-panel stroked tb-slide-toggle">
<mat-expansion-panel class="tb-settings" [expanded]="showSecurityControl.value"> <mat-expansion-panel class="tb-settings" [expanded]="showSecurityControl.value">
<mat-expansion-panel-header fxLayout="row wrap"> <mat-expansion-panel-header fxLayout="row wrap">
<mat-panel-title> <mat-panel-title>
@ -356,7 +356,7 @@
<button mat-raised-button color="primary" <button mat-raised-button color="primary"
(click)="add()" (click)="add()"
[disabled]="slaveConfigFormGroup.invalid || !slaveConfigFormGroup.dirty"> [disabled]="slaveConfigFormGroup.invalid || !slaveConfigFormGroup.dirty">
{{ this.data.buttonTitle | translate }} {{ data.buttonTitle | translate }}
</button> </button>
</div> </div>
</div> </div>

View File

@ -128,6 +128,10 @@ export class ModbusSlaveDialogComponent extends DialogComponent<ModbusSlaveDialo
this.showSecurityControl.patchValue(!!this.data.value.security && !isEqual(this.data.value.security, {})); this.showSecurityControl.patchValue(!!this.data.value.security && !isEqual(this.data.value.security, {}));
} }
get protocolType(): ModbusProtocolType {
return this.slaveConfigFormGroup.get('type').value;
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next();
this.destroy$.complete(); this.destroy$.complete();
@ -236,7 +240,7 @@ export class ModbusSlaveDialogComponent extends DialogComponent<ModbusSlaveDialo
} }
private updateSecurityEnabling(isEnabled: boolean): void { private updateSecurityEnabling(isEnabled: boolean): void {
if (isEnabled) { if (isEnabled && this.protocolType !== ModbusProtocolType.Serial) {
this.slaveConfigFormGroup.get('security').enable({emitEvent: false}); this.slaveConfigFormGroup.get('security').enable({emitEvent: false});
} else { } else {
this.slaveConfigFormGroup.get('security').disable({emitEvent: false}); this.slaveConfigFormGroup.get('security').disable({emitEvent: false});

View File

@ -200,7 +200,7 @@
"timeseries": [ "timeseries": [
{ {
"address": 2, "address": 2,
"type": "int", "type": "8int",
"tag": "smm", "tag": "smm",
"objectsCount": 1, "objectsCount": 1,
"value": "12334" "value": "12334"