Lwm2m: front: refactoring
This commit is contained in:
parent
4382c0c4b8
commit
d56c33ddb1
@ -139,7 +139,7 @@ export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor {
|
|||||||
Validators.maxLength(this.lenMaxServerPublicKey)]);
|
Validators.maxLength(this.lenMaxServerPublicKey)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any): void {
|
writeValue(value: ServerSecurityConfig): void {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.updateValueFields(value);
|
this.updateValueFields(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,12 +21,11 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '@app/core/core.state';
|
import { AppState } from '@app/core/core.state';
|
||||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
import {
|
import {
|
||||||
ID, INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
|
INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
|
||||||
getDefaultProfileConfig,
|
getDefaultProfileConfig,
|
||||||
Instance,
|
|
||||||
ObjectLwM2M,
|
ObjectLwM2M,
|
||||||
ProfileConfigModels,
|
ProfileConfigModels,
|
||||||
ResourceLwM2M
|
ModelValue
|
||||||
} from './profile-config.models';
|
} from './profile-config.models';
|
||||||
import { DeviceProfileService } from '@core/http/device-profile.service';
|
import { DeviceProfileService } from '@core/http/device-profile.service';
|
||||||
import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
|
import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
|
||||||
@ -113,7 +112,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any | null): void {
|
writeValue(value: ProfileConfigModels | null): void {
|
||||||
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
|
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
|
||||||
this.lwm2mDeviceConfigFormGroup.patchValue({
|
this.lwm2mDeviceConfigFormGroup.patchValue({
|
||||||
configurationJson: this.configurationValue
|
configurationJson: this.configurationValue
|
||||||
@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initWriteValue = (): void => {
|
private initWriteValue = (): void => {
|
||||||
const modelValue = {objectIds: null, objectsList: []};
|
const modelValue = {objectIds: null, objectsList: []} as ModelValue;
|
||||||
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig();
|
||||||
if (modelValue.objectIds !== null) {
|
if (modelValue.objectIds !== null) {
|
||||||
const sortOrder = {
|
const sortOrder = {
|
||||||
@ -140,11 +139,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateWriteValue = (value: any): void => {
|
private updateWriteValue = (value: ModelValue): void => {
|
||||||
const objectsList = value.objectsList;
|
|
||||||
this.lwm2mDeviceProfileFormGroup.patchValue({
|
this.lwm2mDeviceProfileFormGroup.patchValue({
|
||||||
objectIds: value,
|
objectIds: value,
|
||||||
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList),
|
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value['objectsList']),
|
||||||
shortId: this.configurationValue.bootstrap.servers.shortId,
|
shortId: this.configurationValue.bootstrap.servers.shortId,
|
||||||
lifetime: this.configurationValue.bootstrap.servers.lifetime,
|
lifetime: this.configurationValue.bootstrap.servers.lifetime,
|
||||||
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
|
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-profile-lwm2m-object-add-instances-list',
|
selector: 'tb-profile-lwm2m-object-add-instances-list',
|
||||||
templateUrl: './lwm2m-object-add-instances-list.component.html',
|
templateUrl: './lwm2m-object-add-instances-list.component.html',
|
||||||
styleUrls: [],
|
|
||||||
providers: [{
|
providers: [{
|
||||||
provide: NG_VALUE_ACCESSOR,
|
provide: NG_VALUE_ACCESSOR,
|
||||||
useExisting: forwardRef(() => Lwm2mObjectAddInstancesListComponent),
|
useExisting: forwardRef(() => Lwm2mObjectAddInstancesListComponent),
|
||||||
|
|||||||
@ -30,8 +30,7 @@ export interface Lwm2mObjectAddInstancesData {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-lwm2m-object-add-instances',
|
selector: 'tb-lwm2m-object-add-instances',
|
||||||
templateUrl: './lwm2m-object-add-instances.component.html',
|
templateUrl: './lwm2m-object-add-instances.component.html'
|
||||||
styleUrls: []
|
|
||||||
})
|
})
|
||||||
export class Lwm2mObjectAddInstancesComponent extends DialogComponent<Lwm2mObjectAddInstancesComponent, object> implements OnInit {
|
export class Lwm2mObjectAddInstancesComponent extends DialogComponent<Lwm2mObjectAddInstancesComponent, object> implements OnInit {
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import { Store } from '@ngrx/store';
|
|||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { filter, map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators';
|
import { filter, map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators';
|
||||||
import { ObjectLwM2M } from './profile-config.models';
|
import { ModelValue, ObjectLwM2M } from './profile-config.models';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
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';
|
||||||
@ -120,7 +120,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any): void {
|
writeValue(value: ModelValue): void {
|
||||||
this.searchText = '';
|
this.searchText = '';
|
||||||
if (isDefinedAndNotNull(value)) {
|
if (isDefinedAndNotNull(value)) {
|
||||||
if (Array.isArray(value.objectIds)) {
|
if (Array.isArray(value.objectIds)) {
|
||||||
@ -193,7 +193,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
|||||||
return this.lw2mModels;
|
return this.lw2mModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onFocus = (): void => {
|
onFocus = (): void => {
|
||||||
if (!this.dirty) {
|
if (!this.dirty) {
|
||||||
this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true});
|
this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true});
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-profile-lwm2m-observe-attr-telemetry-resource',
|
selector: 'tb-profile-lwm2m-observe-attr-telemetry-resource',
|
||||||
templateUrl: './lwm2m-observe-attr-telemetry-resource.component.html',
|
templateUrl: './lwm2m-observe-attr-telemetry-resource.component.html',
|
||||||
styleUrls: [],
|
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: NG_VALUE_ACCESSOR,
|
provide: NG_VALUE_ACCESSOR,
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import {
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
import { Instance, ObjectLwM2M, ResourceLwM2M } from './profile-config.models';
|
import { CLIENT_LWM2M, Instance, INSTANCES, ObjectLwM2M, ResourceLwM2M, RESOURCES } from './profile-config.models';
|
||||||
import { deepClone, isDefinedAndNotNull, isEqual, isUndefined } from '@core/utils';
|
import { deepClone, isDefinedAndNotNull, isEqual, isUndefined } from '@core/utils';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
@ -78,7 +78,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
public translate: TranslateService) {
|
public translate: TranslateService) {
|
||||||
this.observeAttrTelemetryFormGroup = this.fb.group({
|
this.observeAttrTelemetryFormGroup = this.fb.group({
|
||||||
clientLwM2M: this.fb.array([])
|
[CLIENT_LWM2M]: this.fb.array([])
|
||||||
});
|
});
|
||||||
this.observeAttrTelemetryFormGroup.valueChanges.subscribe(value => {
|
this.observeAttrTelemetryFormGroup.valueChanges.subscribe(value => {
|
||||||
if (isUndefined(this.disabled) || !this.disabled) {
|
if (isUndefined(this.disabled) || !this.disabled) {
|
||||||
@ -87,7 +87,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private propagateChange = (v: any) => { };
|
private propagateChange = (v: any) => {
|
||||||
|
};
|
||||||
|
|
||||||
registerOnChange(fn: any): void {
|
registerOnChange(fn: any): void {
|
||||||
this.propagateChange = fn;
|
this.propagateChange = fn;
|
||||||
@ -123,14 +124,14 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any): void {
|
writeValue(value: {}): void {
|
||||||
if (isDefinedAndNotNull(value)) {
|
if (isDefinedAndNotNull(value)) {
|
||||||
this.buildClientObjectsLwM2M(value.clientLwM2M);
|
this.buildClientObjectsLwM2M(value[CLIENT_LWM2M]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildClientObjectsLwM2M = (objectsLwM2M: ObjectLwM2M []): void => {
|
private buildClientObjectsLwM2M = (objectsLwM2M: ObjectLwM2M []): void => {
|
||||||
this.observeAttrTelemetryFormGroup.setControl('clientLwM2M',
|
this.observeAttrTelemetryFormGroup.setControl(CLIENT_LWM2M,
|
||||||
this.createObjectsLwM2M(objectsLwM2M)
|
this.createObjectsLwM2M(objectsLwM2M)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -157,23 +158,23 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
get clientLwM2MFormArray(): FormArray {
|
get clientLwM2MFormArray(): FormArray {
|
||||||
return this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray;
|
return this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
instancesLwm2mFormArray = (objectLwM2M: AbstractControl): FormArray => {
|
instancesLwm2mFormArray = (objectLwM2M: AbstractControl): FormArray => {
|
||||||
return objectLwM2M.get('instances') as FormArray;
|
return objectLwM2M.get(INSTANCES) as FormArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeInstanceResourcesCheckBox = (value: boolean, instance: AbstractControl, type: string): void => {
|
changeInstanceResourcesCheckBox = (value: boolean, instance: AbstractControl, type: string): void => {
|
||||||
const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]);
|
const resources = deepClone(instance.get(RESOURCES).value as ResourceLwM2M[]);
|
||||||
resources.forEach(resource => resource[type] = value);
|
resources.forEach(resource => resource[type] = value);
|
||||||
instance.get('resources').patchValue(resources);
|
instance.get(RESOURCES).patchValue(resources);
|
||||||
this.propagateChange(this.observeAttrTelemetryFormGroup.value);
|
this.propagateChange(this.observeAttrTelemetryFormGroup.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateValidators = (): void => {
|
private updateValidators = (): void => {
|
||||||
this.observeAttrTelemetryFormGroup.get('clientLwM2M').setValidators(this.required ? Validators.required : []);
|
this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).setValidators(this.required ? Validators.required : []);
|
||||||
this.observeAttrTelemetryFormGroup.get('clientLwM2M').updateValueAndValidity();
|
this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).updateValueAndValidity();
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByParams = (index: number, element: any): number => {
|
trackByParams = (index: number, element: any): number => {
|
||||||
@ -181,7 +182,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
getIndeterminate = (instance: AbstractControl, type: string): boolean => {
|
getIndeterminate = (instance: AbstractControl, type: string): boolean => {
|
||||||
const resources = instance.get('resources').value as ResourceLwM2M[];
|
const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
|
||||||
if (isDefinedAndNotNull(resources)) {
|
if (isDefinedAndNotNull(resources)) {
|
||||||
const checkedResource = resources.filter(resource => resource[type]);
|
const checkedResource = resources.filter(resource => resource[type]);
|
||||||
return checkedResource.length !== 0 && checkedResource.length !== resources.length;
|
return checkedResource.length !== 0 && checkedResource.length !== resources.length;
|
||||||
@ -190,7 +191,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChecked = (instance: AbstractControl, type: string): boolean => {
|
getChecked = (instance: AbstractControl, type: string): boolean => {
|
||||||
const resources = instance.get('resources').value as ResourceLwM2M[];
|
const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
|
||||||
return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]);
|
return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,10 +240,10 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateInstancesIds = (data: Lwm2mObjectAddInstancesData): void => {
|
private updateInstancesIds = (data: Lwm2mObjectAddInstancesData): void => {
|
||||||
const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray).controls
|
const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray).controls
|
||||||
.find(e => e.value.id === data.objectId) as FormGroup;
|
.find(e => e.value.id === data.objectId) as FormGroup;
|
||||||
const instancesArray = objectLwM2MFormGroup.value.instances as Instance [];
|
const instancesArray = objectLwM2MFormGroup.value.instances as Instance [];
|
||||||
const instancesFormArray = objectLwM2MFormGroup.get('instances') as FormArray;
|
const instancesFormArray = objectLwM2MFormGroup.get(INSTANCES) as FormArray;
|
||||||
const instance0 = deepClone(instancesFormArray.at(0).value as Instance);
|
const instance0 = deepClone(instancesFormArray.at(0).value as Instance);
|
||||||
instance0.resources.forEach(r => {
|
instance0.resources.forEach(r => {
|
||||||
r.attribute = false;
|
r.attribute = false;
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
|
import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
|
||||||
|
|
||||||
export const ID = 'id';
|
|
||||||
export const INSTANCES = 'instances';
|
export const INSTANCES = 'instances';
|
||||||
export const RESOURCES = 'resources';
|
export const RESOURCES = 'resources';
|
||||||
export const OBSERVE_ATTR_TELEMETRY = 'observeAttrTelemetry';
|
export const OBSERVE_ATTR_TELEMETRY = 'observeAttrTelemetry';
|
||||||
@ -24,6 +23,7 @@ export const OBSERVE = 'observe';
|
|||||||
export const ATTRIBUTE = 'attribute';
|
export const ATTRIBUTE = 'attribute';
|
||||||
export const TELEMETRY = 'telemetry';
|
export const TELEMETRY = 'telemetry';
|
||||||
export const KEY_NAME = 'keyName';
|
export const KEY_NAME = 'keyName';
|
||||||
|
export const CLIENT_LWM2M = 'clientLwM2M';
|
||||||
export const DEFAULT_ID_SERVER = 123;
|
export const DEFAULT_ID_SERVER = 123;
|
||||||
export const DEFAULT_ID_BOOTSTRAP = 111;
|
export const DEFAULT_ID_BOOTSTRAP = 111;
|
||||||
export const DEFAULT_HOST_NAME = 'localhost';
|
export const DEFAULT_HOST_NAME = 'localhost';
|
||||||
@ -58,6 +58,11 @@ export const SECURITY_CONFIG_MODE_NAMES = new Map<SECURITY_CONFIG_MODE, string>(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export interface ModelValue {
|
||||||
|
objectIds: number[] | null,
|
||||||
|
objectsList: ObjectLwM2M[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface BootstrapServersSecurityConfig {
|
export interface BootstrapServersSecurityConfig {
|
||||||
shortId: number;
|
shortId: number;
|
||||||
lifetime: number;
|
lifetime: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user