Commit 3cf97e0a4f811e99240a545c9777b78015a4e96e

Authored by Vladyslav_Prykhodko
1 parent 8b70cbdb

UI: Init models for transport type switch

... ... @@ -31,7 +31,8 @@ import {
31 31 credentialTypeNames,
32 32 DeviceCredentialMQTTBasic,
33 33 DeviceCredentials,
34   - DeviceCredentialsType
  34 + DeviceCredentialsType,
  35 + DeviceTransportType
35 36 } from '@shared/models/device.models';
36 37 import { Subject } from 'rxjs';
37 38 import { takeUntil } from 'rxjs/operators';
... ... @@ -58,6 +59,9 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
58 59 @Input()
59 60 disabled: boolean;
60 61
  62 + @Input()
  63 + deviceTransportType = DeviceTransportType.DEFAULT;
  64 +
61 65 private destroy$ = new Subject();
62 66
63 67 deviceCredentialsFormGroup: FormGroup;
... ...
... ... @@ -31,6 +31,7 @@
31 31 <div mat-dialog-content>
32 32 <fieldset [disabled]="(isLoading$ | async) || isReadOnly">
33 33 <tb-device-credentials
  34 + [deviceTransportType]="deviceTransportType"
34 35 formControlName="credential">
35 36 </tb-device-credentials>
36 37 </fieldset>
... ...
... ... @@ -21,13 +21,16 @@ import { Store } from '@ngrx/store';
21 21 import { AppState } from '@core/core.state';
22 22 import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms';
23 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 25 import { DialogComponent } from '@shared/components/dialog.component';
26 26 import { Router } from '@angular/router';
  27 +import { DeviceProfileService } from '@core/http/device-profile.service';
  28 +import { forkJoin } from 'rxjs';
27 29
28 30 export interface DeviceCredentialsDialogData {
29 31 isReadOnly: boolean;
30 32 deviceId: string;
  33 + deviceProfileId: string;
31 34 }
32 35
33 36 @Component({
... ... @@ -47,18 +50,13 @@ export class DeviceCredentialsDialogComponent extends
47 50
48 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 55 constructor(protected store: Store<AppState>,
59 56 protected router: Router,
60 57 @Inject(MAT_DIALOG_DATA) public data: DeviceCredentialsDialogData,
61 58 private deviceService: DeviceService,
  59 + private deviceProfileService: DeviceProfileService,
62 60 @SkipSelf() private errorStateMatcher: ErrorStateMatcher,
63 61 public dialogRef: MatDialogRef<DeviceCredentialsDialogComponent, DeviceCredentials>,
64 62 public fb: FormBuilder) {
... ... @@ -84,14 +82,16 @@ export class DeviceCredentialsDialogComponent extends
84 82 }
85 83
86 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 97 cancel(): void {
... ...
... ... @@ -112,7 +112,8 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
112 112 ));
113 113 };
114 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 118 this.config.headerComponent = DeviceTableHeaderComponent;
118 119
... ... @@ -528,6 +529,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
528 529 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
529 530 data: {
530 531 deviceId: device.id.id,
  532 + deviceProfileId: device.deviceProfileId.id,
531 533 isReadOnly: this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user'
532 534 }
533 535 }).afterClosed().subscribe(deviceCredentials => {
... ...
... ... @@ -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 697 export interface DeviceCredentials extends BaseData<DeviceCredentialsId> {
684 698 deviceId: DeviceId;
685 699 credentialsType: DeviceCredentialsType;
... ...