fix mqtt-device-profile-transport-configuration.component.ts
This commit is contained in:
parent
37c381996e
commit
19c860ebfb
@ -90,6 +90,11 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
|
|||||||
transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required],
|
transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required],
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
let configurationFormGroup = this.mqttDeviceProfileTransportConfigurationFormGroup.controls.configuration as FormGroup;
|
||||||
|
configurationFormGroup.get('transportPayloadType').valueChanges.subscribe(payloadType => {
|
||||||
|
this.onTransportPayloadTypeChanged(payloadType, configurationFormGroup);
|
||||||
|
this.mqttDeviceProfileTransportConfigurationFormGroup.updateValueAndValidity();
|
||||||
|
});
|
||||||
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => {
|
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => {
|
||||||
this.updateModel();
|
this.updateModel();
|
||||||
});
|
});
|
||||||
@ -112,11 +117,8 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
|
|||||||
writeValue(value: MqttDeviceProfileTransportConfiguration | null): void {
|
writeValue(value: MqttDeviceProfileTransportConfiguration | null): void {
|
||||||
if (isDefinedAndNotNull(value)) {
|
if (isDefinedAndNotNull(value)) {
|
||||||
let configurationFormGroup = this.mqttDeviceProfileTransportConfigurationFormGroup.controls.configuration as FormGroup;
|
let configurationFormGroup = this.mqttDeviceProfileTransportConfigurationFormGroup.controls.configuration as FormGroup;
|
||||||
let payloadType = value.transportPayloadType;
|
let type = value.transportPayloadType;
|
||||||
if (payloadType === MqttTransportPayloadType.PROTOBUF) {
|
this.updateTransportPayloadBasedControls(type, configurationFormGroup);
|
||||||
configurationFormGroup.registerControl('deviceTelemetryProtoSchema', this.fb.control(null, Validators.required));
|
|
||||||
configurationFormGroup.registerControl('deviceAttributesProtoSchema', this.fb.control(null, Validators.required));
|
|
||||||
}
|
|
||||||
this.mqttDeviceProfileTransportConfigurationFormGroup.patchValue({configuration: value}, {emitEvent: false});
|
this.mqttDeviceProfileTransportConfigurationFormGroup.patchValue({configuration: value}, {emitEvent: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,9 +128,16 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
|
|||||||
if (this.mqttDeviceProfileTransportConfigurationFormGroup.valid) {
|
if (this.mqttDeviceProfileTransportConfigurationFormGroup.valid) {
|
||||||
configuration = this.mqttDeviceProfileTransportConfigurationFormGroup.getRawValue().configuration;
|
configuration = this.mqttDeviceProfileTransportConfigurationFormGroup.getRawValue().configuration;
|
||||||
configuration.type = DeviceTransportType.MQTT;
|
configuration.type = DeviceTransportType.MQTT;
|
||||||
let configurationFormGroup = this.mqttDeviceProfileTransportConfigurationFormGroup.controls.configuration as FormGroup;
|
}
|
||||||
let transportPayloadType = configuration.transportPayloadType;
|
this.propagateChange(configuration);
|
||||||
if (transportPayloadType === MqttTransportPayloadType.PROTOBUF) {
|
}
|
||||||
|
|
||||||
|
private onTransportPayloadTypeChanged(type: MqttTransportPayloadType, configurationFormGroup: FormGroup) {
|
||||||
|
this.updateTransportPayloadBasedControls(type, configurationFormGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateTransportPayloadBasedControls(type: MqttTransportPayloadType, configurationFormGroup: FormGroup) {
|
||||||
|
if (type === MqttTransportPayloadType.PROTOBUF) {
|
||||||
configurationFormGroup.registerControl('deviceTelemetryProtoSchema', this.fb.control(null, Validators.required));
|
configurationFormGroup.registerControl('deviceTelemetryProtoSchema', this.fb.control(null, Validators.required));
|
||||||
configurationFormGroup.registerControl('deviceAttributesProtoSchema', this.fb.control(null, Validators.required));
|
configurationFormGroup.registerControl('deviceAttributesProtoSchema', this.fb.control(null, Validators.required));
|
||||||
} else {
|
} else {
|
||||||
@ -136,8 +145,6 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
|
|||||||
configurationFormGroup.removeControl('deviceAttributesProtoSchema');
|
configurationFormGroup.removeControl('deviceAttributesProtoSchema');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.propagateChange(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
private validationMQTTTopic(): ValidatorFn {
|
private validationMQTTTopic(): ValidatorFn {
|
||||||
return (c: FormControl) => {
|
return (c: FormControl) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user