Commit 3cf97e0a4f811e99240a545c9777b78015a4e96e
1 parent
8b70cbdb
UI: Init models for transport type switch
Showing
5 changed files
with
39 additions
and
18 deletions
@@ -31,7 +31,8 @@ import { | @@ -31,7 +31,8 @@ import { | ||
31 | credentialTypeNames, | 31 | credentialTypeNames, |
32 | DeviceCredentialMQTTBasic, | 32 | DeviceCredentialMQTTBasic, |
33 | DeviceCredentials, | 33 | DeviceCredentials, |
34 | - DeviceCredentialsType | 34 | + DeviceCredentialsType, |
35 | + DeviceTransportType | ||
35 | } from '@shared/models/device.models'; | 36 | } from '@shared/models/device.models'; |
36 | import { Subject } from 'rxjs'; | 37 | import { Subject } from 'rxjs'; |
37 | import { takeUntil } from 'rxjs/operators'; | 38 | import { takeUntil } from 'rxjs/operators'; |
@@ -58,6 +59,9 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, | @@ -58,6 +59,9 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, | ||
58 | @Input() | 59 | @Input() |
59 | disabled: boolean; | 60 | disabled: boolean; |
60 | 61 | ||
62 | + @Input() | ||
63 | + deviceTransportType = DeviceTransportType.DEFAULT; | ||
64 | + | ||
61 | private destroy$ = new Subject(); | 65 | private destroy$ = new Subject(); |
62 | 66 | ||
63 | deviceCredentialsFormGroup: FormGroup; | 67 | deviceCredentialsFormGroup: FormGroup; |
@@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
31 | <div mat-dialog-content> | 31 | <div mat-dialog-content> |
32 | <fieldset [disabled]="(isLoading$ | async) || isReadOnly"> | 32 | <fieldset [disabled]="(isLoading$ | async) || isReadOnly"> |
33 | <tb-device-credentials | 33 | <tb-device-credentials |
34 | + [deviceTransportType]="deviceTransportType" | ||
34 | formControlName="credential"> | 35 | formControlName="credential"> |
35 | </tb-device-credentials> | 36 | </tb-device-credentials> |
36 | </fieldset> | 37 | </fieldset> |
@@ -21,13 +21,16 @@ import { Store } from '@ngrx/store'; | @@ -21,13 +21,16 @@ import { Store } from '@ngrx/store'; | ||
21 | import { AppState } from '@core/core.state'; | 21 | import { AppState } from '@core/core.state'; |
22 | import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms'; | 22 | import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms'; |
23 | import { DeviceService } from '@core/http/device.service'; | 23 | import { DeviceService } from '@core/http/device.service'; |
24 | -import { credentialTypeNames, DeviceCredentials, DeviceCredentialsType } from '@shared/models/device.models'; | 24 | +import { DeviceCredentials, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models'; |
25 | import { DialogComponent } from '@shared/components/dialog.component'; | 25 | import { DialogComponent } from '@shared/components/dialog.component'; |
26 | import { Router } from '@angular/router'; | 26 | import { Router } from '@angular/router'; |
27 | +import { DeviceProfileService } from '@core/http/device-profile.service'; | ||
28 | +import { forkJoin } from 'rxjs'; | ||
27 | 29 | ||
28 | export interface DeviceCredentialsDialogData { | 30 | export interface DeviceCredentialsDialogData { |
29 | isReadOnly: boolean; | 31 | isReadOnly: boolean; |
30 | deviceId: string; | 32 | deviceId: string; |
33 | + deviceProfileId: string; | ||
31 | } | 34 | } |
32 | 35 | ||
33 | @Component({ | 36 | @Component({ |
@@ -47,18 +50,13 @@ export class DeviceCredentialsDialogComponent extends | @@ -47,18 +50,13 @@ export class DeviceCredentialsDialogComponent extends | ||
47 | 50 | ||
48 | submitted = false; | 51 | submitted = false; |
49 | 52 | ||
50 | - deviceCredentialsType = DeviceCredentialsType; | ||
51 | - | ||
52 | - credentialsTypes = Object.keys(DeviceCredentialsType); | ||
53 | - | ||
54 | - credentialTypeNamesMap = credentialTypeNames; | ||
55 | - | ||
56 | - hidePassword = true; | 53 | + deviceTransportType: DeviceTransportType; |
57 | 54 | ||
58 | constructor(protected store: Store<AppState>, | 55 | constructor(protected store: Store<AppState>, |
59 | protected router: Router, | 56 | protected router: Router, |
60 | @Inject(MAT_DIALOG_DATA) public data: DeviceCredentialsDialogData, | 57 | @Inject(MAT_DIALOG_DATA) public data: DeviceCredentialsDialogData, |
61 | private deviceService: DeviceService, | 58 | private deviceService: DeviceService, |
59 | + private deviceProfileService: DeviceProfileService, | ||
62 | @SkipSelf() private errorStateMatcher: ErrorStateMatcher, | 60 | @SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
63 | public dialogRef: MatDialogRef<DeviceCredentialsDialogComponent, DeviceCredentials>, | 61 | public dialogRef: MatDialogRef<DeviceCredentialsDialogComponent, DeviceCredentials>, |
64 | public fb: FormBuilder) { | 62 | public fb: FormBuilder) { |
@@ -84,14 +82,16 @@ export class DeviceCredentialsDialogComponent extends | @@ -84,14 +82,16 @@ export class DeviceCredentialsDialogComponent extends | ||
84 | } | 82 | } |
85 | 83 | ||
86 | loadDeviceCredentials() { | 84 | loadDeviceCredentials() { |
87 | - this.deviceService.getDeviceCredentials(this.data.deviceId).subscribe( | ||
88 | - (deviceCredentials) => { | ||
89 | - this.deviceCredentials = deviceCredentials; | ||
90 | - this.deviceCredentialsFormGroup.patchValue({ | ||
91 | - credential: deviceCredentials | ||
92 | - }, {emitEvent: false}); | ||
93 | - } | ||
94 | - ); | 85 | + const task = []; |
86 | + task.push(this.deviceService.getDeviceCredentials(this.data.deviceId)); | ||
87 | + task.push(this.deviceProfileService.getDeviceProfileInfo(this.data.deviceProfileId)); | ||
88 | + forkJoin(task).subscribe(([deviceCredentials, deviceProfile]: [DeviceCredentials, DeviceProfileInfo]) => { | ||
89 | + this.deviceTransportType = deviceProfile.transportType; | ||
90 | + this.deviceCredentials = deviceCredentials; | ||
91 | + this.deviceCredentialsFormGroup.patchValue({ | ||
92 | + credential: deviceCredentials | ||
93 | + }, {emitEvent: false}); | ||
94 | + }); | ||
95 | } | 95 | } |
96 | 96 | ||
97 | cancel(): void { | 97 | cancel(): void { |
@@ -112,7 +112,8 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | @@ -112,7 +112,8 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | ||
112 | )); | 112 | )); |
113 | }; | 113 | }; |
114 | this.config.onEntityAction = action => this.onDeviceAction(action); | 114 | this.config.onEntityAction = action => this.onDeviceAction(action); |
115 | - this.config.detailsReadonly = () => (this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user'); | 115 | + this.config.detailsReadonly = () => |
116 | + (this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user'); | ||
116 | 117 | ||
117 | this.config.headerComponent = DeviceTableHeaderComponent; | 118 | this.config.headerComponent = DeviceTableHeaderComponent; |
118 | 119 | ||
@@ -528,6 +529,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | @@ -528,6 +529,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | ||
528 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | 529 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
529 | data: { | 530 | data: { |
530 | deviceId: device.id.id, | 531 | deviceId: device.id.id, |
532 | + deviceProfileId: device.deviceProfileId.id, | ||
531 | isReadOnly: this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user' | 533 | isReadOnly: this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user' |
532 | } | 534 | } |
533 | }).afterClosed().subscribe(deviceCredentials => { | 535 | }).afterClosed().subscribe(deviceCredentials => { |
@@ -680,6 +680,20 @@ export const credentialTypeNames = new Map<DeviceCredentialsType, string>( | @@ -680,6 +680,20 @@ export const credentialTypeNames = new Map<DeviceCredentialsType, string>( | ||
680 | ] | 680 | ] |
681 | ); | 681 | ); |
682 | 682 | ||
683 | +export const credentialTypesByTransportType = new Map<DeviceTransportType, DeviceCredentialsType[]>( | ||
684 | + [ | ||
685 | + [DeviceTransportType.DEFAULT, [ | ||
686 | + DeviceCredentialsType.ACCESS_TOKEN, DeviceCredentialsType.X509_CERTIFICATE, DeviceCredentialsType.MQTT_BASIC | ||
687 | + ]], | ||
688 | + [DeviceTransportType.MQTT, [ | ||
689 | + DeviceCredentialsType.ACCESS_TOKEN, DeviceCredentialsType.X509_CERTIFICATE, DeviceCredentialsType.MQTT_BASIC | ||
690 | + ]], | ||
691 | + [DeviceTransportType.COAP, [DeviceCredentialsType.ACCESS_TOKEN, DeviceCredentialsType.X509_CERTIFICATE]], | ||
692 | + [DeviceTransportType.LWM2M, [DeviceCredentialsType.LWM2M_CREDENTIALS]], | ||
693 | + [DeviceTransportType.SNMP, [DeviceCredentialsType.ACCESS_TOKEN, DeviceCredentialsType.X509_CERTIFICATE]] | ||
694 | + ] | ||
695 | +); | ||
696 | + | ||
683 | export interface DeviceCredentials extends BaseData<DeviceCredentialsId> { | 697 | export interface DeviceCredentials extends BaseData<DeviceCredentialsId> { |
684 | deviceId: DeviceId; | 698 | deviceId: DeviceId; |
685 | credentialsType: DeviceCredentialsType; | 699 | credentialsType: DeviceCredentialsType; |