Commit d56c33ddb120d180f8ebb5bbfeafa4540c9af81e

Authored by nickAS21
1 parent 4382c0c4

Lwm2m: front: refactoring

... ... @@ -139,7 +139,7 @@ export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor {
139 139 Validators.maxLength(this.lenMaxServerPublicKey)]);
140 140 }
141 141
142   - writeValue(value: any): void {
  142 + writeValue(value: ServerSecurityConfig): void {
143 143 if (value) {
144 144 this.updateValueFields(value);
145 145 }
... ...
... ... @@ -21,12 +21,11 @@ import { Store } from '@ngrx/store';
21 21 import { AppState } from '@app/core/core.state';
22 22 import { coerceBooleanProperty } from '@angular/cdk/coercion';
23 23 import {
24   - ID, INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
  24 + INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
25 25 getDefaultProfileConfig,
26   - Instance,
27 26 ObjectLwM2M,
28 27 ProfileConfigModels,
29   - ResourceLwM2M
  28 + ModelValue
30 29 } from './profile-config.models';
31 30 import { DeviceProfileService } from '@core/http/device-profile.service';
32 31 import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
... ... @@ -113,7 +112,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
113 112 }
114 113 }
115 114
116   - writeValue(value: any | null): void {
  115 + writeValue(value: ProfileConfigModels | null): void {
117 116 this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
118 117 this.lwm2mDeviceConfigFormGroup.patchValue({
119 118 configurationJson: this.configurationValue
... ... @@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
122 121 }
123 122
124 123 private initWriteValue = (): void => {
125   - const modelValue = {objectIds: null, objectsList: []};
  124 + const modelValue = {objectIds: null, objectsList: []} as ModelValue;
126 125 modelValue.objectIds = this.getObjectsFromJsonAllConfig();
127 126 if (modelValue.objectIds !== null) {
128 127 const sortOrder = {
... ... @@ -140,11 +139,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
140 139 }
141 140 }
142 141
143   - private updateWriteValue = (value: any): void => {
144   - const objectsList = value.objectsList;
  142 + private updateWriteValue = (value: ModelValue): void => {
145 143 this.lwm2mDeviceProfileFormGroup.patchValue({
146 144 objectIds: value,
147   - observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList),
  145 + observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value['objectsList']),
148 146 shortId: this.configurationValue.bootstrap.servers.shortId,
149 147 lifetime: this.configurationValue.bootstrap.servers.lifetime,
150 148 defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
... ...
... ... @@ -25,7 +25,6 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
25 25 @Component({
26 26 selector: 'tb-profile-lwm2m-object-add-instances-list',
27 27 templateUrl: './lwm2m-object-add-instances-list.component.html',
28   - styleUrls: [],
29 28 providers: [{
30 29 provide: NG_VALUE_ACCESSOR,
31 30 useExisting: forwardRef(() => Lwm2mObjectAddInstancesListComponent),
... ...
... ... @@ -30,8 +30,7 @@ export interface Lwm2mObjectAddInstancesData {
30 30
31 31 @Component({
32 32 selector: 'tb-lwm2m-object-add-instances',
33   - templateUrl: './lwm2m-object-add-instances.component.html',
34   - styleUrls: []
  33 + templateUrl: './lwm2m-object-add-instances.component.html'
35 34 })
36 35 export class Lwm2mObjectAddInstancesComponent extends DialogComponent<Lwm2mObjectAddInstancesComponent, object> implements OnInit {
37 36
... ...
... ... @@ -21,7 +21,7 @@ import { Store } from '@ngrx/store';
21 21 import { AppState } from '@core/core.state';
22 22 import { Observable } from 'rxjs';
23 23 import { filter, map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators';
24   -import { ObjectLwM2M } from './profile-config.models';
  24 +import { ModelValue, ObjectLwM2M } from './profile-config.models';
25 25 import { TranslateService } from '@ngx-translate/core';
26 26 import { DeviceProfileService } from '@core/http/device-profile.service';
27 27 import { Direction } from '@shared/models/page/sort-order';
... ... @@ -120,7 +120,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
120 120 }
121 121 }
122 122
123   - writeValue(value: any): void {
  123 + writeValue(value: ModelValue): void {
124 124 this.searchText = '';
125 125 if (isDefinedAndNotNull(value)) {
126 126 if (Array.isArray(value.objectIds)) {
... ... @@ -193,7 +193,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
193 193 return this.lw2mModels;
194 194 }
195 195
196   -
197 196 onFocus = (): void => {
198 197 if (!this.dirty) {
199 198 this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true});
... ...
... ... @@ -25,7 +25,6 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
25 25 @Component({
26 26 selector: 'tb-profile-lwm2m-observe-attr-telemetry-resource',
27 27 templateUrl: './lwm2m-observe-attr-telemetry-resource.component.html',
28   - styleUrls: [],
29 28 providers: [
30 29 {
31 30 provide: NG_VALUE_ACCESSOR,
... ...
... ... @@ -28,7 +28,7 @@ import {
28 28 import { Store } from '@ngrx/store';
29 29 import { AppState } from '@core/core.state';
30 30 import { coerceBooleanProperty } from '@angular/cdk/coercion';
31   -import { Instance, ObjectLwM2M, ResourceLwM2M } from './profile-config.models';
  31 +import { CLIENT_LWM2M, Instance, INSTANCES, ObjectLwM2M, ResourceLwM2M, RESOURCES } from './profile-config.models';
32 32 import { deepClone, isDefinedAndNotNull, isEqual, isUndefined } from '@core/utils';
33 33 import { MatDialog } from '@angular/material/dialog';
34 34 import { TranslateService } from '@ngx-translate/core';
... ... @@ -78,7 +78,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
78 78 private dialog: MatDialog,
79 79 public translate: TranslateService) {
80 80 this.observeAttrTelemetryFormGroup = this.fb.group({
81   - clientLwM2M: this.fb.array([])
  81 + [CLIENT_LWM2M]: this.fb.array([])
82 82 });
83 83 this.observeAttrTelemetryFormGroup.valueChanges.subscribe(value => {
84 84 if (isUndefined(this.disabled) || !this.disabled) {
... ... @@ -87,7 +87,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
87 87 });
88 88 }
89 89
90   - private propagateChange = (v: any) => { };
  90 + private propagateChange = (v: any) => {
  91 + };
91 92
92 93 registerOnChange(fn: any): void {
93 94 this.propagateChange = fn;
... ... @@ -123,14 +124,14 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
123 124 }
124 125 }
125 126
126   - writeValue(value: any): void {
  127 + writeValue(value: {}): void {
127 128 if (isDefinedAndNotNull(value)) {
128   - this.buildClientObjectsLwM2M(value.clientLwM2M);
  129 + this.buildClientObjectsLwM2M(value[CLIENT_LWM2M]);
129 130 }
130 131 }
131 132
132 133 private buildClientObjectsLwM2M = (objectsLwM2M: ObjectLwM2M []): void => {
133   - this.observeAttrTelemetryFormGroup.setControl('clientLwM2M',
  134 + this.observeAttrTelemetryFormGroup.setControl(CLIENT_LWM2M,
134 135 this.createObjectsLwM2M(objectsLwM2M)
135 136 );
136 137 }
... ... @@ -157,23 +158,23 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
157 158 }
158 159
159 160 get clientLwM2MFormArray(): FormArray {
160   - return this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray;
  161 + return this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray;
161 162 }
162 163
163 164 instancesLwm2mFormArray = (objectLwM2M: AbstractControl): FormArray => {
164   - return objectLwM2M.get('instances') as FormArray;
  165 + return objectLwM2M.get(INSTANCES) as FormArray;
165 166 }
166 167
167 168 changeInstanceResourcesCheckBox = (value: boolean, instance: AbstractControl, type: string): void => {
168   - const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]);
  169 + const resources = deepClone(instance.get(RESOURCES).value as ResourceLwM2M[]);
169 170 resources.forEach(resource => resource[type] = value);
170   - instance.get('resources').patchValue(resources);
  171 + instance.get(RESOURCES).patchValue(resources);
171 172 this.propagateChange(this.observeAttrTelemetryFormGroup.value);
172 173 }
173 174
174 175 private updateValidators = (): void => {
175   - this.observeAttrTelemetryFormGroup.get('clientLwM2M').setValidators(this.required ? Validators.required : []);
176   - this.observeAttrTelemetryFormGroup.get('clientLwM2M').updateValueAndValidity();
  176 + this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).setValidators(this.required ? Validators.required : []);
  177 + this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).updateValueAndValidity();
177 178 }
178 179
179 180 trackByParams = (index: number, element: any): number => {
... ... @@ -181,7 +182,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
181 182 }
182 183
183 184 getIndeterminate = (instance: AbstractControl, type: string): boolean => {
184   - const resources = instance.get('resources').value as ResourceLwM2M[];
  185 + const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
185 186 if (isDefinedAndNotNull(resources)) {
186 187 const checkedResource = resources.filter(resource => resource[type]);
187 188 return checkedResource.length !== 0 && checkedResource.length !== resources.length;
... ... @@ -190,7 +191,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
190 191 }
191 192
192 193 getChecked = (instance: AbstractControl, type: string): boolean => {
193   - const resources = instance.get('resources').value as ResourceLwM2M[];
  194 + const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
194 195 return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]);
195 196 }
196 197
... ... @@ -239,10 +240,10 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
239 240 }
240 241
241 242 private updateInstancesIds = (data: Lwm2mObjectAddInstancesData): void => {
242   - const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray).controls
  243 + const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray).controls
243 244 .find(e => e.value.id === data.objectId) as FormGroup;
244 245 const instancesArray = objectLwM2MFormGroup.value.instances as Instance [];
245   - const instancesFormArray = objectLwM2MFormGroup.get('instances') as FormArray;
  246 + const instancesFormArray = objectLwM2MFormGroup.get(INSTANCES) as FormArray;
246 247 const instance0 = deepClone(instancesFormArray.at(0).value as Instance);
247 248 instance0.resources.forEach(r => {
248 249 r.attribute = false;
... ...
... ... @@ -16,7 +16,6 @@
16 16
17 17 import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
18 18
19   -export const ID = 'id';
20 19 export const INSTANCES = 'instances';
21 20 export const RESOURCES = 'resources';
22 21 export const OBSERVE_ATTR_TELEMETRY = 'observeAttrTelemetry';
... ... @@ -24,6 +23,7 @@ export const OBSERVE = 'observe';
24 23 export const ATTRIBUTE = 'attribute';
25 24 export const TELEMETRY = 'telemetry';
26 25 export const KEY_NAME = 'keyName';
  26 +export const CLIENT_LWM2M = 'clientLwM2M';
27 27 export const DEFAULT_ID_SERVER = 123;
28 28 export const DEFAULT_ID_BOOTSTRAP = 111;
29 29 export const DEFAULT_HOST_NAME = 'localhost';
... ... @@ -58,6 +58,11 @@ export const SECURITY_CONFIG_MODE_NAMES = new Map<SECURITY_CONFIG_MODE, string>(
58 58 ]
59 59 );
60 60
  61 +export interface ModelValue {
  62 + objectIds: number[] | null,
  63 + objectsList: ObjectLwM2M[]
  64 +}
  65 +
61 66 export interface BootstrapServersSecurityConfig {
62 67 shortId: number;
63 68 lifetime: number;
... ...