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) {
delete configuration.type;
}
this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
setTimeout(() => {
this.deviceProfileTransportConfigurationFormGroup.updateValueAndValidity();
this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
}, 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,
KEY_NAME,
Lwm2mProfileConfigModels,
ModelValue,
ObjectLwM2M,
OBSERVE,
OBSERVE_ATTR_TELEMETRY,
@ -49,7 +48,7 @@ import {
TELEMETRY
} from './lwm2m-profile-config.models';
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 { Direction } from '@shared/models/page/sort-order';
import _ from 'lodash';
@ -226,32 +225,30 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}
private initWriteValue = (): void => {
const modelValue = {objectIds: [], objectsList: []} as ModelValue;
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
if (modelValue.objectIds.length > 0) {
const objectIds = this.getObjectsFromJsonAllConfig();
if (objectIds.length > 0) {
const sortOrder = {
property: 'id',
direction: Direction.ASC
};
this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe(
this.deviceProfileService.getLwm2mObjects(sortOrder, objectIds, null).subscribe(
(objectsList) => {
modelValue.objectsList = objectsList;
this.updateWriteValue(modelValue);
this.updateWriteValue(objectsList);
}
);
} else {
this.updateWriteValue(modelValue);
this.updateWriteValue([]);
}
}
private updateWriteValue = (value: ModelValue): void => {
private updateWriteValue = (value: ObjectLwM2M[]): void => {
const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ?
this.configurationValue.clientLwM2mSettings.fwUpdateResource : '';
const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ?
this.configurationValue.clientLwM2mSettings.swUpdateResource : '';
this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList),
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value),
bootstrap: this.configurationValue.bootstrap,
clientLwM2mSettings: {
clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
@ -334,6 +331,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const isNotZeroInstanceId = (instance) => !instance.includes('/0/');
return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId);
}
private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
const instancesPath = attribute.concat(telemetry)
.filter(instance => !instance.includes('/0/'))
@ -454,21 +452,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
});
}
});
if (isUndefined(this.configurationValue.observeAttr)) {
this.configurationValue.observeAttr = {
observe: observeArray,
attribute: attributeArray,
telemetry: telemetryArray,
keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew),
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;
}
this.configurationValue.observeAttr = {
observe: observeArray,
attribute: attributeArray,
telemetry: telemetryArray,
keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew),
attributeLwm2m: attributes
};
}
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 { Observable } from 'rxjs';
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 { Direction } from '@shared/models/page/sort-order';
import { isDefined, isDefinedAndNotNull, isString } from '@core/utils';
@ -54,7 +54,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
private requiredValue: boolean;
private dirty = false;
private modelValue: Array<string> = [];
lwm2mListFormGroup: FormGroup;
objectsList: Array<ObjectLwM2M> = [];
@ -92,7 +91,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
this.lwm2mListFormGroup.valueChanges.subscribe((value) => {
let formValue = null;
if (this.lwm2mListFormGroup.valid) {
formValue = value;
formValue = value.objectsList;
}
this.propagateChange(formValue);
});
@ -139,15 +138,13 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
}
}
writeValue(value: ModelValue): void {
writeValue(value: ObjectLwM2M[]): void {
this.searchText = '';
if (isDefinedAndNotNull(value)) {
if (Array.isArray(value.objectIds)) {
this.modelValue = value.objectIds;
this.objectsList = value.objectsList;
if (Array.isArray(value)) {
this.objectsList = value;
} else {
this.objectsList = [];
this.modelValue = [];
}
this.lwm2mListFormGroup.patchValue({objectsList: this.objectsList}, {emitEvent: false});
this.dirty = false;
@ -161,8 +158,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
}
private add(object: ObjectLwM2M): void {
if (isDefinedAndNotNull(this.modelValue) && this.modelValue.indexOf(object.keyId) === -1) {
this.modelValue.push(object.keyId);
if (isDefinedAndNotNull(this.objectsList) && this.objectsList.findIndex(item => item.keyId === object.keyId) === -1) {
this.objectsList.push(object);
this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
this.addList.next(this.objectsList);
@ -171,12 +167,10 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
}
remove = (object: ObjectLwM2M): void => {
let index = this.objectsList.indexOf(object);
const index = this.objectsList.indexOf(object);
if (index >= 0) {
this.objectsList.splice(index, 1);
this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
index = this.modelValue.indexOf(object.keyId);
this.modelValue.splice(index, 1);
this.removeList.next(object);
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 {
shortId: number;
lifetime: number;

Loading…
Cancel
Save