Commit 34453f26687180ccd1fcd83ca2a0e29e6a54a57b

Authored by Vladyslav Prykhodko
1 parent 3cf97e0a

UI: Device credential add processing deviceTransportType

@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 16
17 --> 17 -->
18 <section [formGroup]="deviceCredentialsFormGroup"> 18 <section [formGroup]="deviceCredentialsFormGroup">
19 - <mat-form-field class="mat-block"> 19 + <mat-form-field class="mat-block" [fxShow]="credentialsTypes?.length > 1">
20 <mat-label translate>device.credentials-type</mat-label> 20 <mat-label translate>device.credentials-type</mat-label>
21 <mat-select formControlName="credentialsType"> 21 <mat-select formControlName="credentialsType">
22 <mat-option *ngFor="let credentialsType of credentialsTypes" [value]="credentialsType"> 22 <mat-option *ngFor="let credentialsType of credentialsTypes" [value]="credentialsType">
@@ -29,6 +29,7 @@ import { @@ -29,6 +29,7 @@ import {
29 } from '@angular/forms'; 29 } from '@angular/forms';
30 import { 30 import {
31 credentialTypeNames, 31 credentialTypeNames,
  32 + credentialTypesByTransportType,
32 DeviceCredentialMQTTBasic, 33 DeviceCredentialMQTTBasic,
33 DeviceCredentials, 34 DeviceCredentials,
34 DeviceCredentialsType, 35 DeviceCredentialsType,
@@ -59,8 +60,21 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, @@ -59,8 +60,21 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
59 @Input() 60 @Input()
60 disabled: boolean; 61 disabled: boolean;
61 62
  63 + private deviceTransportTypeValue = DeviceTransportType.DEFAULT;
  64 + get deviceTransportType(): DeviceTransportType {
  65 + return this.deviceTransportTypeValue
  66 + }
62 @Input() 67 @Input()
63 - deviceTransportType = DeviceTransportType.DEFAULT; 68 + set deviceTransportType(type: DeviceTransportType) {
  69 + if (type) {
  70 + this.deviceTransportTypeValue = type;
  71 + this.credentialsTypes = credentialTypesByTransportType.get(type);
  72 + const currentType = this.deviceCredentialsFormGroup.get('credentialsType').value;
  73 + if (!this.credentialsTypes.includes(currentType)) {
  74 + this.deviceCredentialsFormGroup.get('credentialsType').patchValue(this.credentialsTypes[0], {onlySelf: true});
  75 + }
  76 + }
  77 + }
64 78
65 private destroy$ = new Subject(); 79 private destroy$ = new Subject();
66 80
@@ -68,7 +82,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, @@ -68,7 +82,7 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit,
68 82
69 deviceCredentialsType = DeviceCredentialsType; 83 deviceCredentialsType = DeviceCredentialsType;
70 84
71 - credentialsTypes = Object.values(DeviceCredentialsType); 85 + credentialsTypes = credentialTypesByTransportType.get(DeviceTransportType.DEFAULT);
72 86
73 credentialTypeNamesMap = credentialTypeNames; 87 credentialTypeNamesMap = credentialTypeNames;
74 88
@@ -64,7 +64,8 @@ @@ -64,7 +64,8 @@
64 [ngClass]="{invisible: deviceWizardFormGroup.get('addProfileType').value !== 0}" 64 [ngClass]="{invisible: deviceWizardFormGroup.get('addProfileType').value !== 0}"
65 [addNewProfile]="false" 65 [addNewProfile]="false"
66 [selectDefaultProfile]="true" 66 [selectDefaultProfile]="true"
67 - [editProfileEnabled]="false"> 67 + [editProfileEnabled]="false"
  68 + (deviceProfileChanged)="deviceProfileChanged($event)">
68 </tb-device-profile-autocomplete> 69 </tb-device-profile-autocomplete>
69 <mat-form-field fxFlex class="mat-block" 70 <mat-form-field fxFlex class="mat-block"
70 [ngClass]="{invisible: deviceWizardFormGroup.get('addProfileType').value !== 1}"> 71 [ngClass]="{invisible: deviceWizardFormGroup.get('addProfileType').value !== 1}">
@@ -154,6 +155,7 @@ @@ -154,6 +155,7 @@
154 <mat-checkbox style="padding-bottom: 16px;" formControlName="setCredential">{{ 'device.wizard.add-credentials' | translate }}</mat-checkbox> 155 <mat-checkbox style="padding-bottom: 16px;" formControlName="setCredential">{{ 'device.wizard.add-credentials' | translate }}</mat-checkbox>
155 <tb-device-credentials 156 <tb-device-credentials
156 [fxShow]="credentialsFormGroup.get('setCredential').value" 157 [fxShow]="credentialsFormGroup.get('setCredential').value"
  158 + [deviceTransportType]="deviceTransportType"
157 formControlName="credential"> 159 formControlName="credential">
158 </tb-device-credentials> 160 </tb-device-credentials>
159 </form> 161 </form>
@@ -25,6 +25,7 @@ import { @@ -25,6 +25,7 @@ import {
25 createDeviceProfileConfiguration, 25 createDeviceProfileConfiguration,
26 createDeviceProfileTransportConfiguration, 26 createDeviceProfileTransportConfiguration,
27 DeviceProfile, 27 DeviceProfile,
  28 + DeviceProfileInfo,
28 DeviceProfileType, 29 DeviceProfileType,
29 DeviceProvisionConfiguration, 30 DeviceProvisionConfiguration,
30 DeviceProvisionType, 31 DeviceProvisionType,
@@ -91,6 +92,7 @@ export class DeviceWizardDialogComponent extends @@ -91,6 +92,7 @@ export class DeviceWizardDialogComponent extends
91 serviceType = ServiceType.TB_RULE_ENGINE; 92 serviceType = ServiceType.TB_RULE_ENGINE;
92 93
93 private subscriptions: Subscription[] = []; 94 private subscriptions: Subscription[] = [];
  95 + private currentDeviceProfileTransportType = DeviceTransportType.DEFAULT;
94 96
95 constructor(protected store: Store<AppState>, 97 constructor(protected store: Store<AppState>,
96 protected router: Router, 98 protected router: Router,
@@ -265,6 +267,20 @@ export class DeviceWizardDialogComponent extends @@ -265,6 +267,20 @@ export class DeviceWizardDialogComponent extends
265 } 267 }
266 } 268 }
267 269
  270 + get deviceTransportType(): DeviceTransportType {
  271 + if (this.deviceWizardFormGroup.get('addProfileType').value) {
  272 + return this.transportConfigFormGroup.get('transportType').value;
  273 + } else {
  274 + return this.currentDeviceProfileTransportType;
  275 + }
  276 + }
  277 +
  278 + deviceProfileChanged(deviceProfile: DeviceProfileInfo) {
  279 + if (deviceProfile) {
  280 + this.currentDeviceProfileTransportType = deviceProfile.transportType;
  281 + }
  282 + }
  283 +
268 private createDeviceProfile(): Observable<EntityId> { 284 private createDeviceProfile(): Observable<EntityId> {
269 if (this.deviceWizardFormGroup.get('addProfileType').value) { 285 if (this.deviceWizardFormGroup.get('addProfileType').value) {
270 const deviceProvisionConfiguration: DeviceProvisionConfiguration = this.provisionConfigFormGroup.get('provisionConfiguration').value; 286 const deviceProvisionConfiguration: DeviceProvisionConfiguration = this.provisionConfigFormGroup.get('provisionConfiguration').value;
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 --> 17 -->
18 <form [formGroup]="deviceCredentialsFormGroup" (ngSubmit)="save()" style="min-width: 350px;"> 18 <form [formGroup]="deviceCredentialsFormGroup" (ngSubmit)="save()" style="min-width: 350px;">
19 <mat-toolbar color="primary"> 19 <mat-toolbar color="primary">
20 - <h2 translate>device.device-credentials</h2> 20 + <h2>{{ 'device.device-credentials' | translate }}</h2>
21 <span fxFlex></span> 21 <span fxFlex></span>
22 <button mat-icon-button 22 <button mat-icon-button
23 (click)="cancel()" 23 (click)="cancel()"