Browse Source

Lwm2m: fix bug add new instance (#4554)

* Lwm2m: fix bug add new instance

* Lwm2m: add KeyName default with instanceId
pull/4563/head
nickAS21 5 years ago
committed by GitHub
parent
commit
0f15033739
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  2. 5
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts

16
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 => {

5
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<number>, 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);
}

2
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?: {};
}

Loading…
Cancel
Save