Commit 671dfa7668a5b6279080030552b7367b9c2a17f6
1 parent
81585f04
Add validator to unique MQTT device topic filter
Showing
3 changed files
with
15 additions
and
2 deletions
@@ -63,6 +63,9 @@ | @@ -63,6 +63,9 @@ | ||
63 | </mat-error> | 63 | </mat-error> |
64 | </mat-form-field> | 64 | </mat-form-field> |
65 | </div> | 65 | </div> |
66 | + <mat-error *ngIf="mqttDeviceProfileTransportConfigurationFormGroup.get('configuration').hasError('unique')"> | ||
67 | + {{ 'device-profile.mqtt-device-topic-filters-unique' | translate }} | ||
68 | + </mat-error> | ||
66 | <div class="tb-hint" innerHTML="{{ 'device-profile.support-level-wildcards' | translate }}"></div> | 69 | <div class="tb-hint" innerHTML="{{ 'device-profile.support-level-wildcards' | translate }}"></div> |
67 | <div class="tb-hint" innerHTML="{{ 'device-profile.single-level-wildcards-hint' | translate }}"></div> | 70 | <div class="tb-hint" innerHTML="{{ 'device-profile.single-level-wildcards-hint' | translate }}"></div> |
68 | <div class="tb-hint" innerHTML="{{ 'device-profile.multi-level-wildcards-hint' | translate }}"></div> | 71 | <div class="tb-hint" innerHTML="{{ 'device-profile.multi-level-wildcards-hint' | translate }}"></div> |
@@ -51,7 +51,6 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | @@ -51,7 +51,6 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | ||
51 | 51 | ||
52 | mqttTransportPayloadTypeTranslations = mqttTransportPayloadTypeTranslationMap; | 52 | mqttTransportPayloadTypeTranslations = mqttTransportPayloadTypeTranslationMap; |
53 | 53 | ||
54 | - | ||
55 | mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; | 54 | mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; |
56 | 55 | ||
57 | private requiredValue: boolean; | 56 | private requiredValue: boolean; |
@@ -87,7 +86,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | @@ -87,7 +86,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | ||
87 | deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], | 86 | deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
88 | deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], | 87 | deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
89 | transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required] | 88 | transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required] |
90 | - }) | 89 | + }, {validator: this.uniqueDeviceTopicValidator}) |
91 | }); | 90 | }); |
92 | this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { | 91 | this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { |
93 | this.updateModel(); | 92 | this.updateModel(); |
@@ -147,4 +146,14 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | @@ -147,4 +146,14 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control | ||
147 | return null; | 146 | return null; |
148 | }; | 147 | }; |
149 | } | 148 | } |
149 | + | ||
150 | + private uniqueDeviceTopicValidator(control: FormGroup): { [key: string]: boolean } | null { | ||
151 | + if (control.value) { | ||
152 | + const formValue = control.value as MqttDeviceProfileTransportConfiguration; | ||
153 | + if (formValue.deviceAttributesTopic === formValue.deviceTelemetryTopic) { | ||
154 | + return {unique: true}; | ||
155 | + } | ||
156 | + } | ||
157 | + return null; | ||
158 | + } | ||
150 | } | 159 | } |
@@ -885,6 +885,7 @@ | @@ -885,6 +885,7 @@ | ||
885 | "no-device-profiles-found": "No device profiles found.", | 885 | "no-device-profiles-found": "No device profiles found.", |
886 | "create-new-device-profile": "Create a new one!", | 886 | "create-new-device-profile": "Create a new one!", |
887 | "mqtt-device-topic-filters": "MQTT device topic filters", | 887 | "mqtt-device-topic-filters": "MQTT device topic filters", |
888 | + "mqtt-device-topic-filters-unique": "MQTT device topic filters need to be unique.", | ||
888 | "mqtt-device-payload-type": "MQTT device payload", | 889 | "mqtt-device-payload-type": "MQTT device payload", |
889 | "mqtt-device-payload-type-json": "JSON", | 890 | "mqtt-device-payload-type-json": "JSON", |
890 | "mqtt-device-payload-type-proto": "Protobuf", | 891 | "mqtt-device-payload-type-proto": "Protobuf", |