Commit 15abe85b748eb6e08945faff865f92fd517a56ce

Authored by Vladyslav_Prykhodko
1 parent 573837c4

UI: Refactoring LwM2M

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