Browse Source

UI: Refactoring LwM2M

pull/3980/head
Vladyslav_Prykhodko 6 years ago
parent
commit
15abe85b74
  1. 15
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  2. 18
      ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config-server.component.ts
  3. 46
      ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.component.ts

15
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

@ -73,8 +73,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
this.requiredValue = coerceBooleanProperty(value); this.requiredValue = coerceBooleanProperty(value);
} }
private propagateChange = (v: any) => { private propagateChange = (v: any) => { };
};
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private fb: FormBuilder, private fb: FormBuilder,
@ -141,7 +140,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private updateWriteValue = (value: any): void => { private updateWriteValue = (value: any): void => {
const objectsList = deepClone(value.objectsList); const objectsList = value.objectsList;
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
objectIds: value, objectIds: value,
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}, observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)},
@ -251,12 +250,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): ObjectLwM2M [] => { private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): ObjectLwM2M [] => {
const clientObserveAttr = deepClone(listObject); const clientObserveAttr = listObject;
if (this.configurationValue[this.observeAttr]) { if (this.configurationValue[this.observeAttr]) {
const observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>; const observeArray = this.configurationValue[this.observeAttr][this.observe];
const attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>; const attributeArray = this.configurationValue[this.observeAttr][this.attribute];
const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>; const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry];
const keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject; const keyNameJson = this.configurationValue[this.observeAttr][this.keyName];
if (this.includesInstancesNo(attributeArray, telemetryArray)) { if (this.includesInstancesNo(attributeArray, telemetryArray)) {
this.addInstances(attributeArray, telemetryArray, clientObserveAttr); this.addInstances(attributeArray, telemetryArray, clientObserveAttr);
} }

18
ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config-server.component.ts

@ -15,19 +15,17 @@
/// ///
import { Component, forwardRef, Inject, Input, OnInit } from '@angular/core'; import { Component, forwardRef, Inject, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import {
ControlValueAccessor,
FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators
} from '@angular/forms';
import { import {
SECURITY_CONFIG_MODE,
SECURITY_CONFIG_MODE_NAMES,
KEY_REGEXP_HEX_DEC,
ServerSecurityConfig,
DeviceCredentialsDialogLwm2mData, DeviceCredentialsDialogLwm2mData,
KEY_REGEXP_HEX_DEC,
LEN_MAX_PRIVATE_KEY,
LEN_MAX_PSK, LEN_MAX_PSK,
LEN_MAX_PRIVATE_KEY, LEN_MAX_PUBLIC_KEY_RPK, LEN_MAX_PUBLIC_KEY_X509 LEN_MAX_PUBLIC_KEY_RPK,
LEN_MAX_PUBLIC_KEY_X509,
SECURITY_CONFIG_MODE,
SECURITY_CONFIG_MODE_NAMES,
ServerSecurityConfig
} from '@home/pages/device/lwm2m/security-config.models'; } from '@home/pages/device/lwm2m/security-config.models';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';

46
ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.component.ts

@ -15,7 +15,7 @@
/// ///
import {Component, Inject, OnInit } from '@angular/core'; import { Component, Inject, OnInit } from '@angular/core';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
@ -24,22 +24,22 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { import {
SECURITY_CONFIG_MODE_NAMES,
SECURITY_CONFIG_MODE,
SecurityConfigModels,
ClientSecurityConfigPSK,
ClientSecurityConfigRPK,
JSON_ALL_CONFIG,
KEY_REGEXP_HEX_DEC,
DeviceCredentialsDialogLwm2mData,
BOOTSTRAP_SERVER, BOOTSTRAP_SERVER,
BOOTSTRAP_SERVERS, BOOTSTRAP_SERVERS,
LWM2M_SERVER,
ClientSecurityConfigX509,
ClientSecurityConfigNoSEC, ClientSecurityConfigNoSEC,
ClientSecurityConfigPSK,
ClientSecurityConfigRPK,
ClientSecurityConfigX509,
DeviceCredentialsDialogLwm2mData,
getDefaultClientSecurityConfigType, getDefaultClientSecurityConfigType,
JSON_ALL_CONFIG,
KEY_REGEXP_HEX_DEC,
LEN_MAX_PSK, LEN_MAX_PSK,
LEN_MAX_PUBLIC_KEY_RPK LEN_MAX_PUBLIC_KEY_RPK,
LWM2M_SERVER,
SECURITY_CONFIG_MODE,
SECURITY_CONFIG_MODE_NAMES,
SecurityConfigModels
} from './security-config.models'; } from './security-config.models';
import { WINDOW } from '@core/services/window.service'; import { WINDOW } from '@core/services/window.service';
import { MatTabChangeEvent } from '@angular/material/tabs'; import { MatTabChangeEvent } from '@angular/material/tabs';
@ -65,9 +65,9 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
bootstrapServer: string; bootstrapServer: string;
lwm2mServer: string; lwm2mServer: string;
jsonObserveData: {}; jsonObserveData: {};
lenMaxKeyClient = LEN_MAX_PSK as number; lenMaxKeyClient = LEN_MAX_PSK;
tabPrevious: MatTab; tabPrevious: MatTab;
tabIndexPrevious = 0 as number; tabIndexPrevious = 0;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected router: Router, protected router: Router,
@ -111,23 +111,23 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
} }
private initClientSecurityConfig = (jsonAllConfig: SecurityConfigModels): void => { private initClientSecurityConfig = (jsonAllConfig: SecurityConfigModels): void => {
switch (jsonAllConfig.client.securityConfigClientMode.toString()) { switch (jsonAllConfig.client.securityConfigClientMode) {
case SECURITY_CONFIG_MODE.NO_SEC.toString(): case SECURITY_CONFIG_MODE.NO_SEC:
break; break;
case SECURITY_CONFIG_MODE.PSK.toString(): case SECURITY_CONFIG_MODE.PSK:
const clientSecurityConfigPSK = jsonAllConfig.client as ClientSecurityConfigPSK; const clientSecurityConfigPSK = jsonAllConfig.client as ClientSecurityConfigPSK;
this.lwm2mConfigFormGroup.patchValue({ this.lwm2mConfigFormGroup.patchValue({
identityPSK: clientSecurityConfigPSK.identity, identityPSK: clientSecurityConfigPSK.identity,
clientKey: clientSecurityConfigPSK.key, clientKey: clientSecurityConfigPSK.key,
}, {emitEvent: false}); }, {emitEvent: false});
break; break;
case SECURITY_CONFIG_MODE.RPK.toString(): case SECURITY_CONFIG_MODE.RPK:
const clientSecurityConfigRPK = jsonAllConfig.client as ClientSecurityConfigRPK; const clientSecurityConfigRPK = jsonAllConfig.client as ClientSecurityConfigRPK;
this.lwm2mConfigFormGroup.patchValue({ this.lwm2mConfigFormGroup.patchValue({
clientKey: clientSecurityConfigRPK.key, clientKey: clientSecurityConfigRPK.key,
}, {emitEvent: false}); }, {emitEvent: false});
break; break;
case SECURITY_CONFIG_MODE.X509.toString(): case SECURITY_CONFIG_MODE.X509:
const clientSecurityConfigX509 = jsonAllConfig.client as ClientSecurityConfigX509; const clientSecurityConfigX509 = jsonAllConfig.client as ClientSecurityConfigX509;
this.lwm2mConfigFormGroup.patchValue({ this.lwm2mConfigFormGroup.patchValue({
clientCertificate: clientSecurityConfigX509.x509 clientCertificate: clientSecurityConfigX509.x509
@ -295,7 +295,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
private updateIdentityPSK = (): void => { private updateIdentityPSK = (): void => {
const securityMode = 'securityMode'; const securityMode = 'securityMode';
if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) { if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
this.lwm2mConfigFormGroup.get('bootstrapFormGroup').patchValue({ this.lwm2mConfigFormGroup.get('bootstrapFormGroup').patchValue({
clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value
}); });
@ -303,7 +303,7 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
this.jsonAllConfig.client[identity] = this.lwm2mConfigFormGroup.get('identityPSK').value; this.jsonAllConfig.client[identity] = this.lwm2mConfigFormGroup.get('identityPSK').value;
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) { if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
this.lwm2mConfigFormGroup.get('lwm2mServerFormGroup').patchValue({ this.lwm2mConfigFormGroup.get('lwm2mServerFormGroup').patchValue({
clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value clientPublicKeyOrId: this.lwm2mConfigFormGroup.get('identityPSK').value
}); });
@ -316,13 +316,13 @@ export class SecurityConfigComponent extends DialogComponent<SecurityConfigCompo
const key = 'key'; const key = 'key';
const securityMode = 'securityMode'; const securityMode = 'securityMode';
this.jsonAllConfig.client[key] = this.lwm2mConfigFormGroup.get('clientKey').value; this.jsonAllConfig.client[key] = this.lwm2mConfigFormGroup.get('clientKey').value;
if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) { if (this.lwm2mConfigFormGroup.get('bootstrapServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
this.lwm2mConfigFormGroup.get('bootstrapServer').patchValue({ this.lwm2mConfigFormGroup.get('bootstrapServer').patchValue({
clientSecretKey: this.jsonAllConfig.client[key] clientSecretKey: this.jsonAllConfig.client[key]
}, {emitEvent: false}); }, {emitEvent: false});
this.jsonAllConfig.bootstrap.bootstrapServer.clientSecretKey = this.jsonAllConfig.client[key]; this.jsonAllConfig.bootstrap.bootstrapServer.clientSecretKey = this.jsonAllConfig.client[key];
} }
if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK.toString()) { if (this.lwm2mConfigFormGroup.get('lwm2mServer').value[securityMode] === SECURITY_CONFIG_MODE.PSK) {
this.lwm2mConfigFormGroup.get('lwm2mServer').patchValue({ this.lwm2mConfigFormGroup.get('lwm2mServer').patchValue({
clientSecretKey: this.jsonAllConfig.client[key] clientSecretKey: this.jsonAllConfig.client[key]
}, {emitEvent: false}); }, {emitEvent: false});

Loading…
Cancel
Save