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 | 63 | </mat-error> |
64 | 64 | </mat-form-field> |
65 | 65 | </div> |
66 | + <mat-error *ngIf="mqttDeviceProfileTransportConfigurationFormGroup.get('configuration').hasError('unique')"> | |
67 | + {{ 'device-profile.mqtt-device-topic-filters-unique' | translate }} | |
68 | + </mat-error> | |
66 | 69 | <div class="tb-hint" innerHTML="{{ 'device-profile.support-level-wildcards' | translate }}"></div> |
67 | 70 | <div class="tb-hint" innerHTML="{{ 'device-profile.single-level-wildcards-hint' | translate }}"></div> |
68 | 71 | <div class="tb-hint" innerHTML="{{ 'device-profile.multi-level-wildcards-hint' | translate }}"></div> | ... | ... |
... | ... | @@ -51,7 +51,6 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
51 | 51 | |
52 | 52 | mqttTransportPayloadTypeTranslations = mqttTransportPayloadTypeTranslationMap; |
53 | 53 | |
54 | - | |
55 | 54 | mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; |
56 | 55 | |
57 | 56 | private requiredValue: boolean; |
... | ... | @@ -87,7 +86,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
87 | 86 | deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
88 | 87 | deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
89 | 88 | transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required] |
90 | - }) | |
89 | + }, {validator: this.uniqueDeviceTopicValidator}) | |
91 | 90 | }); |
92 | 91 | this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { |
93 | 92 | this.updateModel(); |
... | ... | @@ -147,4 +146,14 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
147 | 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 | 885 | "no-device-profiles-found": "No device profiles found.", |
886 | 886 | "create-new-device-profile": "Create a new one!", |
887 | 887 | "mqtt-device-topic-filters": "MQTT device topic filters", |
888 | + "mqtt-device-topic-filters-unique": "MQTT device topic filters need to be unique.", | |
888 | 889 | "mqtt-device-payload-type": "MQTT device payload", |
889 | 890 | "mqtt-device-payload-type-json": "JSON", |
890 | 891 | "mqtt-device-payload-type-proto": "Protobuf", | ... | ... |