From 0f150337397472a1b0deb117a7eeb649c9dbcfff Mon Sep 17 00:00:00 2001 From: nickAS21 <44275303+nickAS21@users.noreply.github.com> Date: Fri, 7 May 2021 16:05:48 +0300 Subject: [PATCH] Lwm2m: fix bug add new instance (#4554) * Lwm2m: fix bug add new instance * Lwm2m: add KeyName default with instanceId --- ...-profile-transport-configuration.component.ts | 16 ++++++++++++---- .../lwm2m-observe-attr-telemetry.component.ts | 5 +++-- .../device/lwm2m/lwm2m-profile-config.models.ts | 2 +- 3 files changed, 16 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 60fb27a752..0a943ab5af 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 @@ -23,6 +23,7 @@ import { BINDING_MODE, BINDING_MODE_NAMES, getDefaultProfileConfig, + Instance, INSTANCES, KEY_NAME, Lwm2mProfileConfigModels, @@ -37,6 +38,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service'; import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; import { Direction } from '@shared/models/page/sort-order'; +import _ from 'lodash'; @Component({ selector: 'tb-profile-lwm2m-device-transport-configuration', @@ -230,24 +232,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); } - private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { const instancesPath = attribute.concat(telemetry) .filter(instance => !instance.includes('/0/')) .map(instance => instance.slice(1, instance.lastIndexOf('/'))) .sort(this.sortPath); - new Set(instancesPath).forEach(path => { const pathParameter = Array.from(path.split('/'), String); const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]); if (objectLwM2M) { - const instance = deepClone(objectLwM2M.instances[0]); - instance.id = +pathParameter[1]; + const instance = this.updateInInstanceKeyName (objectLwM2M.instances[0], +pathParameter[1]); objectLwM2M.instances.push(instance); } }); } + private updateInInstanceKeyName = (instance: Instance, instanceId: number): Instance => { + const instanceUpdate = deepClone(instance); + instanceUpdate.id = instanceId; + instanceUpdate.resources.forEach(resource => { + resource.keyName = _.camelCase(resource.name + instanceUpdate.id); + }) + return instanceUpdate; + } + private updateObserveAttrTelemetryObjects = (parameters: string[], objectLwM2MS: ObjectLwM2M[], nameParameter: string): void => { parameters.forEach(parameter => { diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts index 3d6b93b84c..530679113c 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts @@ -45,6 +45,7 @@ import { Lwm2mObjectAddInstancesData, Lwm2mObjectAddInstancesDialogComponent } from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component'; +import _ from 'lodash'; @Component({ selector: 'tb-profile-lwm2m-observe-attr-telemetry', @@ -261,7 +262,6 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor r.attribute = false; r.telemetry = false; r.observe = false; - r.keyName = {}; r.attributeLwm2m = {}; }); const valueOld = this.instancesToSetId(instancesArray); @@ -280,7 +280,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor private addInstancesNew = (idsAdd: Set, objectLwM2MFormGroup: FormGroup, instancesFormArray: FormArray, instanceNew: Instance): void => { idsAdd.forEach(x => { - this.pushInstance(instancesFormArray, x, instanceNew); + instanceNew.resources.forEach(resource => {resource.keyName = _.camelCase(resource.name + x);}); + this.pushInstance(instancesFormArray, x, deepClone(instanceNew as Instance)); }); (instancesFormArray.controls as FormGroup[]).sort((a, b) => a.value.id - b.value.id); } diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts index f6e58df903..acea41394a 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts @@ -246,7 +246,7 @@ export interface ResourceLwM2M { observe: boolean; attribute: boolean; telemetry: boolean; - keyName: {}; + keyName: string; attributeLwm2m?: {}; }