From dc8370c8594211470bd80a0d235cb06585c3c297 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 3 Mar 2021 17:18:49 +0200 Subject: [PATCH 1/2] Lwm2m: front: validateObject on the start --- ...ofile-transport-configuration.component.ts | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts index 40ba18ebe9..2fa7c1cb9a 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts @@ -14,24 +14,30 @@ /// limitations under the License. /// -import { DeviceProfileTransportConfiguration, DeviceTransportType } from '@shared/models/device.models'; -import { Component, forwardRef, Inject, Input } from '@angular/core'; -import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; -import { Store } from '@ngrx/store'; -import { AppState } from '@app/core/core.state'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; +import {DeviceProfileTransportConfiguration, DeviceTransportType} from '@shared/models/device.models'; +import {Component, forwardRef, Inject, Input} from '@angular/core'; +import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators} from '@angular/forms'; +import {Store} from '@ngrx/store'; +import {AppState} from '@app/core/core.state'; +import {coerceBooleanProperty} from '@angular/cdk/coercion'; import { - INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME, + ATTRIBUTE, getDefaultProfileConfig, + INSTANCES, + KEY_NAME, + ModelValue, ObjectLwM2M, + OBSERVE, + OBSERVE_ATTR_TELEMETRY, ProfileConfigModels, - ModelValue + RESOURCES, + TELEMETRY } from './profile-config.models'; -import { DeviceProfileService } from '@core/http/device-profile.service'; -import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils'; -import { WINDOW } from '@core/services/window.service'; -import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; -import { Direction } from '@shared/models/page/sort-order'; +import {DeviceProfileService} from '@core/http/device-profile.service'; +import {deepClone, isDefinedAndNotNull, isUndefined} from '@core/utils'; +import {WINDOW} from '@core/services/window.service'; +import {JsonArray, JsonObject} from '@angular/compiler-cli/ngcc/src/packages/entry_point'; +import {Direction} from '@shared/models/page/sort-order'; @Component({ selector: 'tb-profile-lwm2m-device-transport-configuration', @@ -64,8 +70,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro this.requiredValue = coerceBooleanProperty(value); } - private propagateChange = (v: any) => { - } + private propagateChange = (v: any) => { } constructor(private store: Store, private fb: FormBuilder, @@ -200,7 +205,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro const observeArray = this.configurationValue.observeAttr.observe; const attributeArray = this.configurationValue.observeAttr.attribute; const telemetryArray = this.configurationValue.observeAttr.telemetry; - const keyNameJson = this.configurationValue.observeAttr.keyName; + let keyNameJson = this.configurationValue.observeAttr.keyName; if (this.includesNotZeroInstance(attributeArray, telemetryArray)) { this.addInstances(attributeArray, telemetryArray, clientObserveAttrTelemetry); } @@ -214,6 +219,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, TELEMETRY); } if (isDefinedAndNotNull(keyNameJson)) { + this.configurationValue.observeAttr.keyName = deepClone(this.validateKeyNameObjects(keyNameJson, attributeArray, telemetryArray)); + keyNameJson = this.configurationValue.observeAttr.keyName; this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry); } } @@ -264,6 +271,18 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro }); } + private validateKeyNameObjects = (nameJson: JsonObject, attributeArray: JsonArray, telemetryArray: JsonArray): {} => { + const keyName = JSON.parse(JSON.stringify(nameJson)); + let keyNameValidate = {}; + const keyAttrTelemetry = attributeArray.concat(telemetryArray) ; + Object.keys(keyName).forEach(key => { + if (keyAttrTelemetry.includes(key)) { + keyNameValidate[key] = keyName[key]; + } + }); + return keyNameValidate; + } + private updateObserveAttrTelemetryFromGroupToJson = (val: ObjectLwM2M[]): void => { const observeArray: Array = []; const attributeArray: Array = []; From 03b647c525542c8553d6f39dcc434146eaf70de1 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Thu, 4 Mar 2021 17:19:07 +0200 Subject: [PATCH 2/2] Lwm2m: front: validateObject on the start fix bug --- ...ice-profile-transport-configuration.component.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts index 2fa7c1cb9a..519ecc2981 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts @@ -219,9 +219,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, TELEMETRY); } if (isDefinedAndNotNull(keyNameJson)) { - this.configurationValue.observeAttr.keyName = deepClone(this.validateKeyNameObjects(keyNameJson, attributeArray, telemetryArray)); - keyNameJson = this.configurationValue.observeAttr.keyName; - this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry); + this.configurationValue.observeAttr.keyName = this.validateKeyNameObjects(keyNameJson, attributeArray, telemetryArray); + this.upDateJsonAllConfig(); + this.updateKeyNameObjects(clientObserveAttrTelemetry); } } return {clientLwM2M: clientObserveAttrTelemetry}; @@ -260,14 +260,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro }); } - private updateKeyNameObjects = (nameJson: JsonObject, clientObserveAttrTelemetry: ObjectLwM2M[]): void => { - const keyName = JSON.parse(JSON.stringify(nameJson)); - Object.keys(keyName).forEach(key => { + private updateKeyNameObjects = (clientObserveAttrTelemetry: ObjectLwM2M[]): void => { + Object.keys(this.configurationValue.observeAttr.keyName).forEach(key => { const [objectId, instanceId, resourceId] = Array.from(key.substring(1).split('/'), Number); clientObserveAttrTelemetry.find(objectLwm2m => objectLwm2m.id === objectId) .instances.find(instance => instance.id === instanceId) .resources.find(resource => resource.id === resourceId) - .keyName = keyName[key]; + .keyName = this.configurationValue.observeAttr.keyName[key]; }); }