Commit 15abe85b748eb6e08945faff865f92fd517a56ce

Authored by Vladyslav_Prykhodko
1 parent 573837c4

UI: Refactoring LwM2M

... ... @@ -73,8 +73,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
73 73 this.requiredValue = coerceBooleanProperty(value);
74 74 }
75 75
76   - private propagateChange = (v: any) => {
77   - };
  76 + private propagateChange = (v: any) => { };
78 77
79 78 constructor(private store: Store<AppState>,
80 79 private fb: FormBuilder,
... ... @@ -141,7 +140,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
141 140 }
142 141
143 142 private updateWriteValue = (value: any): void => {
144   - const objectsList = deepClone(value.objectsList);
  143 + const objectsList = value.objectsList;
145 144 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
146 145 objectIds: value,
147 146 observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)},
... ... @@ -251,12 +250,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
251 250 }
252 251
253 252 private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): ObjectLwM2M [] => {
254   - const clientObserveAttr = deepClone(listObject);
  253 + const clientObserveAttr = listObject;
255 254 if (this.configurationValue[this.observeAttr]) {
256   - const observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>;
257   - const attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>;
258   - const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>;
259   - const keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject;
  255 + const observeArray = this.configurationValue[this.observeAttr][this.observe];
  256 + const attributeArray = this.configurationValue[this.observeAttr][this.attribute];
  257 + const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry];
  258 + const keyNameJson = this.configurationValue[this.observeAttr][this.keyName];
260 259 if (this.includesInstancesNo(attributeArray, telemetryArray)) {
261 260 this.addInstances(attributeArray, telemetryArray, clientObserveAttr);
262 261 }
... ...
... ... @@ -15,19 +15,17 @@
15 15 ///
16 16
17 17 import { Component, forwardRef, Inject, Input, OnInit } from '@angular/core';
18   -
19   -import {
20   - ControlValueAccessor,
21   - FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators
22   -} from '@angular/forms';
  18 +import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
23 19 import {
24   - SECURITY_CONFIG_MODE,
25   - SECURITY_CONFIG_MODE_NAMES,
26   - KEY_REGEXP_HEX_DEC,
27   - ServerSecurityConfig,
28 20 DeviceCredentialsDialogLwm2mData,
  21 + KEY_REGEXP_HEX_DEC,
  22 + LEN_MAX_PRIVATE_KEY,
29 23 LEN_MAX_PSK,
30   - LEN_MAX_PRIVATE_KEY, LEN_MAX_PUBLIC_KEY_RPK, LEN_MAX_PUBLIC_KEY_X509
  24 + LEN_MAX_PUBLIC_KEY_RPK,
  25 + LEN_MAX_PUBLIC_KEY_X509,
  26 + SECURITY_CONFIG_MODE,
  27 + SECURITY_CONFIG_MODE_NAMES,
  28 + ServerSecurityConfig
31 29 } from '@home/pages/device/lwm2m/security-config.models';
32 30 import { Store } from '@ngrx/store';
33 31 import { AppState } from '@core/core.state';
... ...
... ... @@ -15,7 +15,7 @@
15 15 ///
16 16
17 17
18   -import {Component, Inject, OnInit } from '@angular/core';
  18 +import { Component, Inject, OnInit } from '@angular/core';
19 19 import { DialogComponent } from '@shared/components/dialog.component';
20 20 import { Store } from '@ngrx/store';
21 21 import { AppState } from '@core/core.state';
... ... @@ -24,22 +24,22 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
24 24 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
25 25 import { TranslateService } from '@ngx-translate/core';
26 26 import {
27   - SECURITY_CONFIG_MODE_NAMES,
28   - SECURITY_CONFIG_MODE,
29   - SecurityConfigModels,
30   - ClientSecurityConfigPSK,
31   - ClientSecurityConfigRPK,
32   - JSON_ALL_CONFIG,
33   - KEY_REGEXP_HEX_DEC,
34   - DeviceCredentialsDialogLwm2mData,
35 27 BOOTSTRAP_SERVER,
36 28 BOOTSTRAP_SERVERS,
37   - LWM2M_SERVER,
38   - ClientSecurityConfigX509,
39 29 ClientSecurityConfigNoSEC,
  30 + ClientSecurityConfigPSK,
  31 + ClientSecurityConfigRPK,
  32 + ClientSecurityConfigX509,
  33 + DeviceCredentialsDialogLwm2mData,
40 34 getDefaultClientSecurityConfigType,
  35 + JSON_ALL_CONFIG,
  36 + KEY_REGEXP_HEX_DEC,
41 37 LEN_MAX_PSK,
42   - LEN_MAX_PUBLIC_KEY_RPK
  38 + LEN_MAX_PUBLIC_KEY_RPK,
  39 + LWM2M_SERVER,
  40 + SECURITY_CONFIG_MODE,
  41 + SECURITY_CONFIG_MODE_NAMES,
  42 + SecurityConfigModels
43 43 } from './security-config.models';
44 44 import { WINDOW } from '@core/services/window.service';
45 45 import { MatTabChangeEvent } from '@angular/material/tabs';
... ... @@ -65,9 +65,9 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
65 65 bootstrapServer: string;
66 66 lwm2mServer: string;
67 67 jsonObserveData: {};
68   - lenMaxKeyClient = LEN_MAX_PSK as number;
  68 + lenMaxKeyClient = LEN_MAX_PSK;
69 69 tabPrevious: MatTab;
70   - tabIndexPrevious = 0 as number;
  70 + tabIndexPrevious = 0;
71 71
72 72 constructor(protected store: Store<AppState>,
73 73 protected router: Router,
... ... @@ -111,23 +111,23 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
111 111 }
112 112
113 113 private initClientSecurityConfig = (jsonAllConfig: SecurityConfigModels): void => {
114   - switch (jsonAllConfig.client.securityConfigClientMode.toString()) {
115   - case SECURITY_CONFIG_MODE.NO_SEC.toString():
  114 + switch (jsonAllConfig.client.securityConfigClientMode) {
  115 + case SECURITY_CONFIG_MODE.NO_SEC:
116 116 break;
117   - case SECURITY_CONFIG_MODE.PSK.toString():
  117 + case SECURITY_CONFIG_MODE.PSK:
118 118 const clientSecurityConfigPSK = jsonAllConfig.client as ClientSecurityConfigPSK;
119 119 this.lwm2mConfigFormGroup.patchValue({
120 120 identityPSK: clientSecurityConfigPSK.identity,
121 121 clientKey: clientSecurityConfigPSK.key,
122 122 }, {emitEvent: false});
123 123 break;
124   - case SECURITY_CONFIG_MODE.RPK.toString():
  124 + case SECURITY_CONFIG_MODE.RPK:
125 125 const clientSecurityConfigRPK = jsonAllConfig.client as ClientSecurityConfigRPK;
126 126 this.lwm2mConfigFormGroup.patchValue({
127 127 clientKey: clientSecurityConfigRPK.key,
128 128 }, {emitEvent: false});
129 129 break;
130   - case SECURITY_CONFIG_MODE.X509.toString():
  130 + case SECURITY_CONFIG_MODE.X509:
131 131 const clientSecurityConfigX509 = jsonAllConfig.client as ClientSecurityConfigX509;
132 132 this.lwm2mConfigFormGroup.patchValue({
133 133 clientCertificate: clientSecurityConfigX509.x509
... ... @@ -295,7 +295,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
295 295
296 296 private updateIdentityPSK = (): void => {
297 297 const securityMode = 'securityMode';
298   - if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) {
  298 + if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
299 299 this.lwm2mConfigFormGroup.get('bootstrapFormGroup').patchValue({
300 300 clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value
301 301 });
... ... @@ -303,7 +303,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
303 303 this.jsonAllConfig.client[identity] = this.lwm2mConfigFormGroup.get('identityPSK').value;
304 304 this.upDateJsonAllConfig();
305 305 }
306   - if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) {
  306 + if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
307 307 this.lwm2mConfigFormGroup.get('lwm2mServerFormGroup').patchValue({
308 308 clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value
309 309 });
... ... @@ -316,13 +316,13 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
316 316 const key = 'key';
317 317 const securityMode = 'securityMode';
318 318 this.jsonAllConfig.client[key] = this.lwm2mConfigFormGroup.get('clientKey').value;
319   - if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) {
  319 + if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
320 320 this.lwm2mConfigFormGroup.get('bootstrapServer').patchValue({
321 321 clientSecretKey: this.jsonAllConfig.client[key]
322 322 }, {emitEvent: false});
323 323 this.jsonAllConfig.bootstrap.bootstrapServer.clientSecretKey = this.jsonAllConfig.client[key];
324 324 }
325   - if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) {
  325 + if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
326 326 this.lwm2mConfigFormGroup.get('lwm2mServer').patchValue({
327 327 clientSecretKey: this.jsonAllConfig.client[key]
328 328 }, {emitEvent: false});
... ...