Commit 1028273d25956e7ea08afd149446459ba86f3d3d

Authored by Vladyslav_Prykhodko
1 parent 2ce709e3

UI: Fixed processing error in device wizard: move to error step and save transport type

... ... @@ -46,7 +46,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
46 46 import { DeviceProfileDialogComponent, DeviceProfileDialogData } from './device-profile-dialog.component';
47 47 import { MatAutocomplete } from '@angular/material/autocomplete';
48 48 import { AddDeviceProfileDialogComponent, AddDeviceProfileDialogData } from './add-device-profile-dialog.component';
49   -import { emptyPageData } from "@shared/models/page/page-data";
  49 +import { emptyPageData } from '@shared/models/page/page-data';
50 50
51 51 @Component({
52 52 selector: 'tb-device-profile-autocomplete',
... ... @@ -146,7 +146,6 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor,
146 146 ngOnInit() {
147 147 this.filteredDeviceProfiles = this.selectDeviceProfileFormGroup.get('deviceProfile').valueChanges
148 148 .pipe(
149   - debounceTime(150),
150 149 tap((value: DeviceProfileInfo | string) => {
151 150 let modelValue: DeviceProfileInfo | null;
152 151 if (typeof value === 'string' || !value) {
... ... @@ -173,6 +172,7 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor,
173 172 return '';
174 173 }
175 174 }),
  175 + debounceTime(150),
176 176 distinctUntilChanged(),
177 177 switchMap(name => this.fetchDeviceProfiles(name)),
178 178 share()
... ...
... ... @@ -303,13 +303,14 @@ export class DeviceWizardDialogComponent extends
303 303 deviceProfile.defaultRuleChainId = new RuleChainId(this.deviceWizardFormGroup.get('defaultRuleChainId').value);
304 304 }
305 305 return this.deviceProfileService.saveDeviceProfile(deepTrim(deviceProfile)).pipe(
306   - map(profile => profile.id),
307   - tap((profileId) => {
  306 + tap((profile) => {
  307 + this.currentDeviceProfileTransportType = profile.transportType;
308 308 this.deviceWizardFormGroup.patchValue({
309   - deviceProfileId: profileId,
  309 + deviceProfileId: profile.id,
310 310 addProfileType: 0
311 311 });
312   - })
  312 + }),
  313 + map(profile => profile.id)
313 314 );
314 315 } else {
315 316 return of(this.deviceWizardFormGroup.get('deviceProfileId').value);
... ... @@ -334,7 +335,12 @@ export class DeviceWizardDialogComponent extends
334 335 id: this.customerFormGroup.get('customerId').value
335 336 };
336 337 }
337   - return this.data.entitiesTableConfig.saveEntity(deepTrim(device));
  338 + return this.data.entitiesTableConfig.saveEntity(deepTrim(device)).pipe(
  339 + catchError(e => {
  340 + this.addDeviceWizardStepper.selectedIndex = 0;
  341 + return throwError(e);
  342 + })
  343 + );
338 344 }
339 345
340 346 private saveCredentials(device: BaseData<HasId>): Observable<boolean> {
... ... @@ -345,6 +351,7 @@ export class DeviceWizardDialogComponent extends
345 351 const deviceCredentialsValue = {...deviceCredentials, ...this.credentialsFormGroup.value.credential};
346 352 return this.deviceService.saveDeviceCredentials(deviceCredentialsValue).pipe(
347 353 catchError(e => {
  354 + this.addDeviceWizardStepper.selectedIndex = 1;
348 355 return this.deviceService.deleteDevice(device.id.id).pipe(
349 356 mergeMap(() => {
350 357 return throwError(e);
... ...