From dc8370c8594211470bd80a0d235cb06585c3c297 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 3 Mar 2021 17:18:49 +0200 Subject: [PATCH] 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 = [];