Browse Source

UI: LwM2M device profile refactoring object list component models data

pull/4844/head
Vladyslav_Prykhodko 5 years ago
committed by Andrew Shvayka
parent
commit
385c60a656
  1. 3
      ui-ngx/src/app/modules/home/components/profile/device/device-profile-transport-configuration.component.ts
  2. 42
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  3. 20
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts
  4. 5
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts

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

@ -89,9 +89,8 @@ export class DeviceProfileTransportConfigurationComponent implements ControlValu
if (configuration) { if (configuration) {
delete configuration.type; delete configuration.type;
} }
this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
setTimeout(() => { setTimeout(() => {
this.deviceProfileTransportConfigurationFormGroup.updateValueAndValidity(); this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
}, 0); }, 0);
} }

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

@ -38,7 +38,6 @@ import {
INSTANCES, INSTANCES,
KEY_NAME, KEY_NAME,
Lwm2mProfileConfigModels, Lwm2mProfileConfigModels,
ModelValue,
ObjectLwM2M, ObjectLwM2M,
OBSERVE, OBSERVE,
OBSERVE_ATTR_TELEMETRY, OBSERVE_ATTR_TELEMETRY,
@ -49,7 +48,7 @@ import {
TELEMETRY TELEMETRY
} from './lwm2m-profile-config.models'; } from './lwm2m-profile-config.models';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { deepClone, isDefinedAndNotNull, isEmpty, isUndefined } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isEmpty } 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'; import _ from 'lodash';
@ -226,32 +225,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private initWriteValue = (): void => { private initWriteValue = (): void => {
const modelValue = {objectIds: [], objectsList: []} as ModelValue; const objectIds = this.getObjectsFromJsonAllConfig();
modelValue.objectIds = this.getObjectsFromJsonAllConfig(); if (objectIds.length > 0) {
if (modelValue.objectIds.length > 0) {
const sortOrder = { const sortOrder = {
property: 'id', property: 'id',
direction: Direction.ASC direction: Direction.ASC
}; };
this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe( this.deviceProfileService.getLwm2mObjects(sortOrder, objectIds, null).subscribe(
(objectsList) => { (objectsList) => {
modelValue.objectsList = objectsList; this.updateWriteValue(objectsList);
this.updateWriteValue(modelValue);
} }
); );
} else { } else {
this.updateWriteValue(modelValue); this.updateWriteValue([]);
} }
} }
private updateWriteValue = (value: ModelValue): void => { private updateWriteValue = (value: ObjectLwM2M[]): void => {
const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ? const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ?
this.configurationValue.clientLwM2mSettings.fwUpdateResource : ''; this.configurationValue.clientLwM2mSettings.fwUpdateResource : '';
const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ? const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ?
this.configurationValue.clientLwM2mSettings.swUpdateResource : ''; this.configurationValue.clientLwM2mSettings.swUpdateResource : '';
this.lwm2mDeviceProfileFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value, objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList), observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value),
bootstrap: this.configurationValue.bootstrap, bootstrap: this.configurationValue.bootstrap,
clientLwM2mSettings: { clientLwM2mSettings: {
clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
@ -334,6 +331,7 @@ 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/'))
@ -454,21 +452,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}); });
} }
}); });
if (isUndefined(this.configurationValue.observeAttr)) { this.configurationValue.observeAttr = {
this.configurationValue.observeAttr = { observe: observeArray,
observe: observeArray, attribute: attributeArray,
attribute: attributeArray, telemetry: telemetryArray,
telemetry: telemetryArray, keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew),
keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew), attributeLwm2m: attributes
attributeLwm2m: attributes };
};
} else {
this.configurationValue.observeAttr.observe = observeArray;
this.configurationValue.observeAttr.attribute = attributeArray;
this.configurationValue.observeAttr.telemetry = telemetryArray;
this.configurationValue.observeAttr.keyName = this.sortObjectKeyPathJson(KEY_NAME, keyNameNew);
this.configurationValue.observeAttr.attributeLwm2m = attributes;
}
} }
sortObjectKeyPathJson = (key: string, value: object): object => { sortObjectKeyPathJson = (key: string, value: object): object => {

20
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts

@ -28,7 +28,7 @@ import {
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { distinctUntilChanged, filter, mergeMap, share, tap } from 'rxjs/operators'; import { distinctUntilChanged, filter, mergeMap, share, tap } from 'rxjs/operators';
import { ModelValue, ObjectLwM2M, PAGE_SIZE_LIMIT } from './lwm2m-profile-config.models'; import { ObjectLwM2M, PAGE_SIZE_LIMIT } from './lwm2m-profile-config.models';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import { isDefined, isDefinedAndNotNull, isString } from '@core/utils'; import { isDefined, isDefinedAndNotNull, isString } from '@core/utils';
@ -54,7 +54,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
private requiredValue: boolean; private requiredValue: boolean;
private dirty = false; private dirty = false;
private modelValue: Array<string> = [];
lwm2mListFormGroup: FormGroup; lwm2mListFormGroup: FormGroup;
objectsList: Array<ObjectLwM2M> = []; objectsList: Array<ObjectLwM2M> = [];
@ -92,7 +91,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
this.lwm2mListFormGroup.valueChanges.subscribe((value) => { this.lwm2mListFormGroup.valueChanges.subscribe((value) => {
let formValue = null; let formValue = null;
if (this.lwm2mListFormGroup.valid) { if (this.lwm2mListFormGroup.valid) {
formValue = value; formValue = value.objectsList;
} }
this.propagateChange(formValue); this.propagateChange(formValue);
}); });
@ -139,15 +138,13 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
} }
writeValue(value: ModelValue): void { writeValue(value: ObjectLwM2M[]): void {
this.searchText = ''; this.searchText = '';
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
if (Array.isArray(value.objectIds)) { if (Array.isArray(value)) {
this.modelValue = value.objectIds; this.objectsList = value;
this.objectsList = value.objectsList;
} else { } else {
this.objectsList = []; this.objectsList = [];
this.modelValue = [];
} }
this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false}); this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false});
this.dirty = false; this.dirty = false;
@ -161,8 +158,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
private add(object: ObjectLwM2M): void { private add(object: ObjectLwM2M): void {
if (isDefinedAndNotNull(this.modelValue) && this.modelValue.indexOf(object.keyId) === -1) { if (isDefinedAndNotNull(this.objectsList) && this.objectsList.findIndex(item => item.keyId === object.keyId) === -1) {
this.modelValue.push(object.keyId);
this.objectsList.push(object); this.objectsList.push(object);
this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
this.addList.next(this.objectsList); this.addList.next(this.objectsList);
@ -171,12 +167,10 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
remove = (object: ObjectLwM2M): void => { remove = (object: ObjectLwM2M): void => {
let index = this.objectsList.indexOf(object); const index = this.objectsList.indexOf(object);
if (index >= 0) { if (index >= 0) {
this.objectsList.splice(index, 1); this.objectsList.splice(index, 1);
this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
index = this.modelValue.indexOf(object.keyId);
this.modelValue.splice(index, 1);
this.removeList.next(object); this.removeList.next(object);
this.clear(); this.clear();
} }

5
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts

@ -127,11 +127,6 @@ export const PowerModeTranslationMap = new Map<PowerMode, string>(
] ]
); );
export interface ModelValue {
objectIds: string[];
objectsList: ObjectLwM2M[];
}
export interface BootstrapServersSecurityConfig { export interface BootstrapServersSecurityConfig {
shortId: number; shortId: number;
lifetime: number; lifetime: number;

Loading…
Cancel
Save