diff --git a/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.html index d99ddfa554..7ca331b946 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.html @@ -21,6 +21,24 @@
+ + device-profile.mqtt-device-topic-filters-spark-plug-attribute-metric-names + + + {{name}} + close + + + + +
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts index 4a81284d5c..dfed5099e2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts @@ -41,6 +41,8 @@ import { import { isDefinedAndNotNull } from '@core/utils'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; +import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; +import { MatChipInputEvent } from '@angular/material/chips'; @Component({ selector: 'tb-mqtt-device-profile-transport-configuration', @@ -77,6 +79,8 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control private propagateChange = (v: any) => { }; + separatorKeysCodes = [ENTER, COMMA, SEMICOLON]; + constructor(private store: Store, private fb: FormBuilder) { } @@ -93,6 +97,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], sparkPlug: [false], + sparkPlugAttributesMetricNames: [null], sendAckOnValidationException: [false, Validators.required], transportPayloadTypeConfiguration: this.fb.group({ transportPayloadType: [TransportPayloadType.JSON, Validators.required], @@ -124,6 +129,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control if (value) { this.mqttDeviceProfileTransportConfigurationFormGroup.disable({emitEvent: false}); this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlug').enable({emitEvent: false}); + this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').enable({emitEvent: false}); } else { this.mqttDeviceProfileTransportConfigurationFormGroup.enable({emitEvent: false}); } @@ -169,6 +175,34 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control } } + removeAttributeMetricName(name: string): void { + const names: string[] = this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').value; + const index = names.indexOf(name); + if (index >= 0) { + names.splice(index, 1); + this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').setValue(names); + } + } + + addAttributeMetricName(event: MatChipInputEvent): void { + const input = event.input; + let value = event.value; + if ((value || '').trim()) { + value = value.trim(); + let names: string[] = this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').value; + if (!names || names.indexOf(value) === -1) { + if (!names) { + names = []; + } + names.push(value); + this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').setValue(names, {emitEvent: true}); + } + } + if (input) { + input.value = ''; + } + } + private updateModel() { let configuration: DeviceProfileTransportConfiguration = null; if (this.mqttDeviceProfileTransportConfigurationFormGroup.valid) { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 104ebc8887..5aef433a09 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1355,6 +1355,8 @@ "mqtt-device-topic-filters-unique": "MQTT device topic filters need to be unique.", "mqtt-device-topic-filters-spark-plug": "MQTT device topic filters SparkPlug.", "mqtt-device-topic-filters-spark-plug-hint": "Default - telemetry. Example: namespace/group_id/message_type/edge_node_id/[device_id].", + "mqtt-device-topic-filters-spark-plug-attribute-metric-names": "SparkPlug attributes metric names", + "mqtt-device-topic-filters-spark-plug-attribute-metric-names-hint": "Names of SparkPlug metrics that will be stored as device attributes. All other metrics will be stored as device telemetry", "mqtt-device-payload-type": "MQTT device payload", "mqtt-device-payload-type-json": "JSON", "mqtt-device-payload-type-proto": "Protobuf",