Browse Source

Refactoring LwM2M Config with enabled/disabled bootstrap

pull/5729/head
Sergey Tarnavskiy 5 years ago
parent
commit
bb99ef14ed
  1. 30
      ui-ngx/src/app/core/http/device-profile.service.ts
  2. 7
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.html
  3. 24
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts
  4. 12
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts
  5. 7
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
  6. 9
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

30
ui-ngx/src/app/core/http/device-profile.service.ts

@ -84,20 +84,22 @@ export class DeviceProfileService {
return this.getLwm2mBootstrapSecurityInfo(isBootstrapServer, config).pipe( return this.getLwm2mBootstrapSecurityInfo(isBootstrapServer, config).pipe(
map(securityConfig => { map(securityConfig => {
const serverSecurityConfigInfo = deepClone(securityConfig); const serverSecurityConfigInfo = deepClone(securityConfig);
switch (securityMode) { if (serverSecurityConfigInfo) {
case Lwm2mSecurityType.PSK: switch (securityMode) {
serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort; case Lwm2mSecurityType.PSK:
serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost; serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort;
serverSecurityConfigInfo.serverPublicKey = ''; serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost;
break; serverSecurityConfigInfo.serverPublicKey = '';
case Lwm2mSecurityType.RPK: break;
case Lwm2mSecurityType.X509: case Lwm2mSecurityType.RPK:
serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort; case Lwm2mSecurityType.X509:
serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost; serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort;
break; serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost;
case Lwm2mSecurityType.NO_SEC: break;
serverSecurityConfigInfo.serverPublicKey = ''; case Lwm2mSecurityType.NO_SEC:
break; serverSecurityConfigInfo.serverPublicKey = '';
break;
}
} }
return serverSecurityConfigInfo; return serverSecurityConfigInfo;
}) })

7
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.html

@ -20,7 +20,8 @@
<div *ngFor="let serverConfig of serverConfigsFromArray().controls; trackBy: trackByParams; let $index = index;"> <div *ngFor="let serverConfig of serverConfigsFromArray().controls; trackBy: trackByParams; let $index = index;">
<tb-profile-lwm2m-device-config-server <tb-profile-lwm2m-device-config-server
[formControl]="serverConfig" [formControl]="serverConfig"
(removeServer)="removeServerConfig($event, $index)"> (removeServer)="removeServerConfig($event, $index)"
(isTransportWasRunWithBootstrapChange)="updateIsTransportWasRunWithBootstrap($event)">
</tb-profile-lwm2m-device-config-server> </tb-profile-lwm2m-device-config-server>
</div> </div>
</mat-accordion> </mat-accordion>
@ -32,8 +33,8 @@
<button mat-raised-button color="primary" <button mat-raised-button color="primary"
type="button" type="button"
(click)="addServerConfig()"> (click)="addServerConfig()">
<span>{{ ((isBootstrapAdded() || !isBootstrapServerUpdateEnableValue) ? 'device-profile.lwm2m.add-lwm2m-server-config' : <span>{{ (this.isBootstrapServerNotAvailable() ? 'device-profile.lwm2m.add-lwm2m-server-config' :
'device-profile.lwm2m.add-server-config') | translate}}</span> 'device-profile.lwm2m.add-server-config') | translate }}</span>
</button> </button>
</div> </div>
</div> </div>

24
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectorRef, Component, forwardRef, Input, OnInit } from '@angular/core'; import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
import { import {
AbstractControl, AbstractControl,
ControlValueAccessor, ControlValueAccessor,
@ -57,6 +57,12 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
@Input() @Input()
disabled: boolean; disabled: boolean;
@Input()
isTransportWasRunWithBootstrap: boolean;
@Output()
isTransportWasRunWithBootstrapChange = new EventEmitter<boolean>();
public isBootstrapServerUpdateEnableValue: boolean; public isBootstrapServerUpdateEnableValue: boolean;
@Input() @Input()
set isBootstrapServerUpdateEnable(value: boolean) { set isBootstrapServerUpdateEnable(value: boolean) {
@ -147,7 +153,7 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
} }
addServerConfig(): void { addServerConfig(): void {
const addDialogObs = (this.isBootstrapAdded() || !this.isBootstrapServerUpdateEnableValue) ? of(false) : const addDialogObs = this.isBootstrapServerNotAvailable() ? of(false) :
this.matDialog.open<Lwm2mBootstrapAddConfigServerDialogComponent>(Lwm2mBootstrapAddConfigServerDialogComponent, { this.matDialog.open<Lwm2mBootstrapAddConfigServerDialogComponent>(Lwm2mBootstrapAddConfigServerDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'] panelClass: ['tb-dialog', 'tb-fullscreen-dialog']
@ -165,10 +171,18 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
serverConfig.securityMode = Lwm2mSecurityType.NO_SEC; serverConfig.securityMode = Lwm2mSecurityType.NO_SEC;
this.serverConfigsFromArray().push(this.fb.control(serverConfig)); this.serverConfigsFromArray().push(this.fb.control(serverConfig));
this.updateModel(); this.updateModel();
} else {
this.isTransportWasRunWithBootstrap = false;
this.isTransportWasRunWithBootstrapChange.emit(this.isTransportWasRunWithBootstrap);
} }
}); });
} }
updateIsTransportWasRunWithBootstrap(newValue: boolean): void {
this.isTransportWasRunWithBootstrap = newValue;
this.isTransportWasRunWithBootstrapChange.emit(this.isTransportWasRunWithBootstrap);
}
public validate(c: FormControl) { public validate(c: FormControl) {
return (this.bootstrapConfigServersFormGroup.valid) ? null : { return (this.bootstrapConfigServersFormGroup.valid) ? null : {
serverConfigs: { serverConfigs: {
@ -177,7 +191,11 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
}; };
} }
public isBootstrapAdded() { public isBootstrapServerNotAvailable(): boolean {
return this.isBootstrapAdded() || !this.isBootstrapServerUpdateEnableValue || !this.isTransportWasRunWithBootstrap;
}
private isBootstrapAdded(): boolean {
const serverConfigsArray = this.serverConfigsFromArray().getRawValue(); const serverConfigsArray = this.serverConfigsFromArray().getRawValue();
for (let i = 0; i < serverConfigsArray.length; i++) { for (let i = 0; i < serverConfigsArray.length; i++) {
if (serverConfigsArray[i].bootstrapServerIs) { if (serverConfigsArray[i].bootstrapServerIs) {

12
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts

@ -71,10 +71,14 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap;
publicKeyOrIdTooltipNamesMap = Lwm2mPublicKeyOrIdTooltipTranslationsMap; publicKeyOrIdTooltipNamesMap = Lwm2mPublicKeyOrIdTooltipTranslationsMap;
currentSecurityMode = null; currentSecurityMode = null;
bootstrapDisabled = false;
@Output() @Output()
removeServer = new EventEmitter(); removeServer = new EventEmitter();
@Output()
isTransportWasRunWithBootstrapChange = new EventEmitter<boolean>();
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => { };
constructor(public fb: FormBuilder, constructor(public fb: FormBuilder,
@ -136,6 +140,11 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
if (!serverData) { if (!serverData) {
this.serverFormGroup.patchValue(value); this.serverFormGroup.patchValue(value);
} }
if (!value && this.serverFormGroup.get('bootstrapServerIs').value === true) {
this.isTransportWasRunWithBootstrapChange.emit(false);
this.bootstrapDisabled = true;
this.serverFormGroup.get('securityMode').disable({emitEvent: false});
}
}); });
} }
} }
@ -150,6 +159,9 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
this.serverFormGroup.disable({emitEvent: false}); this.serverFormGroup.disable({emitEvent: false});
} else { } else {
this.serverFormGroup.enable({emitEvent: false}); this.serverFormGroup.enable({emitEvent: false});
if (this.bootstrapDisabled) {
this.serverFormGroup.get('securityMode').disable({emitEvent: false});
}
} }
} }

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

