Browse Source

UI: Refactoring LWM2M device profile transport configuration Servers tab

pull/4780/head
Vladyslav_Prykhodko 5 years ago
parent
commit
74d2a3ebaf
  1. 42
      ui-ngx/src/app/core/http/device-profile.service.ts
  2. 5
      ui-ngx/src/app/modules/home/components/profile/device/device-profile-transport-configuration.component.ts
  3. 26
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.html
  4. 54
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts
  5. 41
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
  6. 46
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  7. 44
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts
  8. 16
      ui-ngx/src/assets/locale/locale.constant-en_US.json

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

@ -21,18 +21,23 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
import { Observable, of, throwError } from 'rxjs'; import { Observable, of, throwError } from 'rxjs';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models'; import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models';
import { isDefinedAndNotNull, isEmptyStr } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isEmptyStr } from '@core/utils';
import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models'; import {
ObjectLwM2M,
securityConfigMode,
ServerSecurityConfig,
ServerSecurityConfigInfo
} from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
import { SortOrder } from '@shared/models/page/sort-order'; import { SortOrder } from '@shared/models/page/sort-order';
import { OtaPackageService } from '@core/http/ota-package.service'; import { OtaPackageService } from '@core/http/ota-package.service';
import { mergeMap, tap } from 'rxjs/operators'; import { map, mergeMap, tap } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DeviceProfileService { export class DeviceProfileService {
private lwm2mBootstrapSecurityInfoInMemoryCache = new Map<boolean, ServerSecurityConfig>(); private lwm2mBootstrapSecurityInfoInMemoryCache = new Map<boolean, ServerSecurityConfigInfo>();
constructor( constructor(
private http: HttpClient, private http: HttpClient,
@ -60,12 +65,12 @@ export class DeviceProfileService {
return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config)); return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config));
} }
public getLwm2mBootstrapSecurityInfo(isBootstrapServer: boolean, config?: RequestConfig): Observable<ServerSecurityConfig> { public getLwm2mBootstrapSecurityInfo(isBootstrapServer: boolean, config?: RequestConfig): Observable<ServerSecurityConfigInfo> {
const securityConfig = this.lwm2mBootstrapSecurityInfoInMemoryCache.get(isBootstrapServer); const securityConfig = this.lwm2mBootstrapSecurityInfoInMemoryCache.get(isBootstrapServer);
if (securityConfig) { if (securityConfig) {
return of(securityConfig); return of(securityConfig);
} else { } else {
return this.http.get<ServerSecurityConfig>( return this.http.get<ServerSecurityConfigInfo>(
`/api/lwm2m/deviceProfile/bootstrap/${isBootstrapServer}`, `/api/lwm2m/deviceProfile/bootstrap/${isBootstrapServer}`,
defaultHttpOptionsFromConfig(config) defaultHttpOptionsFromConfig(config)
).pipe( ).pipe(
@ -74,6 +79,31 @@ export class DeviceProfileService {
} }
} }
public getLwm2mBootstrapSecurityInfoBySecurityType(isBootstrapServer: boolean, securityMode = securityConfigMode.NO_SEC,
config?: RequestConfig): Observable<ServerSecurityConfig> {
return this.getLwm2mBootstrapSecurityInfo(isBootstrapServer, config).pipe(
map(securityConfig => {
const serverSecurityConfigInfo = deepClone(securityConfig);
switch (securityMode) {
case securityConfigMode.PSK:
serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort;
serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost;
serverSecurityConfigInfo.serverPublicKey = '';
break;
case securityConfigMode.RPK:
case securityConfigMode.X509:
serverSecurityConfigInfo.port = serverSecurityConfigInfo.securityPort;
serverSecurityConfigInfo.host = serverSecurityConfigInfo.securityHost;
break;
case securityConfigMode.NO_SEC:
serverSecurityConfigInfo.serverPublicKey = '';
break;
}
return serverSecurityConfigInfo;
})
);
}
public getLwm2mObjectsPage(pageLink: PageLink, config?: RequestConfig): Observable<Array<ObjectLwM2M>> { public getLwm2mObjectsPage(pageLink: PageLink, config?: RequestConfig): Observable<Array<ObjectLwM2M>> {
return this.http.get<Array<ObjectLwM2M>>( return this.http.get<Array<ObjectLwM2M>>(
`/api/resource/lwm2m/page${pageLink.toQuery()}`, `/api/resource/lwm2m/page${pageLink.toQuery()}`,

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

@ -89,9 +89,10 @@ export class DeviceProfileTransportConfigurationComponent implements ControlValu
if (configuration) { if (configuration) {
delete configuration.type; delete configuration.type;
} }
this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false});
setTimeout(() => { setTimeout(() => {
this.deviceProfileTransportConfigurationFormGroup.patchValue({configuration}, {emitEvent: false}); this.deviceProfileTransportConfigurationFormGroup.updateValueAndValidity();
}); }, 0);
} }
private updateModel() { private updateModel() {

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

@ -35,19 +35,33 @@
</mat-form-field> </mat-form-field>
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.server-port' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.server-port' | translate }}</mat-label>
<input matInput type="number" formControlName="port" required min="0"> <input matInput type="number" formControlName="port" required min="0" max="65535">
<mat-error *ngIf="serverFormGroup.get('port').hasError('required')"> <mat-error *ngIf="serverFormGroup.get('port').hasError('required')">
{{ 'device-profile.lwm2m.server-port-required' | translate }} {{ 'device-profile.lwm2m.server-port-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="serverFormGroup.get('port').hasError('pattern')">
{{ 'device-profile.lwm2m.server-port-pattern' | translate }}
</mat-error>
<mat-error *ngIf="serverFormGroup.get('port').hasError('min') ||
serverFormGroup.get('port').hasError('max')">
{{ 'device-profile.lwm2m.server-port-range' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px" fxLayoutGap.xs="0px"> <div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px" fxLayoutGap.xs="0px">
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label>
<input matInput type="number" formControlName="serverId" required min="0"> <input matInput type="number" min="1" max="65534" formControlName="serverId" required>
<mat-error *ngIf="serverFormGroup.get('serverId').hasError('required')"> <mat-error *ngIf="serverFormGroup.get('serverId').hasError('required')">
{{ 'device-profile.lwm2m.short-id-required' | translate }} {{ 'device-profile.lwm2m.short-id-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="serverFormGroup.get('serverId').hasError('pattern')">
{{ 'device-profile.lwm2m.short-id-pattern' | translate }}
</mat-error>
<mat-error *ngIf="serverFormGroup.get('serverId').hasError('min') ||
serverFormGroup.get('serverId').hasError('max')">
{{ 'device-profile.lwm2m.short-id-range' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.client-hold-off-time' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.client-hold-off-time' | translate }}</mat-label>
@ -57,6 +71,10 @@
<mat-error *ngIf="serverFormGroup.get('clientHoldOffTime').hasError('required')"> <mat-error *ngIf="serverFormGroup.get('clientHoldOffTime').hasError('required')">
{{ 'device-profile.lwm2m.client-hold-off-time-required' | translate }} {{ 'device-profile.lwm2m.client-hold-off-time-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="serverFormGroup.get('clientHoldOffTime').hasError('min') ||
serverFormGroup.get('clientHoldOffTime').hasError('pattern')">
{{ 'device-profile.lwm2m.client-hold-off-time-pattern' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.account-after-timeout' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.account-after-timeout' | translate }}</mat-label>
@ -66,6 +84,10 @@
<mat-error *ngIf="serverFormGroup.get('bootstrapServerAccountTimeout').hasError('required')"> <mat-error *ngIf="serverFormGroup.get('bootstrapServerAccountTimeout').hasError('required')">
{{ 'device-profile.lwm2m.account-after-timeout-required' | translate }} {{ 'device-profile.lwm2m.account-after-timeout-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="serverFormGroup.get('bootstrapServerAccountTimeout').hasError('min') ||
serverFormGroup.get('bootstrapServerAccountTimeout').hasError('pattern')">
{{ 'device-profile.lwm2m.account-after-timeout-pattern' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div *ngIf="serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK || <div *ngIf="serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK ||

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

@ -20,7 +20,9 @@ import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
NG_VALIDATORS, NG_VALIDATORS,
NG_VALUE_ACCESSOR, ValidationErrors, Validator, NG_VALUE_ACCESSOR,
ValidationErrors,
Validator,
Validators Validators
} from '@angular/forms'; } from '@angular/forms';
import { import {
@ -34,10 +36,9 @@ import {
ServerSecurityConfig ServerSecurityConfig
} from './lwm2m-profile-config.models'; } from './lwm2m-profile-config.models';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { of, Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { map, mergeMap, takeUntil, tap } from 'rxjs/operators'; import { mergeMap, takeUntil, tap } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { deepClone } from '@core/utils';
@Component({ @Component({
selector: 'tb-profile-lwm2m-device-config-server', selector: 'tb-profile-lwm2m-device-config-server',
@ -61,7 +62,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
private disabled = false; private disabled = false;
private destroy$ = new Subject(); private destroy$ = new Subject();
private securityDefaultConfig: ServerSecurityConfig; private isDataLoadedIntoCache = false;
serverFormGroup: FormGroup; serverFormGroup: FormGroup;
securityConfigLwM2MType = securityConfigMode; securityConfigLwM2MType = securityConfigMode;
@ -82,12 +83,13 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
ngOnInit(): void { ngOnInit(): void {
this.serverFormGroup = this.fb.group({ this.serverFormGroup = this.fb.group({
host: ['', Validators.required], host: ['', Validators.required],
port: [this.isBootstrapServer ? DEFAULT_PORT_BOOTSTRAP_NO_SEC : DEFAULT_PORT_SERVER_NO_SEC, [Validators.required, Validators.min(0)]], port: [this.isBootstrapServer ? DEFAULT_PORT_BOOTSTRAP_NO_SEC : DEFAULT_PORT_SERVER_NO_SEC,
[Validators.required, Validators.min(1), Validators.max(65535), Validators.pattern('[0-9]*')]],
securityMode: [securityConfigMode.NO_SEC], securityMode: [securityConfigMode.NO_SEC],
serverPublicKey: ['', Validators.required], serverPublicKey: [''],
clientHoldOffTime: ['', [Validators.required, Validators.min(0)]], clientHoldOffTime: ['', [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
serverId: ['', [Validators.required, Validators.min(0)]], serverId: ['', [Validators.required, Validators.min(1), Validators.max(65534), Validators.pattern('[0-9]*')]],
bootstrapServerAccountTimeout: ['', [Validators.required, Validators.min(0)]], bootstrapServerAccountTimeout: ['', [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
}); });
this.serverFormGroup.get('securityMode').valueChanges.pipe( this.serverFormGroup.get('securityMode').valueChanges.pipe(
tap(securityMode => this.updateValidate(securityMode)), tap(securityMode => this.updateValidate(securityMode)),
@ -113,7 +115,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
this.serverFormGroup.patchValue(serverData, {emitEvent: false}); this.serverFormGroup.patchValue(serverData, {emitEvent: false});
this.updateValidate(serverData.securityMode); this.updateValidate(serverData.securityMode);
} }
if (!this.securityDefaultConfig){ if (!this.isDataLoadedIntoCache){
this.getLwm2mBootstrapSecurityInfo().subscribe(value => { this.getLwm2mBootstrapSecurityInfo().subscribe(value => {
if (!serverData) { if (!serverData) {
this.serverFormGroup.patchValue(value); this.serverFormGroup.patchValue(value);
@ -176,37 +178,11 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
} }
private getLwm2mBootstrapSecurityInfo(securityMode = securityConfigMode.NO_SEC): Observable<ServerSecurityConfig> { private getLwm2mBootstrapSecurityInfo(securityMode = securityConfigMode.NO_SEC): Observable<ServerSecurityConfig> {
if (this.securityDefaultConfig) { return this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(this.isBootstrapServer, securityMode).pipe(
return of(this.processingBootstrapSecurityInfo(this.securityDefaultConfig, securityMode)); tap(() => this.isDataLoadedIntoCache = true)
}
return this.deviceProfileService.getLwm2mBootstrapSecurityInfo(this.isBootstrapServer).pipe(
map(securityInfo => {
this.securityDefaultConfig = securityInfo;
return this.processingBootstrapSecurityInfo(securityInfo, securityMode);
})
); );
} }
private processingBootstrapSecurityInfo(securityConfig: ServerSecurityConfig, securityMode: securityConfigMode): ServerSecurityConfig {
const config = deepClone(securityConfig);
switch (securityMode) {
case securityConfigMode.PSK:
config.port = config.securityPort;
config.host = config.securityHost;
config.serverPublicKey = '';
break;
case securityConfigMode.RPK:
case securityConfigMode.X509:
config.port = config.securityPort;
config.host = config.securityHost;
break;
case securityConfigMode.NO_SEC:
config.serverPublicKey = '';
break;
}
return config;
}
validate(): ValidationErrors | null { validate(): ValidationErrors | null {
return this.serverFormGroup.valid ? null : { return this.serverFormGroup.valid ? null : {
serverFormGroup: true serverFormGroup: true

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

@ -41,14 +41,21 @@
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title>{{ 'device-profile.lwm2m.servers' | translate }}</mat-panel-title> <mat-panel-title>{{ 'device-profile.lwm2m.servers' | translate }}</mat-panel-title>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<ng-template formGroupName="servers"> <ng-template matExpansionPanelContent formGroupName="servers">
<div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px" fxLayoutGap.xs="0px"> <div fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px" fxLayoutGap.xs="0px">
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label>
<input matInput type="number" min="0" formControlName="shortId" required> <input matInput type="number" min="1" max="65534" formControlName="shortId" required>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.shortId').hasError('required')"> <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.shortId').hasError('required')">
{{ 'device-profile.lwm2m.short-id-required' | translate }} {{ 'device-profile.lwm2m.short-id-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.shortId').hasError('min') ||
lwm2mDeviceProfileFormGroup.get('bootstrap.servers.shortId').hasError('max')">
{{ 'device-profile.lwm2m.short-id-range' | translate }}
</mat-error>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.shortId').hasError('pattern')">
{{ 'device-profile.lwm2m.short-id-pattern' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.lifetime' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.lifetime' | translate }}</mat-label>
@ -56,6 +63,10 @@
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.lifetime').hasError('required')"> <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.lifetime').hasError('required')">
{{ 'device-profile.lwm2m.lifetime-required' | translate }} {{ 'device-profile.lwm2m.lifetime-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.lifetime').hasError('pattern') ||
lwm2mDeviceProfileFormGroup.get('bootstrap.servers.lifetime').hasError('min')">
{{ 'device-profile.lwm2m.lifetime-pattern' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.default-min-period' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.default-min-period' | translate }}</mat-label>
@ -63,6 +74,10 @@
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.defaultMinPeriod').hasError('required')"> <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.defaultMinPeriod').hasError('required')">
{{ 'device-profile.lwm2m.default-min-period-required' | translate }} {{ 'device-profile.lwm2m.default-min-period-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('bootstrap.servers.defaultMinPeriod').hasError('pattern') ||
lwm2mDeviceProfileFormGroup.get('bootstrap.servers.defaultMinPeriod').hasError('min')">
{{ 'device-profile.lwm2m.default-min-period-pattern' | translate }}
</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
@ -82,19 +97,23 @@
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title>{{ 'device-profile.lwm2m.bootstrap-server' | translate }}</mat-panel-title> <mat-panel-title>{{ 'device-profile.lwm2m.bootstrap-server' | translate }}</mat-panel-title>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<tb-profile-lwm2m-device-config-server <ng-template matExpansionPanelContent>
formControlName="bootstrapServer" <tb-profile-lwm2m-device-config-server
[isBootstrapServer]="true"> formControlName="bootstrapServer"
</tb-profile-lwm2m-device-config-server> [isBootstrapServer]="true">
</tb-profile-lwm2m-device-config-server>
</ng-template>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel> <mat-expansion-panel>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title>{{ 'device-profile.lwm2m.lwm2m-server' | translate }}</mat-panel-title> <mat-panel-title>{{ 'device-profile.lwm2m.lwm2m-server' | translate }}</mat-panel-title>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<tb-profile-lwm2m-device-config-server <ng-template matExpansionPanelContent>
formControlName="lwm2mServer" <tb-profile-lwm2m-device-config-server
[isBootstrapServer]="false"> formControlName="lwm2mServer"
</tb-profile-lwm2m-device-config-server> [isBootstrapServer]="false">
</tb-profile-lwm2m-device-config-server>
</ng-template>
</mat-expansion-panel> </mat-expansion-panel>
</mat-accordion> </mat-accordion>
</section> </section>
@ -148,7 +167,7 @@
<!-- <div fxLayout="column">--> <!-- <div fxLayout="column">-->
<!-- <mat-form-field class="mat-block">--> <!-- <mat-form-field class="mat-block">-->
<!-- <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>--> <!-- <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>-->
<!-- <mat-select formControlName="clientStrategy"--> <!-- <mat-select formControlName="clientOnlyObserveAfterConnect"-->
<!-- matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:--> <!-- matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:-->
<!-- { count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"--> <!-- { count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"-->
<!-- matTooltipPosition="above">--> <!-- matTooltipPosition="above">-->

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

@ -29,7 +29,10 @@ import {
DEFAULT_MIN_PERIOD, DEFAULT_MIN_PERIOD,
DEFAULT_NOTIF_IF_DESIBLED, DEFAULT_NOTIF_IF_DESIBLED,
DEFAULT_SW_UPDATE_RESOURCE, DEFAULT_SW_UPDATE_RESOURCE,
getDefaultProfileConfig, getDefaultBootstrapServerSecurityConfig,
getDefaultBootstrapServersSecurityConfig, getDefaultLwM2MServerSecurityConfig,
getDefaultProfileClientLwM2mSettingsConfig,
getDefaultProfileObserveAttrConfig,
Instance, Instance,
INSTANCES, INSTANCES,
KEY_NAME, KEY_NAME,
@ -38,7 +41,7 @@ import {
ObjectLwM2M, ObjectLwM2M,
OBSERVE, OBSERVE,
OBSERVE_ATTR_TELEMETRY, OBSERVE_ATTR_TELEMETRY,
RESOURCES, RESOURCES, ServerSecurityConfig,
TELEMETRY TELEMETRY
} from './lwm2m-profile-config.models'; } from './lwm2m-profile-config.models';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
@ -94,16 +97,16 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
bootstrap: this.fb.group({ bootstrap: this.fb.group({
servers: this.fb.group({ servers: this.fb.group({
binding: [DEFAULT_BINDING], binding: [DEFAULT_BINDING],
shortId: [DEFAULT_ID_SERVER, [Validators.required, Validators.min(0)]], shortId: [DEFAULT_ID_SERVER, [Validators.required, Validators.min(1), Validators.max(65534), Validators.pattern('[0-9]*')]],
lifetime: [DEFAULT_LIFE_TIME, [Validators.required, Validators.min(0)]], lifetime: [DEFAULT_LIFE_TIME, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
notifIfDisabled: [DEFAULT_NOTIF_IF_DESIBLED, []], notifIfDisabled: [DEFAULT_NOTIF_IF_DESIBLED, []],
defaultMinPeriod: [DEFAULT_MIN_PERIOD, [Validators.required, Validators.min(0)]], defaultMinPeriod: [DEFAULT_MIN_PERIOD, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
}), }),
bootstrapServer: [null, Validators.required], bootstrapServer: [null, Validators.required],
lwm2mServer: [null, Validators.required] lwm2mServer: [null, Validators.required]
}), }),
clientLwM2mSettings: this.fb.group({ clientLwM2mSettings: this.fb.group({
clientStrategy: [1, []], clientOnlyObserveAfterConnect: [1, []],
fwUpdateStrategy: [1, []], fwUpdateStrategy: [1, []],
swUpdateStrategy: [1, []], swUpdateStrategy: [1, []],
fwUpdateRecourse: [{value: '', disabled: true}, []], fwUpdateRecourse: [{value: '', disabled: true}, []],
@ -177,12 +180,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
} }
writeValue(value: Lwm2mProfileConfigModels | null): void { async writeValue(value: Lwm2mProfileConfigModels | null) {
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
if (Object.keys(value).length !== 0 && (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap)) { if (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap) {
this.configurationValue = value; this.configurationValue = value;
} else { } else {
this.configurationValue = getDefaultProfileConfig(); this.configurationValue = await this.defaultProfileConfig();
} }
this.lwm2mDeviceConfigFormGroup.patchValue({ this.lwm2mDeviceConfigFormGroup.patchValue({
configurationJson: this.configurationValue configurationJson: this.configurationValue
@ -191,6 +194,29 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
} }
private async defaultProfileConfig(): Promise<Lwm2mProfileConfigModels> {
let bootstrap: ServerSecurityConfig;
let lwm2m: ServerSecurityConfig;
try {
[bootstrap, lwm2m] = await Promise.all([
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(true).toPromise(),
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(false).toPromise()
]);
} catch (e) {
bootstrap = getDefaultBootstrapServerSecurityConfig();
lwm2m = getDefaultLwM2MServerSecurityConfig();
}
return {
observeAttr: getDefaultProfileObserveAttrConfig(),
bootstrap: {
servers: getDefaultBootstrapServersSecurityConfig(),
bootstrapServer: bootstrap,
lwm2mServer: lwm2m
},
clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig()
};
}
private initWriteValue = (): void => { private initWriteValue = (): void => {
const modelValue = {objectIds: [], objectsList: []} as ModelValue; const modelValue = {objectIds: [], objectsList: []} as ModelValue;
modelValue.objectIds = this.getObjectsFromJsonAllConfig(); modelValue.objectIds = this.getObjectsFromJsonAllConfig();
@ -220,7 +246,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList), observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList),
bootstrap: this.configurationValue.bootstrap, bootstrap: this.configurationValue.bootstrap,
clientLwM2mSettings: { clientLwM2mSettings: {
clientStrategy: this.configurationValue.clientLwM2mSettings.clientStrategy, clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1, fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1,
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1, swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1,
fwUpdateRecourse: fwResource, fwUpdateRecourse: fwResource,

44
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts

@ -39,7 +39,7 @@ export const DEFAULT_BOOTSTRAP_SERVER_ACCOUNT_TIME_OUT = 0;
export const LEN_MAX_PUBLIC_KEY_RPK = 182; export const LEN_MAX_PUBLIC_KEY_RPK = 182;
export const LEN_MAX_PUBLIC_KEY_X509 = 3000; export const LEN_MAX_PUBLIC_KEY_X509 = 3000;
export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/; export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
export const KEY_REGEXP_NUMBER = /^(\-?|\+?)\d*$/; export const KEY_REGEXP_NUMBER = /^(-?|\+?)\d*$/;
export const INSTANCES_ID_VALUE_MIN = 0; export const INSTANCES_ID_VALUE_MIN = 0;
export const INSTANCES_ID_VALUE_MAX = 65535; export const INSTANCES_ID_VALUE_MAX = 65535;
export const DEFAULT_OTA_UPDATE_PROTOCOL = 'coap://'; export const DEFAULT_OTA_UPDATE_PROTOCOL = 'coap://';
@ -143,18 +143,20 @@ export interface BootstrapServersSecurityConfig {
export interface ServerSecurityConfig { export interface ServerSecurityConfig {
host?: string; host?: string;
securityHost?: string;
port?: number; port?: number;
securityPort?: number;
securityMode: securityConfigMode; securityMode: securityConfigMode;
clientPublicKeyOrId?: string;
clientSecretKey?: string;
serverPublicKey?: string; serverPublicKey?: string;
clientHoldOffTime?: number; clientHoldOffTime?: number;
serverId?: number; serverId?: number;
bootstrapServerAccountTimeout: number; bootstrapServerAccountTimeout: number;
} }
export interface ServerSecurityConfigInfo extends ServerSecurityConfig {
securityHost?: string;
securityPort?: number;
bootstrapServerIs: boolean;
}
interface BootstrapSecurityConfig { interface BootstrapSecurityConfig {
servers: BootstrapServersSecurityConfig; servers: BootstrapServersSecurityConfig;
bootstrapServer: ServerSecurityConfig; bootstrapServer: ServerSecurityConfig;
@ -168,7 +170,7 @@ export interface Lwm2mProfileConfigModels {
} }
export interface ClientLwM2mSettings { export interface ClientLwM2mSettings {
clientStrategy: string; clientOnlyObserveAfterConnect: number;
fwUpdateStrategy: number; fwUpdateStrategy: number;
swUpdateStrategy: number; swUpdateStrategy: number;
fwUpdateRecourse: string; fwUpdateRecourse: string;
@ -193,9 +195,9 @@ export function getDefaultBootstrapServersSecurityConfig(): BootstrapServersSecu
}; };
} }
export function getDefaultBootstrapServerSecurityConfig(hostname: string): ServerSecurityConfig { export function getDefaultBootstrapServerSecurityConfig(): ServerSecurityConfig {
return { return {
host: hostname, host: DEFAULT_LOCAL_HOST_NAME,
port: DEFAULT_PORT_BOOTSTRAP_NO_SEC, port: DEFAULT_PORT_BOOTSTRAP_NO_SEC,
securityMode: securityConfigMode.NO_SEC, securityMode: securityConfigMode.NO_SEC,
serverPublicKey: '', serverPublicKey: '',
@ -205,22 +207,14 @@ export function getDefaultBootstrapServerSecurityConfig(hostname: string): Serve
}; };
} }
export function getDefaultLwM2MServerSecurityConfig(hostname): ServerSecurityConfig { export function getDefaultLwM2MServerSecurityConfig(): ServerSecurityConfig {
const DefaultLwM2MServerSecurityConfig = getDefaultBootstrapServerSecurityConfig(hostname); const DefaultLwM2MServerSecurityConfig = getDefaultBootstrapServerSecurityConfig();
DefaultLwM2MServerSecurityConfig.port = DEFAULT_PORT_SERVER_NO_SEC; DefaultLwM2MServerSecurityConfig.port = DEFAULT_PORT_SERVER_NO_SEC;
DefaultLwM2MServerSecurityConfig.serverId = DEFAULT_ID_SERVER; DefaultLwM2MServerSecurityConfig.serverId = DEFAULT_ID_SERVER;
return DefaultLwM2MServerSecurityConfig; return DefaultLwM2MServerSecurityConfig;
} }
function getDefaultProfileBootstrapSecurityConfig(hostname: any): BootstrapSecurityConfig { export function getDefaultProfileObserveAttrConfig(): ObservableAttributes {
return {
servers: getDefaultBootstrapServersSecurityConfig(),
bootstrapServer: getDefaultBootstrapServerSecurityConfig(hostname),
lwm2mServer: getDefaultLwM2MServerSecurityConfig(hostname)
};
}
function getDefaultProfileObserveAttrConfig(): ObservableAttributes {
return { return {
observe: [], observe: [],
attribute: [], attribute: [],
@ -230,17 +224,9 @@ function getDefaultProfileObserveAttrConfig(): ObservableAttributes {
}; };
} }
export function getDefaultProfileConfig(hostname?: any): Lwm2mProfileConfigModels { export function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
return {
clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig(),
observeAttr: getDefaultProfileObserveAttrConfig(),
bootstrap: getDefaultProfileBootstrapSecurityConfig((hostname) ? hostname : DEFAULT_LOCAL_HOST_NAME)
};
}
function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
return { return {
clientStrategy: '1', clientOnlyObserveAfterConnect: 1,
fwUpdateStrategy: 1, fwUpdateStrategy: 1,
swUpdateStrategy: 1, swUpdateStrategy: 1,
fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE, fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE,

16
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1257,10 +1257,14 @@
"servers": "Servers", "servers": "Servers",
"short-id": "Short ID", "short-id": "Short ID",
"short-id-required": "Short ID is required.", "short-id-required": "Short ID is required.",
"lifetime": "LwM2M Client registration Lifetime", "short-id-range": "Short ID should be in a range from 1 to 65534.",
"lifetime-required": "LwM2M Client registration Lifetime is required.", "short-id-pattern": "Short ID must be a positive integer.",
"default-min-period": "Minimum Period between two notifications (sec)", "lifetime": "Client registration lifetime",
"default-min-period-required": "Minimum Period is required.", "lifetime-required": "Client registration lifetime is required.",
"lifetime-pattern": "Client registration lifetime must be a positive integer.",
"default-min-period": "Minimum period between two notifications (s)",
"default-min-period-required": "Minimum period is required.",
"default-min-period-pattern": "Minimum period must be a positive integer.",
"notification-storing": "Notification storing when disabled or offline", "notification-storing": "Notification storing when disabled or offline",
"binding": "Binding", "binding": "Binding",
"binding-type": { "binding-type": {
@ -1282,15 +1286,19 @@
"server-host-required": "Host is required.", "server-host-required": "Host is required.",
"server-port": "Port", "server-port": "Port",
"server-port-required": "Port is required.", "server-port-required": "Port is required.",
"server-port-pattern": "Port must be a positive integer.",
"server-port-range": "Port should be in a range from 1 to 65535.",
"server-public-key": "Server Public Key", "server-public-key": "Server Public Key",
"server-public-key-required": "Server Public Key is required.", "server-public-key-required": "Server Public Key is required.",
"server-public-key-pattern": "Server Public Key must be hex decimal format.", "server-public-key-pattern": "Server Public Key must be hex decimal format.",
"server-public-key-length": "Server Public Key must be {{ count }} characters.", "server-public-key-length": "Server Public Key must be {{ count }} characters.",
"client-hold-off-time": "Hold Off Time", "client-hold-off-time": "Hold Off Time",
"client-hold-off-time-required": "Hold Off Time is required.", "client-hold-off-time-required": "Hold Off Time is required.",
"client-hold-off-time-pattern": "Hold Off Time must be a positive integer.",
"client-hold-off-time-tooltip": "Client Hold Off Time for use with a Bootstrap-Server only", "client-hold-off-time-tooltip": "Client Hold Off Time for use with a Bootstrap-Server only",
"account-after-timeout": "Account after the timeout", "account-after-timeout": "Account after the timeout",
"account-after-timeout-required": "Account after the timeout is required.", "account-after-timeout-required": "Account after the timeout is required.",
"account-after-timeout-pattern": "Account after the timeout must be a positive integer.",
"account-after-timeout-tooltip": "Bootstrap-Server Account after the timeout value given by this resource.", "account-after-timeout-tooltip": "Bootstrap-Server Account after the timeout value given by this resource.",
"others-tab": "Other settings", "others-tab": "Other settings",
"client-strategy": "Client strategy when connecting", "client-strategy": "Client strategy when connecting",

Loading…
Cancel
Save