|
|
|
@ -14,7 +14,7 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, forwardRef, Input, OnInit } from '@angular/core'; |
|
|
|
import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { |
|
|
|
ControlValueAccessor, |
|
|
|
FormBuilder, |
|
|
|
@ -39,6 +39,8 @@ import { |
|
|
|
transportPayloadTypeTranslationMap |
|
|
|
} from '@shared/models/device.models'; |
|
|
|
import { isDefinedAndNotNull } from '@core/utils'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-mqtt-device-profile-transport-configuration', |
|
|
|
@ -50,7 +52,7 @@ import { isDefinedAndNotNull } from '@core/utils'; |
|
|
|
multi: true |
|
|
|
}] |
|
|
|
}) |
|
|
|
export class MqttDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit { |
|
|
|
export class MqttDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy { |
|
|
|
|
|
|
|
transportPayloadTypes = Object.keys(TransportPayloadType); |
|
|
|
|
|
|
|
@ -58,6 +60,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
|
|
|
|
mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; |
|
|
|
|
|
|
|
private destroy$ = new Subject(); |
|
|
|
private requiredValue: boolean; |
|
|
|
|
|
|
|
get required(): boolean { |
|
|
|
@ -98,15 +101,23 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
}) |
|
|
|
}, {validator: this.uniqueDeviceTopicValidator} |
|
|
|
); |
|
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType') |
|
|
|
.valueChanges.subscribe(payloadType => { |
|
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType').valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe(payloadType => { |
|
|
|
this.updateTransportPayloadBasedControls(payloadType, true); |
|
|
|
}); |
|
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { |
|
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe(() => { |
|
|
|
this.updateModel(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
|
this.destroy$.next(); |
|
|
|
this.destroy$.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
setDisabledState(isDisabled: boolean): void { |
|
|
|
this.disabled = isDisabled; |
|
|
|
if (this.disabled) { |
|
|
|
@ -192,8 +203,8 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
} |
|
|
|
|
|
|
|
private uniqueDeviceTopicValidator(control: FormGroup): { [key: string]: boolean } | null { |
|
|
|
if (control.value) { |
|
|
|
const formValue = control.value as MqttDeviceProfileTransportConfiguration; |
|
|
|
if (control.getRawValue()) { |
|
|
|
const formValue = control.getRawValue() as MqttDeviceProfileTransportConfiguration; |
|
|
|
if (formValue.deviceAttributesTopic === formValue.deviceTelemetryTopic) { |
|
|
|
return {unique: true}; |
|
|
|
} |
|
|
|
|