Commit cd6a76de862efc81fc4c9f6138d76244b896d994

Authored by Vladyslav
Committed by GitHub
1 parent 9cdd9162

Improvement/lwm2m/refactoring 1 (#3956)

UI: Refactoring lwm2m
@@ -22,9 +22,7 @@ import { Observable } from 'rxjs'; @@ -22,9 +22,7 @@ import { Observable } from 'rxjs';
22 import { PageData } from '@shared/models/page/page-data'; 22 import { PageData } from '@shared/models/page/page-data';
23 import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models'; 23 import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models';
24 import { isDefinedAndNotNull } from '@core/utils'; 24 import { isDefinedAndNotNull } from '@core/utils';
25 -import {  
26 - ObjectLwM2M, ServerSecurityConfig  
27 -} from "../../modules/home/components/profile/device/lwm2m/profile-config.models"; 25 +import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/profile-config.models';
28 26
29 @Injectable({ 27 @Injectable({
30 providedIn: 'root' 28 providedIn: 'root'
@@ -43,16 +41,23 @@ export class DeviceProfileService { @@ -43,16 +41,23 @@ export class DeviceProfileService {
43 return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config)); 41 return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config));
44 } 42 }
45 43
46 - public getLwm2mObjects(objectIds: number [], config?: RequestConfig): Observable<ObjectLwM2M[]> {  
47 - return this.http.get<ObjectLwM2M[]>(`/api/lwm2m/deviceProfile/${objectIds}`, defaultHttpOptionsFromConfig(config)); 44 + public getLwm2mObjects(objectIds: number[], config?: RequestConfig): Observable<Array<ObjectLwM2M>> {
  45 + return this.http.get<Array<ObjectLwM2M>>(`/api/lwm2m/deviceProfile/${objectIds}`, defaultHttpOptionsFromConfig(config));
48 } 46 }
49 47
50 - public getLwm2mBootstrapSecurityInfo(securityMode: string, bootstrapServerIs: boolean, config?: RequestConfig): Observable<ServerSecurityConfig> {  
51 - return this.http.get<ServerSecurityConfig>(`/api/lwm2m/deviceProfile/bootstrap/${securityMode}/${bootstrapServerIs}`, defaultHttpOptionsFromConfig(config)); 48 + public getLwm2mBootstrapSecurityInfo(securityMode: string, bootstrapServerIs: boolean,
  49 + config?: RequestConfig): Observable<ServerSecurityConfig> {
  50 + return this.http.get<ServerSecurityConfig>(
  51 + `/api/lwm2m/deviceProfile/bootstrap/${securityMode}/${bootstrapServerIs}`,
  52 + defaultHttpOptionsFromConfig(config)
  53 + );
52 } 54 }
53 55
54 public getLwm2mObjectsPage(pageLink: PageLink, config?: RequestConfig): Observable<PageData<ObjectLwM2M>> { 56 public getLwm2mObjectsPage(pageLink: PageLink, config?: RequestConfig): Observable<PageData<ObjectLwM2M>> {
55 - return this.http.get<PageData<ObjectLwM2M>>(`/api/lwm2m/deviceProfile/objects${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); 57 + return this.http.get<PageData<ObjectLwM2M>>(
  58 + `/api/lwm2m/deviceProfile/objects${pageLink.toQuery()}`,
  59 + defaultHttpOptionsFromConfig(config)
  60 + );
56 } 61 }
57 62
58 public saveDeviceProfile(deviceProfile: DeviceProfile, config?: RequestConfig): Observable<DeviceProfile> { 63 public saveDeviceProfile(deviceProfile: DeviceProfile, config?: RequestConfig): Observable<DeviceProfile> {
@@ -90,9 +90,8 @@ @@ -90,9 +90,8 @@
90 </mat-error> 90 </mat-error>
91 <div mat-dialog-actions fxLayoutAlign="center center"> 91 <div mat-dialog-actions fxLayoutAlign="center center">
92 <button mat-raised-button color="primary" 92 <button mat-raised-button color="primary"
93 - [disabled]="false"  
94 matTooltip="{{'device.lwm2m-value-edit-tip' | translate }}" 93 matTooltip="{{'device.lwm2m-value-edit-tip' | translate }}"
95 - (click)="openSecurityInfoLwM2mDialog($event, deviceCredentialsFormGroup.get('credentialsValue').value, deviceCredentialsFormGroup.get('credentialsId').value )" 94 + (click)="openSecurityInfoLwM2mDialog($event)"
96 > 95 >
97 {{'device.lwm2m-value-edit' | translate }} 96 {{'device.lwm2m-value-edit' | translate }}
98 </button> 97 </button>
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { Component, forwardRef, Inject, Input, OnDestroy, OnInit } from '@angular/core'; 17 +import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
18 import { 18 import {
19 ControlValueAccessor, 19 ControlValueAccessor,
20 FormBuilder, 20 FormBuilder,
@@ -41,8 +41,7 @@ import { @@ -41,8 +41,7 @@ import {
41 DeviceCredentialsDialogLwm2mData, 41 DeviceCredentialsDialogLwm2mData,
42 END_POINT, 42 END_POINT,
43 getDefaultSecurityConfig, 43 getDefaultSecurityConfig,
44 - JSON_ALL_CONFIG,  
45 - SecurityConfigModels 44 + JSON_ALL_CONFIG
46 } from '@home/pages/device/lwm2m/security-config.models'; 45 } from '@home/pages/device/lwm2m/security-config.models';
47 import { TranslateService } from '@ngx-translate/core'; 46 import { TranslateService } from '@ngx-translate/core';
48 import { MatDialog } from '@angular/material/dialog'; 47 import { MatDialog } from '@angular/material/dialog';
@@ -197,6 +196,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, @@ -197,6 +196,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
197 this.deviceCredentialsFormGroup.get('credentialsBasic').disable({emitEvent: false}); 196 this.deviceCredentialsFormGroup.get('credentialsBasic').disable({emitEvent: false});
198 break; 197 break;
199 case DeviceCredentialsType.X509_CERTIFICATE: 198 case DeviceCredentialsType.X509_CERTIFICATE:
  199 + case DeviceCredentialsType.LWM2M_CREDENTIALS:
200 this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required]); 200 this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required]);
201 this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false}); 201 this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false});
202 this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]); 202 this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]);
@@ -211,13 +211,6 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, @@ -211,13 +211,6 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
211 this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([]); 211 this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([]);
212 this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false}); 212 this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false});
213 break; 213 break;
214 - case DeviceCredentialsType.LWM2M_CREDENTIALS:  
215 - this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required]);  
216 - this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity({emitEvent: false});  
217 - this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]);  
218 - this.deviceCredentialsFormGroup.get('credentialsId').updateValueAndValidity({emitEvent: false});  
219 - this.deviceCredentialsFormGroup.get('credentialsBasic').disable({emitEvent: false});  
220 - break;  
221 } 214 }
222 } 215 }
223 216
@@ -245,27 +238,39 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, @@ -245,27 +238,39 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
245 }); 238 });
246 } 239 }
247 240
248 - openSecurityInfoLwM2mDialog($event: Event, value: string, id: string): void { 241 + openSecurityInfoLwM2mDialog($event: Event): void {
249 if ($event) { 242 if ($event) {
250 $event.stopPropagation(); 243 $event.stopPropagation();
251 $event.preventDefault(); 244 $event.preventDefault();
252 } 245 }
  246 + let credentialsValue = this.deviceCredentialsFormGroup.get('credentialsValue').value;
  247 + if (credentialsValue === null || credentialsValue.length === 0) {
  248 + credentialsValue = getDefaultSecurityConfig();
  249 + } else {
  250 + credentialsValue = JSON.parse(credentialsValue);
  251 + }
  252 + const credentialsId = this.deviceCredentialsFormGroup.get('credentialsId').value || DEFAULT_END_POINT;
253 this.dialog.open<SecurityConfigComponent, DeviceCredentialsDialogLwm2mData, object>(SecurityConfigComponent, { 253 this.dialog.open<SecurityConfigComponent, DeviceCredentialsDialogLwm2mData, object>(SecurityConfigComponent, {
254 disableClose: true, 254 disableClose: true,
255 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], 255 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
256 data: { 256 data: {
257 - jsonAllConfig: (value === null || value.length === 0) ? getDefaultSecurityConfig() as SecurityConfigModels : JSON.parse(value) as SecurityConfigModels,  
258 - endPoint: (id === null) ? DEFAULT_END_POINT : id,  
259 - isNew: (id === null || value === null || value.length === 0) 257 + jsonAllConfig: credentialsValue,
  258 + endPoint: credentialsId
260 } 259 }
261 }).afterClosed().subscribe( 260 }).afterClosed().subscribe(
262 (res) => { 261 (res) => {
263 if (res) { 262 if (res) {
264 - this.deviceCredentialsFormGroup.get('credentialsValue').patchValue((Object.keys(res[JSON_ALL_CONFIG]).length === 0 || JSON.stringify(res[JSON_ALL_CONFIG]) === "[{}]") ? null : JSON.stringify(res[JSON_ALL_CONFIG]));  
265 - this.deviceCredentialsFormGroup.get('credentialsId').patchValue((Object.keys(res[END_POINT]).length === 0 || JSON.stringify(res[END_POINT]) === "[{}]") ? null : JSON.stringify(res[END_POINT]).split('\"').join('')); 263 + this.deviceCredentialsFormGroup.patchValue({
  264 + credentialsValue: this.isDefautLw2mResponse(res[JSON_ALL_CONFIG]) ? null : JSON.stringify(res[JSON_ALL_CONFIG]),
  265 + credentialsId: this.isDefautLw2mResponse(res[END_POINT]) ? null : JSON.stringify(res[END_POINT]).split('\"').join('')
  266 + });
266 this.deviceCredentialsFormGroup.get('credentialsValue').markAsDirty(); 267 this.deviceCredentialsFormGroup.get('credentialsValue').markAsDirty();
267 } 268 }
268 } 269 }
269 ); 270 );
270 } 271 }
  272 +
  273 + private isDefautLw2mResponse(response: object): boolean {
  274 + return Object.keys(response).length === 0 || JSON.stringify(response) === '[{}]';
  275 + }
271 } 276 }
@@ -307,7 +307,7 @@ import { Lwm2mProfileComponentsModule } from '@home/components/profile/device/lw @@ -307,7 +307,7 @@ import { Lwm2mProfileComponentsModule } from '@home/components/profile/device/lw
307 EditAlarmDetailsDialogComponent, 307 EditAlarmDetailsDialogComponent,
308 DeviceProfileProvisionConfigurationComponent, 308 DeviceProfileProvisionConfigurationComponent,
309 AlarmScheduleComponent, 309 AlarmScheduleComponent,
310 - Lwm2mProfileComponentsModule, 310 + // Lwm2mProfileComponentsModule,
311 SmsProviderConfigurationComponent, 311 SmsProviderConfigurationComponent,
312 AwsSnsProviderConfigurationComponent, 312 AwsSnsProviderConfigurationComponent,
313 TwilioSmsProviderConfigurationComponent 313 TwilioSmsProviderConfigurationComponent
@@ -21,10 +21,9 @@ @@ -21,10 +21,9 @@
21 <div fxLayout="row" fxLayoutGap="8px"> 21 <div fxLayout="row" fxLayoutGap="8px">
22 <mat-form-field class="mat-block"> 22 <mat-form-field class="mat-block">
23 <mat-label>{{ 'device-profile.lwm2m.mode' | translate }}</mat-label> 23 <mat-label>{{ 'device-profile.lwm2m.mode' | translate }}</mat-label>
24 - <mat-select formControlName="securityMode"  
25 - [ngSwitch]="securityConfigLwM2MTypes"> 24 + <mat-select formControlName="securityMode">
26 <mat-option *ngFor="let securityMode of securityConfigLwM2MTypes" 25 <mat-option *ngFor="let securityMode of securityConfigLwM2MTypes"
27 - [value]="securityMode" > 26 + [value]="securityMode">
28 {{ credentialTypeLwM2MNamesMap.get(securityConfigLwM2MType[securityMode]) }} 27 {{ credentialTypeLwM2MNamesMap.get(securityConfigLwM2MType[securityMode]) }}
29 </mat-option> 28 </mat-option>
30 </mat-select> 29 </mat-select>
@@ -87,33 +86,31 @@ @@ -87,33 +86,31 @@
87 {{ 'device-profile.lwm2m.bootstrap-server' | translate }} 86 {{ 'device-profile.lwm2m.bootstrap-server' | translate }}
88 </mat-checkbox> 87 </mat-checkbox>
89 </div> 88 </div>
90 - <div [fxShow]="serverFormGroup.get('securityMode').value !== securityConfigLwM2MType.NO_SEC">  
91 - <div  
92 - [fxShow]="serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK ||  
93 - serverFormGroup.get('securityMode').value === securityConfigLwM2MType.X509">  
94 - <mat-form-field class="mat-block">  
95 - <mat-label>{{ 'device-profile.lwm2m.server-public-key' | translate }}</mat-label>  
96 - <textarea matInput type="text" rows="3" cols="1" formControlName="serverPublicKey" #serverPublicKey maxlength={{lenMaxServerPublicKey}}  
97 - matTooltip="{{'device-profile.lwm2m.server-public-key-tip' | translate}}"  
98 - [required]="serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK ||  
99 - serverFormGroup.get('securityMode').value === securityConfigLwM2MType.X509"></textarea>  
100 - <mat-hint align="end">{{serverPublicKey.value?.length || 0}}/{{lenMaxServerPublicKey}}</mat-hint>  
101 - <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('required')">  
102 - {{ 'device-profile.lwm2m.server-public-key' | translate }}  
103 - <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>  
104 - </mat-error>  
105 - <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('pattern') &&  
106 - serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK">  
107 - {{ 'device-profile.lwm2m.client-key' | translate }}  
108 - <strong>{{ 'device-profile.lwm2m.pattern_hex_dec_182' | translate }}</strong>  
109 - </mat-error>  
110 - <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('pattern') &&  
111 - serverFormGroup.get('securityMode').value === securityConfigLwM2MType.X509">  
112 - {{ 'device-profile.lwm2m.client-key' | translate }}  
113 - <strong>{{ 'device-profile.lwm2m.pattern_hex_dec' | translate }}</strong>  
114 - </mat-error>  
115 - </mat-form-field>  
116 - </div> 89 + <div *ngIf="serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK ||
  90 + serverFormGroup.get('securityMode').value === securityConfigLwM2MType.X509">
  91 + <mat-form-field class="mat-block">
  92 + <mat-label>{{ 'device-profile.lwm2m.server-public-key' | translate }}</mat-label>
  93 + <textarea matInput type="text" rows="3" cols="1" required
  94 + formControlName="serverPublicKey" #serverPublicKey
  95 + maxlength="{{lenMaxServerPublicKey}}"
  96 + matTooltip="{{'device-profile.lwm2m.server-public-key-tip' | translate}}"
  97 + ></textarea>
  98 + <mat-hint align="end">{{serverPublicKey.value?.length || 0}}/{{lenMaxServerPublicKey}}</mat-hint>
  99 + <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('required')">
  100 + {{ 'device-profile.lwm2m.server-public-key' | translate }}
  101 + <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
  102 + </mat-error>
  103 + <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('pattern') &&
  104 + serverFormGroup.get('securityMode').value === securityConfigLwM2MType.RPK">
  105 + {{ 'device-profile.lwm2m.client-key' | translate }}
  106 + <strong>{{ 'device-profile.lwm2m.pattern_hex_dec_182' | translate }}</strong>
  107 + </mat-error>
  108 + <mat-error *ngIf="serverFormGroup.get('serverPublicKey').hasError('pattern') &&
  109 + serverFormGroup.get('securityMode').value === securityConfigLwM2MType.X509">
  110 + {{ 'device-profile.lwm2m.client-key' | translate }}
  111 + <strong>{{ 'device-profile.lwm2m.pattern_hex_dec' | translate }}</strong>
  112 + </mat-error>
  113 + </mat-form-field>
117 </div> 114 </div>
118 </div> 115 </div>
119 </div> 116 </div>
@@ -43,7 +43,6 @@ import { DeviceProfileService } from '@core/http/device-profile.service'; @@ -43,7 +43,6 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
43 @Component({ 43 @Component({
44 selector: 'tb-profile-lwm2m-device-config-server', 44 selector: 'tb-profile-lwm2m-device-config-server',
45 templateUrl: './lwm2m-device-config-server.component.html', 45 templateUrl: './lwm2m-device-config-server.component.html',
46 - styleUrls: [],  
47 providers: [ 46 providers: [
48 { 47 {
49 provide: NG_VALUE_ACCESSOR, 48 provide: NG_VALUE_ACCESSOR,
@@ -55,8 +54,8 @@ import { DeviceProfileService } from '@core/http/device-profile.service'; @@ -55,8 +54,8 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
55 54
56 export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAccessor, Validators { 55 export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAccessor, Validators {
57 56
58 - valuePrev = null as any;  
59 private requiredValue: boolean; 57 private requiredValue: boolean;
  58 + valuePrev = null;
60 serverFormGroup: FormGroup; 59 serverFormGroup: FormGroup;
61 securityConfigLwM2MType = SECURITY_CONFIG_MODE; 60 securityConfigLwM2MType = SECURITY_CONFIG_MODE;
62 securityConfigLwM2MTypes = Object.keys(SECURITY_CONFIG_MODE); 61 securityConfigLwM2MTypes = Object.keys(SECURITY_CONFIG_MODE);
@@ -69,7 +68,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -69,7 +68,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
69 disabled: boolean; 68 disabled: boolean;
70 69
71 @Input() 70 @Input()
72 - bootstrapServerIs: boolean 71 + bootstrapServerIs: boolean;
73 72
74 get required(): boolean { 73 get required(): boolean {
75 return this.requiredValue; 74 return this.requiredValue;
@@ -107,7 +106,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -107,7 +106,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
107 } 106 }
108 107
109 updateValueFields(serverData: ServerSecurityConfig): void { 108 updateValueFields(serverData: ServerSecurityConfig): void {
110 - serverData['bootstrapServerIs'] = this.bootstrapServerIs; 109 + serverData.bootstrapServerIs = this.bootstrapServerIs;
111 this.serverFormGroup.patchValue(serverData, {emitEvent: false}); 110 this.serverFormGroup.patchValue(serverData, {emitEvent: false});
112 this.serverFormGroup.get('bootstrapServerIs').disable(); 111 this.serverFormGroup.get('bootstrapServerIs').disable();
113 const securityMode = this.serverFormGroup.get('securityMode').value as SECURITY_CONFIG_MODE; 112 const securityMode = this.serverFormGroup.get('securityMode').value as SECURITY_CONFIG_MODE;
@@ -132,21 +131,22 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -132,21 +131,22 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
132 this.serverFormGroup.get('serverPublicKey').setValidators([Validators.required, Validators.pattern(KEY_PUBLIC_REGEXP_X509)]); 131 this.serverFormGroup.get('serverPublicKey').setValidators([Validators.required, Validators.pattern(KEY_PUBLIC_REGEXP_X509)]);
133 break; 132 break;
134 } 133 }
135 - this.checkValueWithNewValidate(); 134 + this.serverFormGroup.updateValueAndValidity();
  135 + // this.checkValueWithNewValidate();
136 } 136 }
137 137
138 - checkValueWithNewValidate(): void {  
139 - this.serverFormGroup.patchValue({  
140 - host: this.serverFormGroup.get('host').value,  
141 - port: this.serverFormGroup.get('port').value,  
142 - bootstrapServerIs: this.serverFormGroup.get('bootstrapServerIs').value,  
143 - serverPublicKey: this.serverFormGroup.get('serverPublicKey').value,  
144 - clientHoldOffTime: this.serverFormGroup.get('clientHoldOffTime').value,  
145 - serverId: this.serverFormGroup.get('serverId').value,  
146 - bootstrapServerAccountTimeout: this.serverFormGroup.get('bootstrapServerAccountTimeout').value,  
147 - },  
148 - {emitEvent: true});  
149 - } 138 + // checkValueWithNewValidate(): void {
  139 + // this.serverFormGroup.patchValue({
  140 + // host: this.serverFormGroup.get('host').value,
  141 + // port: this.serverFormGroup.get('port').value,
  142 + // bootstrapServerIs: this.serverFormGroup.get('bootstrapServerIs').value,
  143 + // serverPublicKey: this.serverFormGroup.get('serverPublicKey').value,
  144 + // clientHoldOffTime: this.serverFormGroup.get('clientHoldOffTime').value,
  145 + // serverId: this.serverFormGroup.get('serverId').value,
  146 + // bootstrapServerAccountTimeout: this.serverFormGroup.get('bootstrapServerAccountTimeout').value,
  147 + // },
  148 + // {emitEvent: true});
  149 + // }
150 150
151 writeValue(value: any): void { 151 writeValue(value: any): void {
152 if (value) { 152 if (value) {
@@ -154,8 +154,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -154,8 +154,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
154 } 154 }
155 } 155 }
156 156
157 - private propagateChange = (v: any) => {  
158 - }; 157 + private propagateChange = (v: any) => {};
159 158
160 registerOnChange(fn: any): void { 159 registerOnChange(fn: any): void {
161 this.propagateChange = fn; 160 this.propagateChange = fn;
@@ -164,8 +163,8 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -164,8 +163,8 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
164 private propagateChangeState(value: any): void { 163 private propagateChangeState(value: any): void {
165 if (value !== undefined) { 164 if (value !== undefined) {
166 if (this.valuePrev === null) { 165 if (this.valuePrev === null) {
167 - this.valuePrev = "init";  
168 - } else if (this.valuePrev === "init") { 166 + this.valuePrev = 'init';
  167 + } else if (this.valuePrev === 'init') {
169 this.valuePrev = value; 168 this.valuePrev = value;
170 } else if (JSON.stringify(value) !== JSON.stringify(this.valuePrev)) { 169 } else if (JSON.stringify(value) !== JSON.stringify(this.valuePrev)) {
171 this.valuePrev = value; 170 this.valuePrev = value;
@@ -192,7 +191,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -192,7 +191,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
192 } 191 }
193 192
194 getServerGroup(): FormGroup { 193 getServerGroup(): FormGroup {
195 - const port = (this.bootstrapServerIs) ? DEFAULT_PORT_BOOTSTRAP_NO_SEC : DEFAULT_PORT_SERVER_NO_SEC; 194 + const port = this.bootstrapServerIs ? DEFAULT_PORT_BOOTSTRAP_NO_SEC : DEFAULT_PORT_SERVER_NO_SEC;
196 return this.fb.group({ 195 return this.fb.group({
197 host: [this.window.location.hostname, this.required ? [Validators.required] : []], 196 host: [this.window.location.hostname, this.required ? [Validators.required] : []],
198 port: [port, this.required ? [Validators.required] : []], 197 port: [port, this.required ? [Validators.required] : []],
@@ -202,7 +201,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc @@ -202,7 +201,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc
202 clientHoldOffTime: [DEFAULT_CLIENT_HOLD_OFF_TIME, this.required ? [Validators.required] : []], 201 clientHoldOffTime: [DEFAULT_CLIENT_HOLD_OFF_TIME, this.required ? [Validators.required] : []],
203 serverId: [DEFAULT_ID_SERVER, this.required ? [Validators.required] : []], 202 serverId: [DEFAULT_ID_SERVER, this.required ? [Validators.required] : []],
204 bootstrapServerAccountTimeout: ['', this.required ? [Validators.required] : []], 203 bootstrapServerAccountTimeout: ['', this.required ? [Validators.required] : []],
205 - }) 204 + });
206 } 205 }
207 206
208 getLwm2mBootstrapSecurityInfo(mode: string) { 207 getLwm2mBootstrapSecurityInfo(mode: string) {
@@ -40,8 +40,7 @@ @@ -40,8 +40,7 @@
40 <mat-expansion-panel> 40 <mat-expansion-panel>
41 <mat-expansion-panel-header> 41 <mat-expansion-panel-header>
42 <mat-panel-title> 42 <mat-panel-title>
43 - <div  
44 - class="tb-panel-title">{{ 'device-profile.lwm2m.servers' | translate | uppercase }}</div> 43 + <div class="tb-panel-title">{{ 'device-profile.lwm2m.servers' | translate | uppercase }}</div>
45 </mat-panel-title> 44 </mat-panel-title>
46 </mat-expansion-panel-header> 45 </mat-expansion-panel-header>
47 <div fxLayout="column"> 46 <div fxLayout="column">
@@ -93,8 +92,7 @@ @@ -93,8 +92,7 @@
93 <mat-expansion-panel> 92 <mat-expansion-panel>
94 <mat-expansion-panel-header> 93 <mat-expansion-panel-header>
95 <mat-panel-title> 94 <mat-panel-title>
96 - <div  
97 - class="tb-panel-title">{{ 'device-profile.lwm2m.bootstrap-server' | translate | uppercase }}</div> 95 + <div class="tb-panel-title">{{ 'device-profile.lwm2m.bootstrap-server' | translate | uppercase }}</div>
98 </mat-panel-title> 96 </mat-panel-title>
99 </mat-expansion-panel-header> 97 </mat-expansion-panel-header>
100 <div class="mat-padding"> 98 <div class="mat-padding">
@@ -110,8 +108,7 @@ @@ -110,8 +108,7 @@
110 <mat-expansion-panel> 108 <mat-expansion-panel>
111 <mat-expansion-panel-header> 109 <mat-expansion-panel-header>
112 <mat-panel-title> 110 <mat-panel-title>
113 - <div  
114 - class="tb-panel-title">{{ 'device-profile.lwm2m.lwm2m-server' | translate | uppercase }}</div> 111 + <div class="tb-panel-title">{{ 'device-profile.lwm2m.lwm2m-server' | translate | uppercase }}</div>
115 </mat-panel-title> 112 </mat-panel-title>
116 </mat-expansion-panel-header> 113 </mat-expansion-panel-header>
117 <div class="mat-padding"> 114 <div class="mat-padding">
@@ -33,7 +33,7 @@ import { @@ -33,7 +33,7 @@ import {
33 OBSERVE, 33 OBSERVE,
34 OBSERVE_ATTR, 34 OBSERVE_ATTR,
35 TELEMETRY, 35 TELEMETRY,
36 - ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance 36 + ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance, ProfileConfigModels, ResourceLwM2M
37 } from "./profile-config.models"; 37 } from "./profile-config.models";
38 import { DeviceProfileService } from "@core/http/device-profile.service"; 38 import { DeviceProfileService } from "@core/http/device-profile.service";
39 import { deepClone, isUndefined } from "@core/utils"; 39 import { deepClone, isUndefined } from "@core/utils";
@@ -44,7 +44,6 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; @@ -44,7 +44,6 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined';
44 @Component({ 44 @Component({
45 selector: 'tb-profile-lwm2m-device-transport-configuration', 45 selector: 'tb-profile-lwm2m-device-transport-configuration',
46 templateUrl: './lwm2m-device-profile-transport-configuration.component.html', 46 templateUrl: './lwm2m-device-profile-transport-configuration.component.html',
47 - styleUrls: [],  
48 providers: [{ 47 providers: [{
49 provide: NG_VALUE_ACCESSOR, 48 provide: NG_VALUE_ACCESSOR,
50 useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent), 49 useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent),
@@ -53,6 +52,10 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; @@ -53,6 +52,10 @@ import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined';
53 }) 52 })
54 export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, Validators { 53 export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, Validators {
55 54
  55 + private configurationValue: ProfileConfigModels;
  56 + private requiredValue: boolean;
  57 + private disabled = false;
  58 +
56 lwm2mDeviceProfileTransportConfFormGroup: FormGroup; 59 lwm2mDeviceProfileTransportConfFormGroup: FormGroup;
57 observeAttr = OBSERVE_ATTR as string; 60 observeAttr = OBSERVE_ATTR as string;
58 observe = OBSERVE as string; 61 observe = OBSERVE as string;
@@ -62,9 +65,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -62,9 +65,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
62 bootstrapServers: string; 65 bootstrapServers: string;
63 bootstrapServer: string; 66 bootstrapServer: string;
64 lwm2mServer: string; 67 lwm2mServer: string;
65 - private configurationValue: {};  
66 - private requiredValue: boolean;  
67 - private disabled = false as boolean;  
68 sortFunction = this.sortObjectKeyPathJson; 68 sortFunction = this.sortObjectKeyPathJson;
69 69
70 get required(): boolean { 70 get required(): boolean {
@@ -76,8 +76,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -76,8 +76,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
76 this.requiredValue = coerceBooleanProperty(value); 76 this.requiredValue = coerceBooleanProperty(value);
77 } 77 }
78 78
79 - private propagateChange = (v: any) => {  
80 - }; 79 + private propagateChange = (v: any) => { };
81 80
82 constructor(private store: Store<AppState>, 81 constructor(private store: Store<AppState>,
83 private fb: FormBuilder, 82 private fb: FormBuilder,
@@ -85,17 +84,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -85,17 +84,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
85 @Inject(WINDOW) private window: Window) { 84 @Inject(WINDOW) private window: Window) {
86 this.lwm2mDeviceProfileTransportConfFormGroup = this.fb.group({ 85 this.lwm2mDeviceProfileTransportConfFormGroup = this.fb.group({
87 objectIds: [{}, Validators.required], 86 objectIds: [{}, Validators.required],
88 - observeAttrTelemetry: [{'clientLwM2M': [] as ObjectLwM2M []}, Validators.required], 87 + observeAttrTelemetry: [{clientLwM2M: [] as ObjectLwM2M[]}, Validators.required],
89 shortId: [null, Validators.required], 88 shortId: [null, Validators.required],
90 lifetime: [null, Validators.required], 89 lifetime: [null, Validators.required],
91 defaultMinPeriod: [null, Validators.required], 90 defaultMinPeriod: [null, Validators.required],
92 notifIfDisabled: [true, []], 91 notifIfDisabled: [true, []],
93 - binding: ["U", Validators.required], 92 + binding: ['U', Validators.required],
94 bootstrapServer: [null, Validators.required], 93 bootstrapServer: [null, Validators.required],
95 lwm2mServer: [null, Validators.required], 94 lwm2mServer: [null, Validators.required],
96 configurationJson: [null, Validators.required], 95 configurationJson: [null, Validators.required],
97 }); 96 });
98 - this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(value => { 97 + this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(() => {
99 if (!this.disabled) { 98 if (!this.disabled) {
100 this.updateModel(); 99 this.updateModel();
101 } 100 }
@@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -122,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
122 } 121 }
123 122
124 writeValue(value: any | null): void { 123 writeValue(value: any | null): void {
125 - value = (Object.keys(value).length == 0) ? getDefaultProfileConfig() : value; 124 + value = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
126 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ 125 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
127 configurationJson: value 126 configurationJson: value
128 }, 127 },
@@ -132,14 +131,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -132,14 +131,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
132 } 131 }
133 132
134 private initWriteValue(): void { 133 private initWriteValue(): void {
135 - let modelValue = {"objectIds": null, "objectsList": []}; 134 + const modelValue = {objectIds: null, objectsList: []};
136 modelValue.objectIds = this.getObjectsFromJsonAllConfig(); 135 modelValue.objectIds = this.getObjectsFromJsonAllConfig();
137 if (modelValue.objectIds !== null) { 136 if (modelValue.objectIds !== null) {
138 this.deviceProfileService.getLwm2mObjects(modelValue.objectIds).subscribe( 137 this.deviceProfileService.getLwm2mObjects(modelValue.objectIds).subscribe(
139 - (objectsList) => {  
140 - modelValue.objectsList = objectsList;  
141 - this.updateWriteValue(modelValue);  
142 - } 138 + (objectsList) => {
  139 + modelValue.objectsList = objectsList;
  140 + this.updateWriteValue(modelValue);
  141 + }
143 ); 142 );
144 } else { 143 } else {
145 this.updateWriteValue(modelValue); 144 this.updateWriteValue(modelValue);
@@ -147,17 +146,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -147,17 +146,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
147 } 146 }
148 147
149 private updateWriteValue(value: any): void { 148 private updateWriteValue(value: any): void {
150 - let objectsList = deepClone(value.objectsList); 149 + const objectsList = deepClone(value.objectsList);
151 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ 150 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
152 objectIds: value, 151 objectIds: value,
153 observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}, 152 observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)},
154 - shortId: this.configurationValue['bootstrap'].servers.shortId,  
155 - lifetime: this.configurationValue['bootstrap'].servers.lifetime,  
156 - defaultMinPeriod: this.configurationValue['bootstrap'].servers.defaultMinPeriod,  
157 - notifIfDisabled: this.configurationValue['bootstrap'].servers.notifIfDisabled,  
158 - binding: this.configurationValue['bootstrap'].servers.binding,  
159 - bootstrapServer: this.configurationValue['bootstrap'].bootstrapServer,  
160 - lwm2mServer: this.configurationValue['bootstrap'].lwm2mServer 153 + shortId: this.configurationValue.bootstrap.servers.shortId,
  154 + lifetime: this.configurationValue.bootstrap.servers.lifetime,
  155 + defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
  156 + notifIfDisabled: this.configurationValue.bootstrap.servers.notifIfDisabled,
  157 + binding: this.configurationValue.bootstrap.servers.binding,
  158 + bootstrapServer: this.configurationValue.bootstrap.bootstrapServer,
  159 + lwm2mServer: this.configurationValue.bootstrap.lwm2mServer
161 }, 160 },
162 {emitEvent: false}); 161 {emitEvent: false});
163 } 162 }
@@ -174,10 +173,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -174,10 +173,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
174 173
175 private updateObserveAttrTelemetryObjectFormGroup(objectsList: ObjectLwM2M[]) { 174 private updateObserveAttrTelemetryObjectFormGroup(objectsList: ObjectLwM2M[]) {
176 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ 175 this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({
177 - observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}  
178 - },  
179 - {emitEvent: false});  
180 - this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({ 176 + observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}
  177 + },
  178 + {emitEvent: false});
  179 + this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({
181 onlySelf: true 180 onlySelf: true
182 }); 181 });
183 } 182 }
@@ -188,9 +187,11 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -188,9 +187,11 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
188 } 187 }
189 188
190 upDateValueToJsonTab_0(): void { 189 upDateValueToJsonTab_0(): void {
191 - if (!this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").pristine) {  
192 - this.upDateObserveAttrTelemetryFromGroupToJson(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M']);  
193 - this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").markAsPristine({ 190 + if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').pristine) {
  191 + this.upDateObserveAttrTelemetryFromGroupToJson(
  192 + this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M
  193 + );
  194 + this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({
194 onlySelf: true 195 onlySelf: true
195 }); 196 });
196 this.upDateJsonAllConfig(); 197 this.upDateJsonAllConfig();
@@ -200,14 +201,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -200,14 +201,14 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
200 upDateValueToJsonTab_1(): void { 201 upDateValueToJsonTab_1(): void {
201 this.upDateValueServersToJson(); 202 this.upDateValueServersToJson();
202 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').pristine) { 203 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').pristine) {
203 - this.configurationValue['bootstrap'].bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value; 204 + this.configurationValue.bootstrap.bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value;
204 this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').markAsPristine({ 205 this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').markAsPristine({
205 onlySelf: true 206 onlySelf: true
206 }); 207 });
207 this.upDateJsonAllConfig(); 208 this.upDateJsonAllConfig();
208 } 209 }
209 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').pristine) { 210 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').pristine) {
210 - this.configurationValue['bootstrap'].lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value; 211 + this.configurationValue.bootstrap.lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value;
211 this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').markAsPristine({ 212 this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').markAsPristine({
212 onlySelf: true 213 onlySelf: true
213 }); 214 });
@@ -216,36 +217,37 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -216,36 +217,37 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
216 } 217 }
217 218
218 upDateValueServersToJson(): void { 219 upDateValueServersToJson(): void {
  220 + const bootstrapServers = this.configurationValue.bootstrap.servers;
219 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').pristine) { 221 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').pristine) {
220 - this.configurationValue['bootstrap'].servers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value; 222 + bootstrapServers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value;
221 this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').markAsPristine({ 223 this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').markAsPristine({
222 onlySelf: true 224 onlySelf: true
223 }); 225 });
224 this.upDateJsonAllConfig(); 226 this.upDateJsonAllConfig();
225 } 227 }
226 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').pristine) { 228 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').pristine) {
227 - this.configurationValue['bootstrap'].servers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value; 229 + bootstrapServers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value;
228 this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').markAsPristine({ 230 this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').markAsPristine({
229 onlySelf: true 231 onlySelf: true
230 }); 232 });
231 this.upDateJsonAllConfig(); 233 this.upDateJsonAllConfig();
232 } 234 }
233 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').pristine) { 235 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').pristine) {
234 - this.configurationValue['bootstrap'].servers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value; 236 + bootstrapServers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value;
235 this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').markAsPristine({ 237 this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').markAsPristine({
236 onlySelf: true 238 onlySelf: true
237 }); 239 });
238 this.upDateJsonAllConfig(); 240 this.upDateJsonAllConfig();
239 } 241 }
240 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').pristine) { 242 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').pristine) {
241 - this.configurationValue['bootstrap'].servers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value; 243 + bootstrapServers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value;
242 this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').markAsPristine({ 244 this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').markAsPristine({
243 onlySelf: true 245 onlySelf: true
244 }); 246 });
245 this.upDateJsonAllConfig(); 247 this.upDateJsonAllConfig();
246 } 248 }
247 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').pristine) { 249 if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').pristine) {
248 - this.configurationValue['bootstrap'].servers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value; 250 + bootstrapServers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value;
249 this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').markAsPristine({ 251 this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').markAsPristine({
250 onlySelf: true 252 onlySelf: true
251 }); 253 });
@@ -254,122 +256,130 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -254,122 +256,130 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
254 } 256 }
255 257
256 getObserveAttrTelemetryObjects(listObject: ObjectLwM2M[]): ObjectLwM2M [] { 258 getObserveAttrTelemetryObjects(listObject: ObjectLwM2M[]): ObjectLwM2M [] {
257 - let clientObserveAttr = deepClone(listObject) as ObjectLwM2M[]; 259 + const clientObserveAttr = deepClone(listObject);
258 if (this.configurationValue[this.observeAttr]) { 260 if (this.configurationValue[this.observeAttr]) {
259 - let observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>;  
260 - let attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>;  
261 - let telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>;  
262 - let keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject;  
263 - if (this.includesInstancesNo(attributeArray, telemetryArray, clientObserveAttr)) { 261 + const observeArray = this.configurationValue[this.observeAttr][this.observe] as Array<string>;
  262 + const attributeArray = this.configurationValue[this.observeAttr][this.attribute] as Array<string>;
  263 + const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry] as Array<string>;
  264 + const keyNameJson = this.configurationValue[this.observeAttr][this.keyName] as JsonObject;
  265 + if (this.includesInstancesNo(attributeArray, telemetryArray)) {
264 this.addInstances(attributeArray, telemetryArray, clientObserveAttr); 266 this.addInstances(attributeArray, telemetryArray, clientObserveAttr);
265 } 267 }
266 - if (observeArray) this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, "observe");  
267 - if (attributeArray) this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, "attribute");  
268 - if (telemetryArray) this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, "telemetry");  
269 - if (keyNameJson) this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr); 268 + if (observeArray) {
  269 + this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, 'observe');
  270 + }
  271 + if (attributeArray) {
  272 + this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, 'attribute');
  273 + }
  274 + if (telemetryArray) {
  275 + this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, 'telemetry');
  276 + }
  277 + if (keyNameJson) {
  278 + this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr);
  279 + }
270 } 280 }
271 clientObserveAttr.forEach(obj => { 281 clientObserveAttr.forEach(obj => {
272 - obj.instances.sort((a,b) => a.id - b.id);;  
273 - }) 282 + obj.instances.sort((a, b) => a.id - b.id);
  283 + });
274 return clientObserveAttr; 284 return clientObserveAttr;
275 } 285 }
276 286
277 - includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): boolean {  
278 - let isIdIndex = (element) => !element.includes("/0/");  
279 - return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0  
280 - 287 + includesInstancesNo(attributeArray: Array<string>, telemetryArray: Array<string>): boolean {
  288 + const isIdIndex = (element) => !element.includes('/0/');
  289 + return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0;
281 } 290 }
282 291
283 addInstances(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): void { 292 addInstances(attributeArray: Array<string>, telemetryArray: Array<string>, clientObserveAttr: ObjectLwM2M[]): void {
284 - let attr = [] as Array<string>;  
285 - [...attributeArray].filter(x => (!x.includes("/0/"))).forEach(x => { 293 + const attr = [] as Array<string>;
  294 + [...attributeArray].filter(x => (!x.includes('/0/'))).forEach(x => {
286 attr.push(this.convertPathToInstance(x)); 295 attr.push(this.convertPathToInstance(x));
287 }); 296 });
288 - let telemetry = [] as Array<string>;  
289 - [...telemetryArray].filter(x => (!x.includes("/0/"))).forEach(x => { 297 + const telemetry = [] as Array<string>;
  298 + [...telemetryArray].filter(x => (!x.includes('/0/'))).forEach(x => {
290 telemetry.push(this.convertPathToInstance(x)); 299 telemetry.push(this.convertPathToInstance(x));
291 }); 300 });
292 - let instancesNoZero = new Set(attr.concat(telemetry).sort()); 301 + const instancesNoZero = new Set(attr.concat(telemetry).sort());
293 instancesNoZero.forEach(path => { 302 instancesNoZero.forEach(path => {
294 - let pathParameter = Array.from(path.split('/'), Number);  
295 - let objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0])); 303 + const pathParameter = Array.from(path.split('/'), Number);
  304 + const objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0]));
296 if (objectLwM2M) { 305 if (objectLwM2M) {
297 - let instance = deepClone(objectLwM2M.instances[0]) as Instance; 306 + const instance = deepClone(objectLwM2M.instances[0]) as Instance;
298 instance.id = pathParameter[1]; 307 instance.id = pathParameter[1];
299 objectLwM2M.instances.push(instance); 308 objectLwM2M.instances.push(instance);
300 } 309 }
301 - }) 310 + });
302 } 311 }
303 312
304 convertPathToInstance(path: string): string { 313 convertPathToInstance(path: string): string {
305 - let newX = Array.from(path.substring(1).split('/'), Number);  
306 - return [newX[0], newX[1]].join("/"); 314 + const newX = Array.from(path.substring(1).split('/'), Number);
  315 + return [newX[0], newX[1]].join('/');
307 } 316 }
308 317
309 updateObserveAttrTelemetryObjects(isParameter: Array<string>, clientObserveAttr: ObjectLwM2M[], nameParameter: string): void { 318 updateObserveAttrTelemetryObjects(isParameter: Array<string>, clientObserveAttr: ObjectLwM2M[], nameParameter: string): void {
310 isParameter.forEach(attr => { 319 isParameter.forEach(attr => {
311 - let idKeys = Array.from(attr.substring(1).split('/'), Number); 320 + const idKeys = Array.from(attr.substring(1).split('/'), Number);
312 clientObserveAttr 321 clientObserveAttr
313 - .forEach(e => {  
314 - if (e.id == idKeys[0]) {  
315 - let instance = e.instances.find(e => e.id == idKeys[1]);  
316 - if (isNotNullOrUndefined(instance)) {  
317 - instance.resources.find(e => e.id == idKeys[2])[nameParameter] = true; 322 + .forEach(e => {
  323 + if (e.id === idKeys[0]) {
  324 + const instance = e.instances.find(itrInstance => itrInstance.id === idKeys[1]);
  325 + if (isNotNullOrUndefined(instance)) {
  326 + instance.resources.find(resource => resource.id === idKeys[2])[nameParameter] = true;
  327 + }
318 } 328 }
319 - }  
320 - }); 329 + });
321 }); 330 });
322 } 331 }
323 332
324 updateKeyNameObjects(nameJson: JsonObject, clientObserveAttr: ObjectLwM2M[]): void { 333 updateKeyNameObjects(nameJson: JsonObject, clientObserveAttr: ObjectLwM2M[]): void {
325 - let keyName = JSON.parse(JSON.stringify(nameJson));  
326 - Object.keys(keyName).forEach(function (key) {  
327 - let idKeys = Array.from(key.substring(1).split('/'), Number); 334 + const keyName = JSON.parse(JSON.stringify(nameJson));
  335 + Object.keys(keyName).forEach(key => {
  336 + const idKeys = Array.from(key.substring(1).split('/'), Number);
328 clientObserveAttr 337 clientObserveAttr
329 - .forEach(e => {  
330 - if (e.id == idKeys[0]) {  
331 - e.instances.find(e => e.id == idKeys[1]).resources  
332 - .find(e => e.id == idKeys[2]).keyName = keyName[key];  
333 - }  
334 - }); 338 + .forEach(e => {
  339 + if (e.id === idKeys[0]) {
  340 + e.instances
  341 + .find(instance => instance.id === idKeys[1]).resources
  342 + .find(resource => resource.id === idKeys[2]).keyName = keyName[key];
  343 + }
  344 + });
335 }); 345 });
336 } 346 }
337 347
338 - upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M []): void {  
339 - let observeArray = [] as Array<string>;  
340 - let attributeArray = [] as Array<string>;  
341 - let telemetryArray = [] as Array<string>;  
342 - let observeJson = JSON.parse(JSON.stringify(val)); 348 + upDateObserveAttrTelemetryFromGroupToJson(val: ObjectLwM2M[]): void {
  349 + const observeArray: Array<string> = [];
  350 + const attributeArray: Array<string> = [];
  351 + const telemetryArray: Array<string> = [];
  352 + const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
343 let pathObj; 353 let pathObj;
344 let pathInst; 354 let pathInst;
345 - let pathRes 355 + let pathRes;
346 observeJson.forEach(obj => { 356 observeJson.forEach(obj => {
347 Object.entries(obj).forEach(([key, value]) => { 357 Object.entries(obj).forEach(([key, value]) => {
348 if (key === 'id') { 358 if (key === 'id') {
349 pathObj = value; 359 pathObj = value;
350 } 360 }
351 if (key === 'instances') { 361 if (key === 'instances') {
352 - let instancesJson = JSON.parse(JSON.stringify(value)) as []; 362 + const instancesJson = JSON.parse(JSON.stringify(value)) as Instance[];
353 if (instancesJson.length > 0) { 363 if (instancesJson.length > 0) {
354 instancesJson.forEach(instance => { 364 instancesJson.forEach(instance => {
355 - Object.entries(instance).forEach(([key, value]) => {  
356 - if (key === 'id') {  
357 - pathInst = value; 365 + Object.entries(instance).forEach(([instanceKey, instanceValue]) => {
  366 + if (instanceKey === 'id') {
  367 + pathInst = instanceValue;
358 } 368 }
359 - if (key === 'resources') {  
360 - let resourcesJson = JSON.parse(JSON.stringify(value)) as []; 369 + if (instanceKey === 'resources') {
  370 + const resourcesJson = JSON.parse(JSON.stringify(instanceValue)) as ResourceLwM2M[];
361 if (resourcesJson.length > 0) { 371 if (resourcesJson.length > 0) {
362 resourcesJson.forEach(res => { 372 resourcesJson.forEach(res => {
363 - Object.entries(res).forEach(([key, value]) => {  
364 - if (key === 'id') {  
365 - // pathRes = value  
366 - pathRes = '/' + pathObj + '/' + pathInst + '/' + value;  
367 - } else if (key === 'observe' && value) {  
368 - observeArray.push(pathRes)  
369 - } else if (key === 'attribute' && value) {  
370 - attributeArray.push(pathRes)  
371 - } else if (key === 'telemetry' && value) {  
372 - telemetryArray.push(pathRes) 373 + Object.entries(res).forEach(([resourceKey, resourceValue]) => {
  374 + if (resourceKey === 'id') {
  375 + // pathRes = resourceValue
  376 + pathRes = '/' + pathObj + '/' + pathInst + '/' + resourceValue;
  377 + } else if (resourceKey === 'observe' && resourceValue) {
  378 + observeArray.push(pathRes);
  379 + } else if (resourceKey === 'attribute' && resourceValue) {
  380 + attributeArray.push(pathRes);
  381 + } else if (resourceKey === 'telemetry' && resourceValue) {
  382 + telemetryArray.push(pathRes);
373 } 383 }
374 }); 384 });
375 }); 385 });
@@ -396,19 +406,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -396,19 +406,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
396 } 406 }
397 407
398 sortObjectKeyPathJson(key, value) { 408 sortObjectKeyPathJson(key, value) {
399 - if (key == "keyName") { 409 + if (key === 'keyName') {
400 return Object.keys(value).sort((a, b) => { 410 return Object.keys(value).sort((a, b) => {
401 - let aLC = Array.from(a.substring(1).split('/'), Number);  
402 - let bLC = Array.from(b.substring(1).split('/'), Number);  
403 - return aLC[0] == bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0];  
404 - }).reduce((r, k) => (r[k] = value[k], r), {}); 411 + const aLC = Array.from(a.substring(1).split('/'), Number);
  412 + const bLC = Array.from(b.substring(1).split('/'), Number);
  413 + return aLC[0] === bLC[0] ? aLC[1] - bLC[1] : aLC[0] - bLC[0];
  414 + }).reduce((r, k) => r[k] = value[k], {});
405 } else { 415 } else {
406 - return value 416 + return value;
407 } 417 }
408 } 418 }
409 419
410 updateKeyName(): void { 420 updateKeyName(): void {
411 - let paths = new Set<string>(); 421 + const paths = new Set<string>();
412 if (this.configurationValue[this.observeAttr][this.attribute]) { 422 if (this.configurationValue[this.observeAttr][this.attribute]) {
413 this.configurationValue[this.observeAttr][this.attribute].forEach(path => { 423 this.configurationValue[this.observeAttr][this.attribute].forEach(path => {
414 paths.add(path); 424 paths.add(path);
@@ -419,31 +429,32 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -419,31 +429,32 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
419 paths.add(path); 429 paths.add(path);
420 }); 430 });
421 } 431 }
422 - let keyNameNew = {}; 432 + const keyNameNew = {};
423 paths.forEach(path => { 433 paths.forEach(path => {
424 - let pathParameter = this.findIndexsForIds(path); 434 + const pathParameter = this.findIndexsForIds(path);
425 if (pathParameter.length === 3) { 435 if (pathParameter.length === 3) {
426 - let value = this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value['clientLwM2M'][pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];  
427 - keyNameNew[path] = value; 436 + keyNameNew[path] = this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value
  437 + .clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];
428 } 438 }
429 }); 439 });
430 - this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson("keyName", keyNameNew); 440 + this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);
431 } 441 }
432 442
433 findIndexsForIds(path: string): number[] { 443 findIndexsForIds(path: string): number[] {
434 - let pathParameter = Array.from(path.substring(1).split('/'), Number);  
435 - let pathParameterIndexes = [] as number[];  
436 - let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M) as ObjectLwM2M[]; 444 + const pathParameter = Array.from(path.substring(1).split('/'), Number);
  445 + const pathParameterIndexes: number[] = [];
  446 + const objectsOld = deepClone(
  447 + this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[];
437 let isIdIndex = (element) => element.id === pathParameter[0]; 448 let isIdIndex = (element) => element.id === pathParameter[0];
438 - let objIndex = objectsOld.findIndex(isIdIndex); 449 + const objIndex = objectsOld.findIndex(isIdIndex);
439 if (objIndex >= 0) { 450 if (objIndex >= 0) {
440 pathParameterIndexes.push(objIndex); 451 pathParameterIndexes.push(objIndex);
441 isIdIndex = (element) => element.id === pathParameter[1]; 452 isIdIndex = (element) => element.id === pathParameter[1];
442 - let instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex); 453 + const instIndex = objectsOld[objIndex].instances.findIndex(isIdIndex);
443 if (instIndex >= 0) { 454 if (instIndex >= 0) {
444 pathParameterIndexes.push(instIndex); 455 pathParameterIndexes.push(instIndex);
445 isIdIndex = (element) => element.id === pathParameter[2]; 456 isIdIndex = (element) => element.id === pathParameter[2];
446 - let resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex); 457 + const resIndex = objectsOld[objIndex].instances[instIndex].resources.findIndex(isIdIndex);
447 if (resIndex >= 0) { 458 if (resIndex >= 0) {
448 pathParameterIndexes.push(resIndex); 459 pathParameterIndexes.push(resIndex);
449 } 460 }
@@ -453,7 +464,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -453,7 +464,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
453 } 464 }
454 465
455 getObjectsFromJsonAllConfig(): number [] { 466 getObjectsFromJsonAllConfig(): number [] {
456 - let objectsIds = new Set<number>(); 467 + const objectsIds = new Set<number>();
457 if (this.configurationValue[this.observeAttr]) { 468 if (this.configurationValue[this.observeAttr]) {
458 if (this.configurationValue[this.observeAttr][this.observe]) { 469 if (this.configurationValue[this.observeAttr][this.observe]) {
459 this.configurationValue[this.observeAttr][this.observe].forEach(obj => { 470 this.configurationValue[this.observeAttr][this.observe].forEach(obj => {
@@ -488,9 +499,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -488,9 +499,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
488 } 499 }
489 500
490 removeObjectsList(value: ObjectLwM2M): void { 501 removeObjectsList(value: ObjectLwM2M): void {
491 - let objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get("observeAttrTelemetry").value.clientLwM2M); 502 + const objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M);
492 const isIdIndex = (element) => element.id === value.id; 503 const isIdIndex = (element) => element.id === value.id;
493 - let index = objectsOld.findIndex(isIdIndex); 504 + const index = objectsOld.findIndex(isIdIndex);
494 if (index >= 0) { 505 if (index >= 0) {
495 objectsOld.splice(index, 1); 506 objectsOld.splice(index, 1);
496 } 507 }
@@ -504,7 +515,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -504,7 +515,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
504 } 515 }
505 516
506 removeObserveAttrTelemetryFromJson(observeAttrTel: string, id: number): void { 517 removeObserveAttrTelemetryFromJson(observeAttrTel: string, id: number): void {
507 - let isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id; 518 + const isIdIndex = (element) => Array.from(element.substring(1).split('/'), Number)[0] === id;
508 let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex); 519 let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex);
509 while (index >= 0) { 520 while (index >= 0) {
510 this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1); 521 this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1);
@@ -513,9 +524,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -513,9 +524,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
513 } 524 }
514 525
515 removeKeyNameFromJson(id: number): void { 526 removeKeyNameFromJson(id: number): void {
516 - let keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName];  
517 - Object.keys(keyNmaeJson).forEach(function (key) {  
518 - let idKey = Array.from(key.substring(1).split('/'), Number)[0]; 527 + const keyNmaeJson = this.configurationValue[this.observeAttr][this.keyName];
  528 + Object.keys(keyNmaeJson).forEach(key => {
  529 + const idKey = Array.from(key.substring(1).split('/'), Number)[0];
519 if (idKey === id) { 530 if (idKey === id) {
520 delete keyNmaeJson[key]; 531 delete keyNmaeJson[key];
521 } 532 }
@@ -33,7 +33,6 @@ export const KEY_PUBLIC_REGEXP_X509 = /^[0-9a-fA-F]{0,3000}$/; @@ -33,7 +33,6 @@ export const KEY_PUBLIC_REGEXP_X509 = /^[0-9a-fA-F]{0,3000}$/;
33 export interface DeviceCredentialsDialogLwm2mData { 33 export interface DeviceCredentialsDialogLwm2mData {
34 jsonAllConfig?: SecurityConfigModels; 34 jsonAllConfig?: SecurityConfigModels;
35 endPoint?: string; 35 endPoint?: string;
36 - isNew?: boolean;  
37 } 36 }
38 37
39 export enum SECURITY_CONFIG_MODE { 38 export enum SECURITY_CONFIG_MODE {