@ -33,12 +33,17 @@
</mat-tab> </mat-tab>
<mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}"> <mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}">
<section [formGroup]="lwm2mDeviceProfileFormGroup"> <section [formGroup]="lwm2mDeviceProfileFormGroup">
<div *ngIf="!isTransportWasRunWithBootstrap" style="padding:16px 0 0 8px;" fxLayout="row" fxLayoutAlign="start end">
<mat-icon color="warn" class="material-icons" style="margin-right:8px;">warning</mat-icon>
<span style="font-weight:500">LwM2M transport was run without bootstrap server</span>
</div>
<mat-checkbox formControlName="bootstrapServerUpdateEnable" style="margin-left:8px;margin-top:20px"> <mat-checkbox formControlName="bootstrapServerUpdateEnable" style="margin-left:8px;margin-top:20px">
{{ 'device-profile.lwm2m.include-bootstrap-server' | translate }} {{ 'device-profile.lwm2m.include-bootstrap-server' | translate }}
</mat-checkbox> </mat-checkbox>
<section style="padding: 20px 2px"> <section style="padding: 20px 2px">
<tb-profile-lwm2m-bootstrap-config-servers formControlName="bootstrap" <tb-profile-lwm2m-bootstrap-config-servers formControlName="bootstrap"
[isBootstrapServerUpdateEnable]="isBootstrapServerUpdateEnable"> [isBootstrapServerUpdateEnable]="isBootstrapServerUpdateEnable"
[(isTransportWasRunWithBootstrap)]="isTransportWasRunWithBootstrap">
</tb-profile-lwm2m-bootstrap-config-servers> </tb-profile-lwm2m-bootstrap-config-servers>
</section> </section>
</section> </section>

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

@ -74,6 +74,7 @@ import { TranslateService } from '@ngx-translate/core';
export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, Validator, OnDestroy { export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, Validator, OnDestroy {
public disabled = false; public disabled = false;
public isTransportWasRunWithBootstrap = true;
public isBootstrapServerUpdateEnable: boolean; public isBootstrapServerUpdateEnable: boolean;
private requiredValue: boolean; private requiredValue: boolean;
private destroy$ = new Subject(); private destroy$ = new Subject();
@ -226,10 +227,16 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private async defaultProfileConfig(): Promise<void> { private async defaultProfileConfig(): Promise<void> {
const lwm2m: ServerSecurityConfig = await this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(false).toPromise(); let lwm2m: ServerSecurityConfig;
let bootstrap: ServerSecurityConfig;
[bootstrap, lwm2m] = await Promise.all([
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(true).toPromise(),
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(false).toPromise(),
]);
if (lwm2m) { if (lwm2m) {
lwm2m.securityMode = Lwm2mSecurityType.NO_SEC; lwm2m.securityMode = Lwm2mSecurityType.NO_SEC;
} }
this.isTransportWasRunWithBootstrap = !!bootstrap;
this.configurationValue.bootstrap = [lwm2m]; this.configurationValue.bootstrap = [lwm2m];
this.lwm2mDeviceProfileFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
bootstrap: this.configurationValue.bootstrap bootstrap: this.configurationValue.bootstrap

Loading…
Cancel
Save