Browse Source

Merge branch 'master' of github.com:thingsboard/thingsboard

pull/4563/head
Igor Kulikov 5 years ago
parent
commit
1fac07ed5e
  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,
BINDING_MODE_NAMES, BINDING_MODE_NAMES,
getDefaultProfileConfig, getDefaultProfileConfig,
Instance,
INSTANCES, INSTANCES,
KEY_NAME, KEY_NAME,
Lwm2mProfileConfigModels, Lwm2mProfileConfigModels,
@ -37,6 +38,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils';
import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import _ from 'lodash';
@Component({ @Component({
selector: 'tb-profile-lwm2m-device-transport-configuration', selector: 'tb-profile-lwm2m-device-transport-configuration',
@ -230,24 +232,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); const isNotZeroInstanceId = (instance) => !instance.includes('/0/');
return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId);
} }
private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
const instancesPath = attribute.concat(telemetry) const instancesPath = attribute.concat(telemetry)
.filter(instance => !instance.includes('/0/')) .filter(instance => !instance.includes('/0/'))
.map(instance => instance.slice(1, instance.lastIndexOf('/'))) .map(instance => instance.slice(1, instance.lastIndexOf('/')))
.sort(this.sortPath); .sort(this.sortPath);
new Set(instancesPath).forEach(path => { new Set(instancesPath).forEach(path => {
const pathParameter = Array.from(path.split('/'), String); const pathParameter = Array.from(path.split('/'), String);
const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]); const objectLwM2M = clientObserveAttrTelemetry.find(x => x.keyId === pathParameter[0]);
if (objectLwM2M) { if (objectLwM2M) {
const instance = deepClone(objectLwM2M.instances[0]); const instance = this.updateInInstanceKeyName (objectLwM2M.instances[0], +pathParameter[1]);
instance.id = +pathParameter[1];
objectLwM2M.instances.push(instance); 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[], private updateObserveAttrTelemetryObjects = (parameters: string[], objectLwM2MS: ObjectLwM2M[],
nameParameter: string): void => { nameParameter: string): void => {
parameters.forEach(parameter => { 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, Lwm2mObjectAddInstancesData,
Lwm2mObjectAddInstancesDialogComponent Lwm2mObjectAddInstancesDialogComponent
} from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component'; } from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component';
import _ from 'lodash';
@Component({ @Component({
selector: 'tb-profile-lwm2m-observe-attr-telemetry', selector: 'tb-profile-lwm2m-observe-attr-telemetry',
@ -261,7 +262,6 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
r.attribute = false; r.attribute = false;
r.telemetry = false; r.telemetry = false;
r.observe = false; r.observe = false;
r.keyName = {};
r.attributeLwm2m = {}; r.attributeLwm2m = {};
}); });
const valueOld = this.instancesToSetId(instancesArray); const valueOld = this.instancesToSetId(instancesArray);
@ -280,7 +280,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
private addInstancesNew = (idsAdd: Set<number>, objectLwM2MFormGroup: FormGroup, instancesFormArray: FormArray, private addInstancesNew = (idsAdd: Set<number>, objectLwM2MFormGroup: FormGroup, instancesFormArray: FormArray,
instanceNew: Instance): void => { instanceNew: Instance): void => {
idsAdd.forEach(x => { 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); (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; observe: boolean;
attribute: boolean; attribute: boolean;
telemetry: boolean; telemetry: boolean;
keyName: {}; keyName: string;
attributeLwm2m?: {}; attributeLwm2m?: {};
} }

Loading…
Cancel
Save