Browse Source

Lwm2m: front: fix bug updateObserve...ToJson

pull/4021/head
nickAS21 6 years ago
parent
commit
e32e90932b
  1. 66
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

66
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

@ -264,59 +264,27 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const telemetryArray: Array<string> = []; const telemetryArray: Array<string> = [];
const keyNameNew = {}; const keyNameNew = {};
const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
const paths = new Set<string>();
let pathObj;
let pathInst;
let pathRes;
observeJson.forEach(obj => { observeJson.forEach(obj => {
for (const [key, value] of Object.entries(obj)) { if (obj.hasOwnProperty(INSTANCES) && Array.isArray(obj.instances)) {
if (key === ID) { obj.instances.forEach(instance => {
pathObj = value; if (instance.hasOwnProperty(RESOURCES) && Array.isArray(instance.resources)) {
} instance.resources.forEach(resource => {
if (key === INSTANCES) { let pathRes = `/${obj.id}/${instance.id}/${resource.id}`;
const instancesJson = value as Instance[]; if (resource.attribute) {
if (instancesJson.length > 0) { attributeArray.push(pathRes);
instancesJson.forEach(instance => { }
for (const [instanceKey, instanceValue] of Object.entries(instance)) { if (resource.telemetry) {
if (instanceKey === ID) { telemetryArray.push(pathRes);
pathInst = instanceValue; }
} if (resource.attribute || resource.telemetry) {
if (instanceKey === RESOURCES) { keyNameNew[pathRes] = resource.keyName;
const resourcesJson = instanceValue as ResourceLwM2M[]; if (resource.observe) {
if (resourcesJson.length > 0) { observeArray.push(pathRes);
resourcesJson.forEach(res => {
for (const [resourceKey, value] of Object.entries(res)) {
if (resourceKey === ID) {
pathRes = `/${pathObj}/${pathInst}/${value}`;
} else if (resourceKey === ATTRIBUTE && value) {
attributeArray.push(pathRes);
paths.add(pathRes);
} else if (resourceKey === TELEMETRY && value) {
telemetryArray.push(pathRes);
paths.add(pathRes);
}
}
});
/**
* only if these paths are marked in ATTRIBUTE or TELEMETRY
*/
resourcesJson.forEach(res => {
for (const [resourceKey, value] of Object.entries(res)) {
if (resourceKey === ID) {
pathRes = `/${pathObj}/${pathInst}/${value}`;
} else if (resourceKey === OBSERVE && paths.has(pathRes) && value) {
observeArray.push(pathRes);
} else if (resourceKey === KEY_NAME && paths.has(pathRes)) {
keyNameNew[pathRes] = value;
}
}
});
}
} }
} }
}); })
} }
} })
} }
}); });
if (isUndefined(this.configurationValue.observeAttr)) { if (isUndefined(this.configurationValue.observeAttr)) {

Loading…
Cancel
Save