Browse Source

refactoring

pull/11235/head
mpetrov 2 years ago
parent
commit
2837edbbd1
  1. 10
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-config/modbus-slave-config.component.html
  2. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-config/modbus-slave-config.component.ts
  3. 14
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-dialog/modbus-slave-dialog.component.html
  4. 6
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-dialog/modbus-slave-dialog.component.ts
  5. 2
      ui-ngx/src/assets/metadata/connector-default-configs/modbus.json

10
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-config/modbus-slave-config.component.html

@ -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>

8
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-config/modbus-slave-config.component.ts

@ -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});

14
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-dialog/modbus-slave-dialog.component.html

@ -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>

6
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-slave-dialog/modbus-slave-dialog.component.ts

@ -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});

2
ui-ngx/src/assets/metadata/connector-default-configs/modbus.json

@ -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"

Loading…
Cancel
Save