...
|
...
|
@@ -33,7 +33,7 @@ import { |
33
|
33
|
OBSERVE,
|
34
|
34
|
OBSERVE_ATTR,
|
35
|
35
|
TELEMETRY,
|
36
|
|
- ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance
|
|
36
|
+ ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance, ProfileConfigModels, ResourceLwM2M
|
37
|
37
|
} from "./profile-config.models";
|
38
|
38
|
import { DeviceProfileService } from "@core/http/device-profile.service";
|
39
|
39
|
import { deepClone, isUndefined } from "@core/utils";
|
...
|
...
|
@@ -44,7 +44,6 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; |
44
|
44
|
@Component({
|
45
|
45
|
selector: 'tb-profile-lwm2m-device-transport-configuration',
|
46
|
46
|
templateUrl: './lwm2m-device-profile-transport-configuration.component.html',
|
47
|
|
- styleUrls: [],
|
48
|
47
|
providers: [{
|
49
|
48
|
provide: NG_VALUE_ACCESSOR,
|
50
|
49
|
useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent),
|
...
|
...
|
@@ -53,6 +52,10 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; |
53
|
52
|
})
|
54
|
53
|
export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, Validators {
|
55
|
54
|
|
|
55
|
+ private configurationValue: ProfileConfigModels;
|
|
56
|
+ private requiredValue: boolean;
|
|
57
|
+ private disabled = false;
|
|
58
|
+
|
56
|
59
|
lwm2mDeviceProfileTransportConfFormGroup: FormGroup;
|
57
|
60
|
observeAttr = OBSERVE_ATTR as string;
|
58
|
61
|
observe = OBSERVE as string;
|
...
|
...
|
@@ -62,9 +65,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
62
|
65
|
bootstrapServers: string;
|
63
|
66
|
bootstrapServer: string;
|
64
|
67
|
lwm2mServer: string;
|
65
|
|
- private configurationValue: {};
|
66
|
|
- private requiredValue: boolean;
|
67
|
|
- private disabled = false as boolean;
|
68
|
68
|
sortFunction = this.sortObjectKeyPathJson;
|
69
|
69
|
|
70
|
70
|
get required(): boolean {
|
...
|
...
|
@@ -76,8 +76,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
76
|
76
|
this.requiredValue = coerceBooleanProperty(value);
|
77
|
77
|
}
|
78
|
78
|
|
79
|
|
- private propagateChange = (v: any) => {
|
80
|
|
- };
|
|
79
|
+ private propagateChange = (v: any) => { };
|
81
|
80
|
|
82
|
81
|
constructor(private store: Store<AppState>,
|
83
|
82
|
private fb: FormBuilder,
|
...
|
...
|
@@ -85,17 +84,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
85
|
84
|
@Inject(WINDOW) private window: Window) {
|
86
|
85
|
this.lwm2mDeviceProfileTransportConfFormGroup = this.fb.group({
|
87
|
86
|
objectIds: [{}, Validators.required],
|
88
|
|
- observeAttrTelemetry: [{'clientLwM2M': [] as ObjectLwM2M []}, Validators.required],
|
|
87
|
+ observeAttrTelemetry: [{clientLwM2M: [] as ObjectLwM2M[]}, Validators.required],
|
89
|
88
|
shortId: [null, Validators.required],
|
90
|
89
|
lifetime: [null, Validators.required],
|
91
|
90
|
defaultMinPeriod: [null, Validators.required],
|
92
|
91
|
notifIfDisabled: [true, []],
|
93
|
|
- binding: ["U", Validators.required],
|
|
92
|
+ binding: ['U', Validators.required],
|
94
|
93
|
bootstrapServer: [null, Validators.required],
|
95
|
94
|
lwm2mServer: [null, Validators.required],
|
96
|
95
|
configurationJson: [null, Validators.required],
|
97
|
96
|
});
|
98
|
|
- this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(value => {
|
|
97
|
+ this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(() => {
|
99
|
98
|
if (!this.disabled) {
|
100
|
99
|
this.updateModel();
|
101
|
100
|
}
|
...
|
...
|
@@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
122
|
121
|
}
|
123
|
122
|
|
124
|
123
|
writeValue(value: any | null): void {
|
125
|
|
- value = (Object.keys(value).length == 0) ? getDefaultProfileConfig() : value;
|
|
124
|
+ value = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
|
126
|
125
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
|
127
|
126
|
configurationJson: value
|
128
|
127
|
},
|
...
|
...
|
@@ -132,14 +131,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
132
|
131
|
}
|
133
|
132
|
|
134
|
133
|
private initWriteValue(): void {
|
135
|
|
- let modelValue = {"objectIds": null, "objectsList": []};
|
|
134
|
+ const modelValue = {objectIds: null, objectsList: []};
|
136
|
135
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
137
|
136
|
if (modelValue.objectIds !== null) {
|
138
|
137
|
this.deviceProfileService.getLwm2mObjects(modelValue.objectIds).subscribe(
|
139
|
|
- (objectsList) => {
|
140
|
|
- modelValue.objectsList = objectsList;
|
141
|
|
- this.updateWriteValue(modelValue);
|
142
|
|
- }
|
|
138
|
+ (objectsList) => {
|
|
139
|
+ modelValue.objectsList = objectsList;
|
|
140
|
+ this.updateWriteValue(modelValue);
|
|
141
|
+ }
|
143
|
142
|
);
|
144
|
143
|
} else {
|
145
|
144
|
this.updateWriteValue(modelValue);
|
...
|
...
|
@@ -147,17 +146,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
147
|
146
|
}
|
148
|
147
|
|
149
|
148
|
private updateWriteValue(value: any): void {
|
150
|
|
- let objectsList = deepClone(value.objectsList);
|
|
149
|
+ const objectsList = deepClone(value.objectsList);
|
151
|
150
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
|
152
|
151
|
objectIds: value,
|
153
|
152
|
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)},
|
154
|
|
- shortId: this.configurationValue['bootstrap'].servers.shortId,
|
155
|
|
- lifetime: this.configurationValue['bootstrap'].servers.lifetime,
|
156
|
|
- defaultMinPeriod: this.configurationValue['bootstrap'].servers.defaultMinPeriod,
|
157
|
|
- notifIfDisabled: this.configurationValue['bootstrap'].servers.notifIfDisabled,
|
158
|
|
- binding: this.configurationValue['bootstrap'].servers.binding,
|
159
|
|
- bootstrapServer: this.configurationValue['bootstrap'].bootstrapServer,
|
160
|
|
- lwm2mServer: this.configurationValue['bootstrap'].lwm2mServer
|
|
153
|
+ shortId: this.configurationValue.bootstrap.servers.shortId,
|
|
154
|
+ lifetime: this.configurationValue.bootstrap.servers.lifetime,
|
|
155
|
+ defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
|
|
156
|
+ notifIfDisabled: this.configurationValue.bootstrap.servers.notifIfDisabled,
|
|
157
|
+ binding: this.configurationValue.bootstrap.servers.binding,
|
|
158
|
+ bootstrapServer: this.configurationValue.bootstrap.bootstrapServer,
|
|
159
|
+ lwm2mServer: this.configurationValue.bootstrap.lwm2mServer
|
161
|
160
|
},
|
162
|
161
|
{emitEvent: false});
|
163
|
162
|
}
|
...
|
...
|
@@ -174,10 +173,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
174
|
173
|
|
175
|
174
|
private updateObserveAttrTelemetryObjectFormGroup(objectsList: ObjectLwM2M[]) {
|
176
|
175
|
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
|
177
|
|
- observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}
|
178
|
|
- },
|
179
|
|
- {emitEvent: false});
|
180
|
|
- this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({
|
|
176
|
+ observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}
|
|
177
|
+ },
|
|
178
|
+ {emitEvent: false});
|
|
179
|
+ this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({
|
181
|
180
|
onlySelf: true
|
182
|
181
|
});
|
183
|
182
|
}
|
...
|
...
|
@@ -188,9 +187,11 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
188
|
187
|
}
|
189
|
188
|
|
190
|
189
|
upDateValueToJsonTab_0(): void {
|
191
|
|
- if (!this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").pristine) {
|
192
|
|
- this.upDateObserveAttrTelemetryFromGroupToJson(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M']);
|
193
|
|
- this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({
|
|
190
|
+ if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').pristine) {
|
|
191
|
+ this.upDateObserveAttrTelemetryFromGroupToJson(
|
|
192
|
+ this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M
|
|
193
|
+ );
|
|
194
|
+ this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({
|
194
|
195
|
onlySelf: true
|
195
|
196
|
});
|
196
|
197
|
this.upDateJsonAllConfig();
|
...
|
...
|
@@ -200,14 +201,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
200
|
201
|
upDateValueToJsonTab_1(): void {
|
201
|
202
|
this.upDateValueServersToJson();
|
202
|
203
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').pristine) {
|
203
|
|
- this.configurationValue['bootstrap'].bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value;
|
|
204
|
+ this.configurationValue.bootstrap.bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value;
|
204
|
205
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').markAsPristine({
|
205
|
206
|
onlySelf: true
|
206
|
207
|
});
|
207
|
208
|
this.upDateJsonAllConfig();
|
208
|
209
|
}
|
209
|
210
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').pristine) {
|
210
|
|
- this.configurationValue['bootstrap'].lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value;
|
|
211
|
+ this.configurationValue.bootstrap.lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value;
|
211
|
212
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').markAsPristine({
|
212
|
213
|
onlySelf: true
|
213
|
214
|
});
|
...
|
...
|
@@ -216,36 +217,37 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
216
|
217
|
}
|
217
|
218
|
|
218
|
219
|
upDateValueServersToJson(): void {
|
|
220
|
+ const bootstrapServers = this.configurationValue.bootstrap.servers;
|
219
|
221
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').pristine) {
|
220
|
|
- this.configurationValue['bootstrap'].servers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value;
|
|
222
|
+ bootstrapServers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value;
|
221
|
223
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').markAsPristine({
|
222
|
224
|
onlySelf: true
|
223
|
225
|
});
|
224
|
226
|
this.upDateJsonAllConfig();
|
225
|
227
|
}
|
226
|
228
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').pristine) {
|
227
|
|
- this.configurationValue['bootstrap'].servers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value;
|
|
229
|
+ bootstrapServers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value;
|
228
|
230
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').markAsPristine({
|
229
|
231
|
onlySelf: true
|
230
|
232
|
});
|
231
|
233
|
this.upDateJsonAllConfig();
|
232
|
234
|
}
|
233
|
235
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').pristine) {
|
234
|
|
- this.configurationValue['bootstrap'].servers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value;
|
|
236
|
+ bootstrapServers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value;
|
235
|
237
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').markAsPristine({
|
236
|
238
|
onlySelf: true
|
237
|
239
|
});
|
238
|
240
|
this.upDateJsonAllConfig();
|
239
|
241
|
}
|
240
|
242
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').pristine) {
|
241
|
|
- this.configurationValue['bootstrap'].servers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value;
|
|
243
|
+ bootstrapServers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value;
|
242
|
244
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').markAsPristine({
|
243
|
245
|
onlySelf: true
|
244
|
246
|
});
|
245
|
247
|
this.upDateJsonAllConfig();
|
246
|
248
|
}
|
247
|
249
|
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').pristine) {
|
248
|
|
- this.configurationValue['bootstrap'].servers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value;
|
|
250
|
+ bootstrapServers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value;
|
249
|
251
|
this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').markAsPristine({
|
250
|
252
|
onlySelf: true
|
251
|
253
|
});
|
...
|
...
|
@@ -254,122 +256,130 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
254
|
256
|
}
|
255
|
257
|
|
256
|
258
|
getObserveAttrTelemetryObjects(listObject: ObjectLwM2M[]): ObjectLwM2M [] {
|
257
|
|
- let clientObserveAttr = deepClone(listObject) as ObjectLwM2M[];
|
|
259
|
+ const clientObserveAttr = deepClone(listObject);
|
258
|
260
|
if (this.configurationValue[this.observeAttr]) {
|
259
|
|
- let observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>;
|
260
|
|
- let attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>;
|
261
|
|
- let telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>;
|
262
|
|
- let keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject;
|
263
|
|
- if (this.includesInstancesNo(attributeArray, telemetryArray, clientObserveAttr)) {
|
|
261
|
+ const observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>;
|
|
262
|
+ const attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>;
|
|
263
|
+ const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>;
|
|
264
|
+ const keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject;
|
|
265
|
+ if (this.includesInstancesNo(attributeArray, telemetryArray)) {
|
264
|
266
|
this.addInstances(attributeArray, telemetryArray, clientObserveAttr);
|
265
|
267
|
}
|
266
|
|
- if (observeArray) this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, "observe");
|
267
|
|
- if (attributeArray) this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, "attribute");
|
268
|
|
- if (telemetryArray) this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, "telemetry");
|
269
|
|
- if (keyNameJson) this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr);
|
|
268
|
+ if (observeArray) {
|
|
269
|
+ this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, 'observe');
|
|
270
|
+ }
|
|
271
|
+ if (attributeArray) {
|
|
272
|
+ this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, 'attribute');
|
|
273
|
+ }
|
|
274
|
+ if (telemetryArray) {
|
|
275
|
+ this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, 'telemetry');
|
|
276
|
+ }
|
|
277
|
+ if (keyNameJson) {
|
|
278
|
+ this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr);
|
|
279
|
+ }
|
270
|
280
|
}
|
271
|
281
|
clientObserveAttr.forEach(obj => {
|
272
|
|
- obj.instances.sort((a,b) => a.id - b.id);;
|
273
|
|
- })
|
|
282
|
+ obj.instances.sort((a, b) => a.id - b.id);
|
|
283
|
+ });
|
274
|
284
|
return clientObserveAttr;
|
275
|
285
|
}
|
276
|
286
|
|
277
|
|
- includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): boolean {
|
278
|
|
- let isIdIndex = (element) => !element.includes("/0/");
|
279
|
|
- return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0
|
280
|
|
-
|
|
287
|
+ includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>): boolean {
|
|
288
|
+ const isIdIndex = (element) => !element.includes('/0/');
|
|
289
|
+ return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0;
|
281
|
290
|
}
|
282
|
291
|
|
283
|
292
|
addInstances(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): void {
|
284
|
|
- let attr = [] as Array<string>;
|
285
|
|
- [...attributeArray].filter(x => (!x.includes("/0/"))).forEach(x => {
|
|
293
|
+ const attr = [] as Array<string>;
|
|
294
|
+ [...attributeArray].filter(x => (!x.includes('/0/'))).forEach(x => {
|
286
|
295
|
attr.push(this.convertPathToInstance(x));
|
287
|
296
|
});
|
288
|
|
- let telemetry = [] as Array<string>;
|
289
|
|
- [...telemetryArray].filter(x => (!x.includes("/0/"))).forEach(x => {
|
|
297
|
+ const telemetry = [] as Array<string>;
|
|
298
|
+ [...telemetryArray].filter(x => (!x.includes('/0/'))).forEach(x => {
|
290
|
299
|
telemetry.push(this.convertPathToInstance(x));
|
291
|
300
|
});
|
292
|
|
- let instancesNoZero = new Set(attr.concat(telemetry).sort());
|
|
301
|
+ const instancesNoZero = new Set(attr.concat(telemetry).sort());
|
293
|
302
|
instancesNoZero.forEach(path => {
|
294
|
|
- let pathParameter = Array.from(path.split('/'), Number);
|
295
|
|
- let objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0]));
|
|
303
|
+ const pathParameter = Array.from(path.split('/'), Number);
|
|
304
|
+ const objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0]));
|
296
|
305
|
if (objectLwM2M) {
|
297
|
|
- let instance = deepClone(objectLwM2M.instances[0]) as Instance;
|
|
306
|
+ const instance = deepClone(objectLwM2M.instances[0]) as Instance;
|
298
|
307
|
instance.id = pathParameter[1];
|
299
|
308
|
objectLwM2M.instances.push(instance);
|
300
|
309
|
}
|
301
|
|
- })
|
|
310
|
+ });
|
302
|
311
|
}
|
303
|
312
|
|
304
|
313
|
convertPathToInstance(path: string): string {
|
305
|
|
- let newX = Array.from(path.substring(1).split('/'), Number);
|
306
|
|
- return [newX[0], newX[1]].join("/");
|
|
314
|
+ const newX = Array.from(path.substring(1).split('/'), Number);
|
|
315
|
+ return [newX[0], newX[1]].join('/');
|
307
|
316
|
}
|
308
|
317
|
|
309
|
318
|
updateObserveAttrTelemetryObjects(isParameter: Array<string>, clientObserveAttr: ObjectLwM2M[], nameParameter: string): void {
|
310
|
319
|
isParameter.forEach(attr => {
|
311
|
|
- let idKeys = Array.from(attr.substring(1).split('/'), Number);
|
|
320
|
+ const idKeys = Array.from(attr.substring(1).split('/'), Number);
|
312
|
321
|
clientObserveAttr
|
313
|
|
- .forEach(e => {
|
314
|
|
- if (e.id == idKeys[0]) {
|
315
|
|
- let instance = e.instances.find(e => e.id == idKeys[1]);
|
316
|
|
- if (isNotNullOrUndefined(instance)) {
|
317
|
|
- instance.resources.find(e => e.id == idKeys[2])[nameParameter] = true;
|
|
322
|
+ .forEach(e => {
|
|
323
|
+ if (e.id === idKeys[0]) {
|
|
324
|
+ const instance = e.instances.find(itrInstance => itrInstance.id === idKeys[1]);
|
|
325
|
+ if (isNotNullOrUndefined(instance)) {
|
|
326
|
+ instance.resources.find(resource => resource.id === idKeys[2])[nameParameter] = true;
|
|
327
|
+ }
|
318
|
328
|
}
|
319
|
|
- }
|
320
|
|
- });
|
|
329
|
+ });
|
321
|
330
|
});
|
322
|
331
|
}
|
323
|
332
|
|
324
|
333
|
updateKeyNameObjects(nameJson: JsonObject, clientObserveAttr: ObjectLwM2M[]): void {
|
325
|
|
- let keyName = JSON.parse(JSON.stringify(nameJson));
|
326
|
|
- Object.keys(keyName).forEach(function (key) {
|
327
|
|
- let idKeys = Array.from(key.substring(1).split('/'), Number);
|
|
334
|
+ const keyName = JSON.parse(JSON.stringify(nameJson));
|
|
335
|
+ Object.keys(keyName).forEach(key => {
|
|
336
|
+ const idKeys = Array.from(key.substring(1).split('/'), Number);
|
328
|
337
|
clientObserveAttr
|
329
|
|
- .forEach(e => {
|
330
|
|
- if (e.id == idKeys[0]) {
|
331
|
|
- e.instances.find(e => e.id == idKeys[1]).resources
|
332
|
|
- .find(e => e.id == idKeys[2]).keyName = keyName[key];
|
333
|
|
- }
|
334
|
|
- });
|
|
338
|
+ .forEach(e => {
|
|
339
|
+ if (e.id === idKeys[0]) {
|
|
340
|
+ e.instances
|
|
341
|
+ .find(instance => instance.id === idKeys[1]).resources
|
|
342
|
+ .find(resource => resource.id === idKeys[2]).keyName = keyName[key];
|
|
343
|
+ }
|
|
344
|
+ });
|
335
|
345
|
});
|
336
|
346
|
}
|
337
|
347
|
|
338
|
|
- upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M []): void {
|
339
|
|
- let observeArray = [] as Array<string>;
|
340
|
|
- let attributeArray = [] as Array<string>;
|
341
|
|
- let telemetryArray = [] as Array<string>;
|
342
|
|
- let observeJson = JSON.parse(JSON.stringify(val));
|
|
348
|
+ upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M[]): void {
|
|
349
|
+ const observeArray: Array<string> = [];
|
|
350
|
+ const attributeArray: Array<string> = [];
|
|
351
|
+ const telemetryArray: Array<string> = [];
|
|
352
|
+ const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
|
343
|
353
|
let pathObj;
|
344
|
354
|
let pathInst;
|
345
|
|
- let pathRes
|
|
355
|
+ let pathRes;
|
346
|
356
|
observeJson.forEach(obj => {
|
347
|
357
|
Object.entries(obj).forEach(([key, value]) => {
|
348
|
358
|
if (key === 'id') {
|
349
|
359
|
pathObj = value;
|
350
|
360
|
}
|
351
|
361
|
if (key === 'instances') {
|
352
|
|
- let instancesJson = JSON.parse(JSON.stringify(value)) as [];
|
|
362
|
+ const instancesJson = JSON.parse(JSON.stringify(value)) as Instance[];
|
353
|
363
|
if (instancesJson.length > 0) {
|
354
|
364
|
instancesJson.forEach(instance => {
|
355
|
|
- Object.entries(instance).forEach(([key, value]) => {
|
356
|
|
- if (key === 'id') {
|
357
|
|
- pathInst = value;
|
|
365
|
+ Object.entries(instance).forEach(([instanceKey, instanceValue]) => {
|
|
366
|
+ if (instanceKey === 'id') {
|
|
367
|
+ pathInst = instanceValue;
|
358
|
368
|
}
|
359
|
|
- if (key === 'resources') {
|
360
|
|
- let resourcesJson = JSON.parse(JSON.stringify(value)) as [];
|
|
369
|
+ if (instanceKey === 'resources') {
|
|
370
|
+ const resourcesJson = JSON.parse(JSON.stringify(instanceValue)) as ResourceLwM2M[];
|
361
|
371
|
if (resourcesJson.length > 0) {
|
362
|
372
|
resourcesJson.forEach(res => {
|
363
|
|
- Object.entries(res).forEach(([key, value]) => {
|
364
|
|
- if (key === 'id') {
|
365
|
|
- // pathRes = value
|
366
|
|
- pathRes = '/' + pathObj + '/' + pathInst + '/' + value;
|
367
|
|
- } else if (key === 'observe' && value) {
|
368
|
|
- observeArray.push(pathRes)
|
369
|
|
- } else if (key === 'attribute' && value) {
|
370
|
|
- attributeArray.push(pathRes)
|
371
|
|
- } else if (key === 'telemetry' && value) {
|
372
|
|
- telemetryArray.push(pathRes)
|
|
373
|
+ Object.entries(res).forEach(([resourceKey, resourceValue]) => {
|
|
374
|
+ if (resourceKey === 'id') {
|
|
375
|
+ // pathRes = resourceValue
|
|
376
|
+ pathRes = '/' + pathObj + '/' + pathInst + '/' + resourceValue;
|
|
377
|
+ } else if (resourceKey === 'observe' && resourceValue) {
|
|
378
|
+ observeArray.push(pathRes);
|
|
379
|
+ } else if (resourceKey === 'attribute' && resourceValue) {
|
|
380
|
+ attributeArray.push(pathRes);
|
|
381
|
+ } else if (resourceKey === 'telemetry' && resourceValue) {
|
|
382
|
+ telemetryArray.push(pathRes);
|
373
|
383
|
}
|
374
|
384
|
});
|
375
|
385
|
});
|
...
|
...
|
@@ -396,19 +406,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
396
|
406
|
}
|
397
|
407
|
|
398
|
408
|
sortObjectKeyPathJson(key, value) {
|
399
|
|
- if (key == "keyName") {
|
|
409
|
+ if (key === 'keyName') {
|
400
|
410
|
return Object.keys(value).sort((a, b) => {
|
401
|
|
- let aLC = Array.from(a.substring(1).split('/'), Number);
|
402
|
|
- let bLC = Array.from(b.substring(1).split('/'), Number);
|
403
|
|
- return aLC[0] == bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0];
|
404
|
|
- }).reduce((r, k) => (r[k] = value[k], r), {});
|
|
411
|
+ const aLC = Array.from(a.substring(1).split('/'), Number);
|
|
412
|
+ const bLC = Array.from(b.substring(1).split('/'), Number);
|
|
413
|
+ return aLC[0] === bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0];
|
|
414
|
+ }).reduce((r, k) => r[k] = value[k], {});
|
405
|
415
|
} else {
|
406
|
|
- return value
|
|
416
|
+ return value;
|
407
|
417
|
}
|
408
|
418
|
}
|
409
|
419
|
|
410
|
420
|
updateKeyName(): void {
|
411
|
|
- let paths = new Set<string>();
|
|
421
|
+ const paths = new Set<string>();
|
412
|
422
|
if (this.configurationValue[this.observeAttr][this.attribute]) {
|
413
|
423
|
this.configurationValue[this.observeAttr][this.attribute].forEach(path => {
|
414
|
424
|
paths.add(path);
|
...
|
...
|
@@ -419,31 +429,32 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
419
|
429
|
paths.add(path);
|
420
|
430
|
});
|
421
|
431
|
}
|
422
|
|
- let keyNameNew = {};
|
|
432
|
+ const keyNameNew = {};
|
423
|
433
|
paths.forEach(path => {
|
424
|
|
- let pathParameter = this.findIndexsForIds(path);
|
|
434
|
+ const pathParameter = this.findIndexsForIds(path);
|
425
|
435
|
if (pathParameter.length === 3) {
|
426
|
|
- let value = this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M'][pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];
|
427
|
|
- keyNameNew[path] = value;
|
|
436
|
+ keyNameNew[path] = this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value
|
|
437
|
+ .clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];
|
428
|
438
|
}
|
429
|
439
|
});
|
430
|
|
- this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson("keyName", keyNameNew);
|
|
440
|
+ this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);
|
431
|
441
|
}
|
432
|
442
|
|
433
|
443
|
findIndexsForIds(path: string): number[] {
|
434
|
|
- let pathParameter = Array.from(path.substring(1).split('/'), Number);
|
435
|
|
- let pathParameterIndexes = [] as number[];
|
436
|
|
- let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M) as ObjectLwM2M[];
|
|
444
|
+ const pathParameter = Array.from(path.substring(1).split('/'), Number);
|
|
445
|
+ const pathParameterIndexes: number[] = [];
|
|
446
|
+ const objectsOld = deepClone(
|
|
447
|
+ this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[];
|
437
|
448
|
let isIdIndex = (element) => element.id === pathParameter[0];
|
438
|
|
- let objIndex = objectsOld.findIndex(isIdIndex);
|
|
449
|
+ const objIndex = objectsOld.findIndex(isIdIndex);
|
439
|
450
|
if (objIndex >= 0) {
|
440
|
451
|
pathParameterIndexes.push(objIndex);
|
441
|
452
|
isIdIndex = (element) => element.id === pathParameter[1];
|
442
|
|
- let instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex);
|
|
453
|
+ const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex);
|
443
|
454
|
if (instIndex >= 0) {
|
444
|
455
|
pathParameterIndexes.push(instIndex);
|
445
|
456
|
isIdIndex = (element) => element.id === pathParameter[2];
|
446
|
|
- let resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex);
|
|
457
|
+ const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex);
|
447
|
458
|
if (resIndex >= 0) {
|
448
|
459
|
pathParameterIndexes.push(resIndex);
|
449
|
460
|
}
|
...
|
...
|
@@ -453,7 +464,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
453
|
464
|
}
|
454
|
465
|
|
455
|
466
|
getObjectsFromJsonAllConfig(): number [] {
|
456
|
|
- let objectsIds = new Set<number>();
|
|
467
|
+ const objectsIds = new Set<number>();
|
457
|
468
|
if (this.configurationValue[this.observeAttr]) {
|
458
|
469
|
if (this.configurationValue[this.observeAttr][this.observe]) {
|
459
|
470
|
this.configurationValue[this.observeAttr][this.observe].forEach(obj => {
|
...
|
...
|
@@ -488,9 +499,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
488
|
499
|
}
|
489
|
500
|
|
490
|
501
|
removeObjectsList(value: ObjectLwM2M): void {
|
491
|
|
- let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M);
|
|
502
|
+ const objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M);
|
492
|
503
|
const isIdIndex = (element) => element.id === value.id;
|
493
|
|
- let index = objectsOld.findIndex(isIdIndex);
|
|
504
|
+ const index = objectsOld.findIndex(isIdIndex);
|
494
|
505
|
if (index >= 0) {
|
495
|
506
|
objectsOld.splice(index, 1);
|
496
|
507
|
}
|
...
|
...
|
@@ -504,7 +515,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
504
|
515
|
}
|
505
|
516
|
|
506
|
517
|
removeObserveAttrTelemetryFromJson(observeAttrTel: string, id: number): void {
|
507
|
|
- let isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id;
|
|
518
|
+ const isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id;
|
508
|
519
|
let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex);
|
509
|
520
|
while (index >= 0) {
|
510
|
521
|
this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1);
|
...
|
...
|
@@ -513,9 +524,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
513
|
524
|
}
|
514
|
525
|
|
515
|
526
|
removeKeyNameFromJson(id: number): void {
|
516
|
|
- let keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName];
|
517
|
|
- Object.keys(keyNmaeJson).forEach(function (key) {
|
518
|
|
- let idKey = Array.from(key.substring(1).split('/'), Number)[0];
|
|
527
|
+ const keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName];
|
|
528
|
+ Object.keys(keyNmaeJson).forEach(key => {
|
|
529
|
+ const idKey = Array.from(key.substring(1).split('/'), Number)[0];
|
519
|
530
|
if (idKey === id) {
|
520
|
531
|
delete keyNmaeJson[key];
|
521
|
532
|
}
|
...
|
...
|
|