Skip to content

Commit

Permalink
SNRGY-3631 edit device instance: serialise edit requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gr-st committed Nov 25, 2024
1 parent 2328a40 commit 39b9db5
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -143,34 +143,31 @@ export class DeviceInstancesDialogService {

return editDialogRef.afterClosed().pipe(
concatMap((newDevice: DeviceInstanceModel) => {
let obs: Observable<any> = of(null);
const obs: Observable<any> [] = [];
// 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);
Expand Down

0 comments on commit 39b9db5

Please sign in to comment.