Commit 385c60a6565b56b39bc62af7b440d5926c822eda

Authored by Vladyslav_Prykhodko
Committed by Andrew Shvayka
1 parent a230e583

UI: LwM2M device profile refactoring object list component models data

... ... @@ -89,9 +89,8 @@ export class DeviceProfileTransportConfigurationComponent implements ControlValu
89 89 if (configuration) {
90 90 delete configuration.type;
91 91 }
92   - this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
93 92 setTimeout(() => {
94   - this.deviceProfileTransportConfigurationFormGroup.updateValueAndValidity();
  93 + this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
95 94 }, 0);
96 95 }
97 96
... ...
... ... @@ -38,7 +38,6 @@ import {
38 38 INSTANCES,
39 39 KEY_NAME,
40 40 Lwm2mProfileConfigModels,
41   - ModelValue,
42 41 ObjectLwM2M,
43 42 OBSERVE,
44 43 OBSERVE_ATTR_TELEMETRY,
... ... @@ -49,7 +48,7 @@ import {
49 48 TELEMETRY
50 49 } from './lwm2m-profile-config.models';
51 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 52 import { JsonArray, JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
54 53 import { Direction } from '@shared/models/page/sort-order';
55 54 import _ from 'lodash';
... ... @@ -226,32 +225,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
226 225 }
227 226
228 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 230 const sortOrder = {
233 231 property: 'id',
234 232 direction: Direction.ASC
235 233 };
236   - this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe(
  234 + this.deviceProfileService.getLwm2mObjects(sortOrder, objectIds, null).subscribe(
237 235 (objectsList) => {
238   - modelValue.objectsList = objectsList;
239   - this.updateWriteValue(modelValue);
  236 + this.updateWriteValue(objectsList);
240 237 }
241 238 );
242 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 245 const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ?
249 246 this.configurationValue.clientLwM2mSettings.fwUpdateResource : '';
250 247 const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ?
251 248 this.configurationValue.clientLwM2mSettings.swUpdateResource : '';
252 249 this.lwm2mDeviceProfileFormGroup.patchValue({
253 250 objectIds: value,
254   - observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList),
  251 + observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value),
255 252 bootstrap: this.configurationValue.bootstrap,
256 253 clientLwM2mSettings: {
257 254 clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
... ... @@ -334,6 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
334 331 const isNotZeroInstanceId = (instance) => !instance.includes('/0/');
335 332 return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId);
336 333 }
  334 +
337 335 private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
338 336 const instancesPath = attribute.concat(telemetry)
339 337 .filter(instance => !instance.includes('/0/'))
... ... @@ -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 464 sortObjectKeyPathJson = (key: string, value: object): object => {
... ...
... ... @@ -28,7 +28,7 @@ import {
28 28 import { coerceBooleanProperty } from '@angular/cdk/coercion';
29 29 import { Observable } from 'rxjs';
30 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 32 import { DeviceProfileService } from '@core/http/device-profile.service';
33 33 import { Direction } from '@shared/models/page/sort-order';
34 34 import { isDefined, isDefinedAndNotNull, isString } from '@core/utils';
... ... @@ -54,7 +54,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
54 54
55 55 private requiredValue: boolean;
56 56 private dirty = false;
57   - private modelValue: Array<string> = [];
58 57
59 58 lwm2mListFormGroup: FormGroup;
60 59 objectsList: Array<ObjectLwM2M> = [];
... ... @@ -92,7 +91,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
92 91 this.lwm2mListFormGroup.valueChanges.subscribe((value) => {
93 92 let formValue = null;
94 93 if (this.lwm2mListFormGroup.valid) {
95   - formValue = value;
  94 + formValue = value.objectsList;
96 95 }
97 96 this.propagateChange(formValue);
98 97 });
... ... @@ -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 142 this.searchText = '';
144 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 146 } else {
149 147 this.objectsList = [];
150   - this.modelValue = [];
151 148 }
152 149 this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false});
153 150 this.dirty = false;
... ... @@ -161,8 +158,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
161 158 }
162 159
163 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 162 this.objectsList.push(object);
167 163 this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
168 164 this.addList.next(this.objectsList);
... ... @@ -171,12 +167,10 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
171 167 }
172 168
173 169 remove = (object: ObjectLwM2M): void => {
174   - let index = this.objectsList.indexOf(object);
  170 + const index = this.objectsList.indexOf(object);
175 171 if (index >= 0) {
176 172 this.objectsList.splice(index, 1);
177 173 this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
178   - index = this.modelValue.indexOf(object.keyId);
179   - this.modelValue.splice(index, 1);
180 174 this.removeList.next(object);
181 175 this.clear();
182 176 }
... ...
... ... @@ -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 130 export interface BootstrapServersSecurityConfig {
136 131 shortId: number;
137 132 lifetime: number;
... ...