Commit 385c60a6565b56b39bc62af7b440d5926c822eda
Committed by
Andrew Shvayka
1 parent
a230e583
UI: LwM2M device profile refactoring object list component models data
Showing
4 changed files
with
24 additions
and
46 deletions
@@ -89,9 +89,8 @@ export class DeviceProfileTransportConfigurationComponent implements ControlValu | @@ -89,9 +89,8 @@ export class DeviceProfileTransportConfigurationComponent implements ControlValu | ||
89 | if (configuration) { | 89 | if (configuration) { |
90 | delete configuration.type; | 90 | delete configuration.type; |
91 | } | 91 | } |
92 | - this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false}); | ||
93 | setTimeout(() => { | 92 | setTimeout(() => { |
94 | - this.deviceProfileTransportConfigurationFormGroup.updateValueAndValidity(); | 93 | + this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false}); |
95 | }, 0); | 94 | }, 0); |
96 | } | 95 | } |
97 | 96 |
@@ -38,7 +38,6 @@ import { | @@ -38,7 +38,6 @@ import { | ||
38 | INSTANCES, | 38 | INSTANCES, |
39 | KEY_NAME, | 39 | KEY_NAME, |
40 | Lwm2mProfileConfigModels, | 40 | Lwm2mProfileConfigModels, |
41 | - ModelValue, | ||
42 | ObjectLwM2M, | 41 | ObjectLwM2M, |
43 | OBSERVE, | 42 | OBSERVE, |
44 | OBSERVE_ATTR_TELEMETRY, | 43 | OBSERVE_ATTR_TELEMETRY, |
@@ -49,7 +48,7 @@ import { | @@ -49,7 +48,7 @@ import { | ||
49 | TELEMETRY | 48 | TELEMETRY |
50 | } from './lwm2m-profile-config.models'; | 49 | } from './lwm2m-profile-config.models'; |
51 | import { DeviceProfileService } from '@core/http/device-profile.service'; | 50 | import { DeviceProfileService } from '@core/http/device-profile.service'; |
52 | -import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; | 51 | +import { deepClone, isDefinedAndNotNull, isEmpty } from '@core/utils'; |
53 | import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; | 52 | import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; |
54 | import { Direction } from '@shared/models/page/sort-order'; | 53 | import { Direction } from '@shared/models/page/sort-order'; |
55 | import _ from 'lodash'; | 54 | import _ from 'lodash'; |
@@ -226,32 +225,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -226,32 +225,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
226 | } | 225 | } |
227 | 226 | ||
228 | private initWriteValue = (): void => { | 227 | private initWriteValue = (): void => { |
229 | - const modelValue = {objectIds: [], objectsList: []} as ModelValue; | ||
230 | - modelValue.objectIds = this.getObjectsFromJsonAllConfig(); | ||
231 | - if (modelValue.objectIds.length > 0) { | 228 | + const objectIds = this.getObjectsFromJsonAllConfig(); |
229 | + if (objectIds.length > 0) { | ||
232 | const sortOrder = { | 230 | const sortOrder = { |
233 | property: 'id', | 231 | property: 'id', |
234 | direction: Direction.ASC | 232 | direction: Direction.ASC |
235 | }; | 233 | }; |
236 | - this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe( | 234 | + this.deviceProfileService.getLwm2mObjects(sortOrder, objectIds, null).subscribe( |
237 | (objectsList) => { | 235 | (objectsList) => { |
238 | - modelValue.objectsList = objectsList; | ||
239 | - this.updateWriteValue(modelValue); | 236 | + this.updateWriteValue(objectsList); |
240 | } | 237 | } |
241 | ); | 238 | ); |
242 | } else { | 239 | } else { |
243 | - this.updateWriteValue(modelValue); | 240 | + this.updateWriteValue([]); |
244 | } | 241 | } |
245 | } | 242 | } |
246 | 243 | ||
247 | - private updateWriteValue = (value: ModelValue): void => { | 244 | + private updateWriteValue = (value: ObjectLwM2M[]): void => { |
248 | const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ? | 245 | const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ? |
249 | this.configurationValue.clientLwM2mSettings.fwUpdateResource : ''; | 246 | this.configurationValue.clientLwM2mSettings.fwUpdateResource : ''; |
250 | const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ? | 247 | const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ? |
251 | this.configurationValue.clientLwM2mSettings.swUpdateResource : ''; | 248 | this.configurationValue.clientLwM2mSettings.swUpdateResource : ''; |
252 | this.lwm2mDeviceProfileFormGroup.patchValue({ | 249 | this.lwm2mDeviceProfileFormGroup.patchValue({ |
253 | objectIds: value, | 250 | objectIds: value, |
254 | - observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList), | 251 | + observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value), |
255 | bootstrap: this.configurationValue.bootstrap, | 252 | bootstrap: this.configurationValue.bootstrap, |
256 | clientLwM2mSettings: { | 253 | clientLwM2mSettings: { |
257 | clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, | 254 | clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, |
@@ -334,6 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -334,6 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
334 | const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); | 331 | const isNotZeroInstanceId = (instance) => !instance.includes('/0/'); |
335 | return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); | 332 | return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId); |
336 | } | 333 | } |
334 | + | ||
337 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { | 335 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { |
338 | const instancesPath = attribute.concat(telemetry) | 336 | const instancesPath = attribute.concat(telemetry) |
339 | .filter(instance => !instance.includes('/0/')) | 337 | .filter(instance => !instance.includes('/0/')) |
@@ -454,21 +452,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -454,21 +452,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
454 | }); | 452 | }); |
455 | } | 453 | } |
456 | }); | 454 | }); |
457 | - if (isUndefined(this.configurationValue.observeAttr)) { | ||
458 | - this.configurationValue.observeAttr = { | ||
459 | - observe: observeArray, | ||
460 | - attribute: attributeArray, | ||
461 | - telemetry: telemetryArray, | ||
462 | - keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew), | ||
463 | - attributeLwm2m: attributes | ||
464 | - }; | ||
465 | - } else { | ||
466 | - this.configurationValue.observeAttr.observe = observeArray; | ||
467 | - this.configurationValue.observeAttr.attribute = attributeArray; | ||
468 | - this.configurationValue.observeAttr.telemetry = telemetryArray; | ||
469 | - this.configurationValue.observeAttr.keyName = this.sortObjectKeyPathJson(KEY_NAME, keyNameNew); | ||
470 | - this.configurationValue.observeAttr.attributeLwm2m = attributes; | ||
471 | - } | 455 | + this.configurationValue.observeAttr = { |
456 | + observe: observeArray, | ||
457 | + attribute: attributeArray, | ||
458 | + telemetry: telemetryArray, | ||
459 | + keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew), | ||
460 | + attributeLwm2m: attributes | ||
461 | + }; | ||
472 | } | 462 | } |
473 | 463 | ||
474 | sortObjectKeyPathJson = (key: string, value: object): object => { | 464 | sortObjectKeyPathJson = (key: string, value: object): object => { |
@@ -28,7 +28,7 @@ import { | @@ -28,7 +28,7 @@ import { | ||
28 | import { coerceBooleanProperty } from '@angular/cdk/coercion'; | 28 | import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
29 | import { Observable } from 'rxjs'; | 29 | import { Observable } from 'rxjs'; |
30 | import { distinctUntilChanged, filter, mergeMap, share, tap } from 'rxjs/operators'; | 30 | import { distinctUntilChanged, filter, mergeMap, share, tap } from 'rxjs/operators'; |
31 | -import { ModelValue, ObjectLwM2M, PAGE_SIZE_LIMIT } from './lwm2m-profile-config.models'; | 31 | +import { ObjectLwM2M, PAGE_SIZE_LIMIT } from './lwm2m-profile-config.models'; |
32 | import { DeviceProfileService } from '@core/http/device-profile.service'; | 32 | import { DeviceProfileService } from '@core/http/device-profile.service'; |
33 | import { Direction } from '@shared/models/page/sort-order'; | 33 | import { Direction } from '@shared/models/page/sort-order'; |
34 | import { isDefined, isDefinedAndNotNull, isString } from '@core/utils'; | 34 | import { isDefined, isDefinedAndNotNull, isString } from '@core/utils'; |
@@ -54,7 +54,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -54,7 +54,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
54 | 54 | ||
55 | private requiredValue: boolean; | 55 | private requiredValue: boolean; |
56 | private dirty = false; | 56 | private dirty = false; |
57 | - private modelValue: Array<string> = []; | ||
58 | 57 | ||
59 | lwm2mListFormGroup: FormGroup; | 58 | lwm2mListFormGroup: FormGroup; |
60 | objectsList: Array<ObjectLwM2M> = []; | 59 | objectsList: Array<ObjectLwM2M> = []; |
@@ -92,7 +91,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -92,7 +91,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
92 | this.lwm2mListFormGroup.valueChanges.subscribe((value) => { | 91 | this.lwm2mListFormGroup.valueChanges.subscribe((value) => { |
93 | let formValue = null; | 92 | let formValue = null; |
94 | if (this.lwm2mListFormGroup.valid) { | 93 | if (this.lwm2mListFormGroup.valid) { |
95 | - formValue = value; | 94 | + formValue = value.objectsList; |
96 | } | 95 | } |
97 | this.propagateChange(formValue); | 96 | this.propagateChange(formValue); |
98 | }); | 97 | }); |
@@ -139,15 +138,13 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -139,15 +138,13 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
139 | } | 138 | } |
140 | } | 139 | } |
141 | 140 | ||
142 | - writeValue(value: ModelValue): void { | 141 | + writeValue(value: ObjectLwM2M[]): void { |
143 | this.searchText = ''; | 142 | this.searchText = ''; |
144 | if (isDefinedAndNotNull(value)) { | 143 | if (isDefinedAndNotNull(value)) { |
145 | - if (Array.isArray(value.objectIds)) { | ||
146 | - this.modelValue = value.objectIds; | ||
147 | - this.objectsList = value.objectsList; | 144 | + if (Array.isArray(value)) { |
145 | + this.objectsList = value; | ||
148 | } else { | 146 | } else { |
149 | this.objectsList = []; | 147 | this.objectsList = []; |
150 | - this.modelValue = []; | ||
151 | } | 148 | } |
152 | this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false}); | 149 | this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false}); |
153 | this.dirty = false; | 150 | this.dirty = false; |
@@ -161,8 +158,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -161,8 +158,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
161 | } | 158 | } |
162 | 159 | ||
163 | private add(object: ObjectLwM2M): void { | 160 | private add(object: ObjectLwM2M): void { |
164 | - if (isDefinedAndNotNull(this.modelValue) && this.modelValue.indexOf(object.keyId) === -1) { | ||
165 | - this.modelValue.push(object.keyId); | 161 | + if (isDefinedAndNotNull(this.objectsList) && this.objectsList.findIndex(item => item.keyId === object.keyId) === -1) { |
166 | this.objectsList.push(object); | 162 | this.objectsList.push(object); |
167 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); | 163 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); |
168 | this.addList.next(this.objectsList); | 164 | this.addList.next(this.objectsList); |
@@ -171,12 +167,10 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -171,12 +167,10 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
171 | } | 167 | } |
172 | 168 | ||
173 | remove = (object: ObjectLwM2M): void => { | 169 | remove = (object: ObjectLwM2M): void => { |
174 | - let index = this.objectsList.indexOf(object); | 170 | + const index = this.objectsList.indexOf(object); |
175 | if (index >= 0) { | 171 | if (index >= 0) { |
176 | this.objectsList.splice(index, 1); | 172 | this.objectsList.splice(index, 1); |
177 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); | 173 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); |
178 | - index = this.modelValue.indexOf(object.keyId); | ||
179 | - this.modelValue.splice(index, 1); | ||
180 | this.removeList.next(object); | 174 | this.removeList.next(object); |
181 | this.clear(); | 175 | this.clear(); |
182 | } | 176 | } |
@@ -127,11 +127,6 @@ export const PowerModeTranslationMap = new Map<PowerMode, string>( | @@ -127,11 +127,6 @@ export const PowerModeTranslationMap = new Map<PowerMode, string>( | ||
127 | ] | 127 | ] |
128 | ); | 128 | ); |
129 | 129 | ||
130 | -export interface ModelValue { | ||
131 | - objectIds: string[]; | ||
132 | - objectsList: ObjectLwM2M[]; | ||
133 | -} | ||
134 | - | ||
135 | export interface BootstrapServersSecurityConfig { | 130 | export interface BootstrapServersSecurityConfig { |
136 | shortId: number; | 131 | shortId: number; |
137 | lifetime: number; | 132 | lifetime: number; |