From 37506df5c0068d99dfd375b79a7938396e2f4113 Mon Sep 17 00:00:00 2001 From: rusikv Date: Mon, 13 Feb 2023 11:05:26 +0200 Subject: [PATCH 1/2] added chips input for SparkPlug attr metric names --- ...ile-transport-configuration.component.html | 18 ++++++++++ ...ofile-transport-configuration.component.ts | 34 +++++++++++++++++++ .../assets/locale/locale.constant-en_US.json | 2 ++ 3 files changed, 54 insertions(+) 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..efcde3d46b 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}); } @@ -208,6 +214,34 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control } } + public 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); + } + } + + public addAttributeMetricName(event: MatChipInputEvent): void { + const input = event.input; + let value = event.value; + if ((value || '').trim()) { + value = value.trim(); + let keys: string[] = this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').value; + if (!keys || keys.indexOf(value) === -1) { + if (!keys) { + keys = []; + } + keys.push(value); + this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').setValue(keys, {emitEvent: true}); + } + } + if (input) { + input.value = ''; + } + } + private validationMQTTTopic(): ValidatorFn { return (c: FormControl) => { const newTopic = c.value; 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", From fcbdc4194b8700c33a3db4c02f38fa740e07f276 Mon Sep 17 00:00:00 2001 From: rusikv Date: Tue, 14 Feb 2023 10:35:25 +0200 Subject: [PATCH 2/2] changed wrong variable name --- ...ofile-transport-configuration.component.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) 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 efcde3d46b..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 @@ -175,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) { @@ -214,34 +242,6 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control } } - public 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); - } - } - - public addAttributeMetricName(event: MatChipInputEvent): void { - const input = event.input; - let value = event.value; - if ((value || '').trim()) { - value = value.trim(); - let keys: string[] = this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').value; - if (!keys || keys.indexOf(value) === -1) { - if (!keys) { - keys = []; - } - keys.push(value); - this.mqttDeviceProfileTransportConfigurationFormGroup.get('sparkPlugAttributesMetricNames').setValue(keys, {emitEvent: true}); - } - } - if (input) { - input.value = ''; - } - } - private validationMQTTTopic(): ValidatorFn { return (c: FormControl) => { const newTopic = c.value;