From 39b9db54fd10792704d543b384a789e8f3d785e7 Mon Sep 17 00:00:00 2001 From: Greta Date: Mon, 25 Nov 2024 14:54:11 +0000 Subject: [PATCH] SNRGY-3631 edit device instance: serialise edit requests --- .../shared/device-instances-dialog.service.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/modules/devices/device-instances/shared/device-instances-dialog.service.ts b/src/app/modules/devices/device-instances/shared/device-instances-dialog.service.ts index 5689ea8d..39d00fdd 100644 --- a/src/app/modules/devices/device-instances/shared/device-instances-dialog.service.ts +++ b/src/app/modules/devices/device-instances/shared/device-instances-dialog.service.ts @@ -30,7 +30,7 @@ import {DeviceInstancesEditDialogComponent} from '../dialogs/device-instances-ed import {MatSnackBar} from '@angular/material/snack-bar'; import {DeviceInstancesService} from './device-instances.service'; import {DeviceInstancesSelectDialogComponent} from '../dialogs/device-instances-select-dialog.component'; -import {forkJoin, Observable, of} from 'rxjs'; +import {concat, forkJoin, Observable, of} from 'rxjs'; import {LastValuesRequestElementTimescaleModel} from '../../../../widgets/shared/export-data.model'; import {ExportDataService} from '../../../../widgets/shared/export-data.service'; import {map, concatMap} from 'rxjs/operators'; @@ -143,34 +143,31 @@ export class DeviceInstancesDialogService { return editDialogRef.afterClosed().pipe( concatMap((newDevice: DeviceInstanceModel) => { - let obs: Observable = of(null); + const obs: Observable [] = []; // Display Name is an attribute, so if someone got attribute authorization, display name is also allowed if (newDevice !== undefined && userHasUpdateAuthorization) { if (setSpinnerState) { setSpinnerState(true); } - obs = (this.deviceInstancesService.updateDeviceInstance(newDevice)); - } else { + obs.push(this.deviceInstancesService.updateDeviceInstance(newDevice)); + }else { if (newDevice !== undefined && newDevice.attributes !== undefined && userHasUpdateAttributesAuthorization) { if (setSpinnerState) { setSpinnerState(true); } - obs = this.deviceInstancesService.updateDeviceInstanceAttributes(device.id, newDevice.attributes); + obs.push(this.deviceInstancesService.updateDeviceInstanceAttributes(device.id, newDevice.attributes)); } if (newDevice !== undefined && newDevice.display_name != null && userHasUpdateDisplayNameAuthorization && !userHasUpdateAttributesAuthorization) { if (setSpinnerState) { setSpinnerState(true); } - obs = this.deviceInstancesService.updateDeviceInstanceDisplayName(device.id, newDevice.display_name); + obs.push(this.deviceInstancesService.updateDeviceInstanceDisplayName(device.id, newDevice.display_name)); } } - return obs.pipe( + return forkJoin(obs).pipe( map((resp) => { - let errorOccured = false; - if(resp === null) { - errorOccured = true; - } + const errorOccured =resp.some(item=> item === null); if(setSpinnerState) { setSpinnerState(false);