|
|
@ -120,6 +120,39 @@ export class ModbusSlaveDialogComponent extends DialogComponent<ModbusSlaveDialo |
|
|
super(store, router, dialogRef); |
|
|
super(store, router, dialogRef); |
|
|
|
|
|
|
|
|
this.showSecurityControl = this.fb.control(false); |
|
|
this.showSecurityControl = this.fb.control(false); |
|
|
|
|
|
this.initializeSlaveFormGroup(); |
|
|
|
|
|
this.updateSlaveFormGroup(); |
|
|
|
|
|
this.updateControlsEnabling(this.data.value.type); |
|
|
|
|
|
this.observeTypeChange(); |
|
|
|
|
|
this.observeShowSecurity(); |
|
|
|
|
|
this.showSecurityControl.patchValue(!!this.data.value.security && !isEqual(this.data.value.security, {})); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
|
|
this.destroy$.next(); |
|
|
|
|
|
this.destroy$.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cancel(): void { |
|
|
|
|
|
this.dialogRef.close(null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
add(): void { |
|
|
|
|
|
if (!this.slaveConfigFormGroup.valid) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { values, type, serialPort, ...rest } = this.slaveConfigFormGroup.value; |
|
|
|
|
|
const slaveResult = { ...rest, ...values }; |
|
|
|
|
|
|
|
|
|
|
|
if (type === ModbusProtocolType.Serial) { |
|
|
|
|
|
slaveResult.port = serialPort; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.dialogRef.close(slaveResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private initializeSlaveFormGroup(): void { |
|
|
this.slaveConfigFormGroup = this.fb.group({ |
|
|
this.slaveConfigFormGroup = this.fb.group({ |
|
|
name: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], |
|
|
name: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], |
|
|
type: [ModbusProtocolType.TCP], |
|
|
type: [ModbusProtocolType.TCP], |
|
|
@ -149,7 +182,9 @@ export class ModbusSlaveDialogComponent extends DialogComponent<ModbusSlaveDialo |
|
|
values: [{}], |
|
|
values: [{}], |
|
|
security: [{}], |
|
|
security: [{}], |
|
|
}); |
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateSlaveFormGroup(): void { |
|
|
this.slaveConfigFormGroup.patchValue({ |
|
|
this.slaveConfigFormGroup.patchValue({ |
|
|
...this.data.value, |
|
|
...this.data.value, |
|
|
port: this.data.value.type === ModbusProtocolType.Serial ? null : this.data.value.port, |
|
|
port: this.data.value.type === ModbusProtocolType.Serial ? null : this.data.value.port, |
|
|
@ -161,37 +196,8 @@ export class ModbusSlaveDialogComponent extends DialogComponent<ModbusSlaveDialo |
|
|
rpc: this.data.value.rpc ?? [], |
|
|
rpc: this.data.value.rpc ?? [], |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.updateControlsEnabling(this.data.value.type); |
|
|
|
|
|
this.observeTypeChange(); |
|
|
|
|
|
this.observeShowSecurity(); |
|
|
|
|
|
this.showSecurityControl.patchValue(!!this.data.value.security && !isEqual(this.data.value.security, {})); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
|
|
this.destroy$.next(); |
|
|
|
|
|
this.destroy$.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cancel(): void { |
|
|
|
|
|
this.dialogRef.close(null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
add(): void { |
|
|
|
|
|
if (!this.slaveConfigFormGroup.valid) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { values, type, serialPort, ...rest } = this.slaveConfigFormGroup.value; |
|
|
|
|
|
const slaveResult = { ...rest, ...values }; |
|
|
|
|
|
|
|
|
|
|
|
if (type === ModbusProtocolType.Serial) { |
|
|
|
|
|
slaveResult.port = serialPort; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.dialogRef.close(slaveResult); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private observeTypeChange(): void { |
|
|
private observeTypeChange(): void { |
|
|
this.slaveConfigFormGroup.get('type').valueChanges |
|
|
this.slaveConfigFormGroup.get('type').valueChanges |
|
|
.pipe(takeUntil(this.destroy$)) |
|
|
.pipe(takeUntil(this.destroy$)) |
|
|
|