Commit 34453f26687180ccd1fcd83ca2a0e29e6a54a57b

Authored by Vladyslav Prykhodko
1 parent 3cf97e0a

UI: Device credential add processing deviceTransportType

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