From 44c8009cdd6242d504d837db3035961b91a2f00e Mon Sep 17 00:00:00 2001 From: Hannes Hansen Date: Mon, 26 Feb 2024 12:03:54 +0100 Subject: [PATCH] show device updates in list directly after editing; fix #SNRGY-3137 --- .../device-instances.component.ts | 10 ++++- .../device-instances-edit-dialog.component.ts | 1 + .../shared/device-instances-dialog.service.ts | 41 +++++++++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/app/modules/devices/device-instances/device-instances.component.ts b/src/app/modules/devices/device-instances/device-instances.component.ts index c6e3d415..a9761cad 100644 --- a/src/app/modules/devices/device-instances/device-instances.component.ts +++ b/src/app/modules/devices/device-instances/device-instances.component.ts @@ -307,7 +307,15 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit { } editDevice(device: DeviceInstancesModel): void { - this.deviceInstancesDialogService.openDeviceEditDialog(device); + this.deviceInstancesDialogService.openDeviceEditDialog(device).subscribe({ + next: (newDevice) => { + if(newDevice != null) { + const index = this.dataSource.data.findIndex(element => element.id === device.id); + this.dataSource.data[index] = newDevice; + this.dataSource.data = this.dataSource.data; + } + } + }); } duplicateDevice(device: DeviceInstancesModel): void { diff --git a/src/app/modules/devices/device-instances/dialogs/device-instances-edit-dialog.component.ts b/src/app/modules/devices/device-instances/dialogs/device-instances-edit-dialog.component.ts index bfc413c9..9bd116a8 100644 --- a/src/app/modules/devices/device-instances/dialogs/device-instances-edit-dialog.component.ts +++ b/src/app/modules/devices/device-instances/dialogs/device-instances-edit-dialog.component.ts @@ -111,6 +111,7 @@ export class DeviceInstancesEditDialogComponent implements OnInit { origin: this.nicknameAttributeOrigin, value: this.displayname } as Attribute); + this.device.display_name = this.displayname; } } 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 6859fa09..00c8a80c 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 @@ -32,11 +32,11 @@ import {DeviceTypePermSearchModel} from '../../../metadata/device-types-overview import {MatSnackBar} from '@angular/material/snack-bar'; import {DeviceInstancesService} from './device-instances.service'; import {DeviceInstancesSelectDialogComponent} from '../dialogs/device-instances-select-dialog.component'; -import {forkJoin, mergeMap, Observable} from 'rxjs'; +import {forkJoin, mergeMap, Observable, of} from 'rxjs'; import {LastValuesRequestElementTimescaleModel, TimeValuePairModel} from '../../../../widgets/shared/export-data.model'; import {ExportDataService} from '../../../../widgets/shared/export-data.service'; import {environment} from '../../../../../environments/environment'; -import {catchError, map} from 'rxjs/operators'; +import {catchError, map, concatMap} from 'rxjs/operators'; @Injectable({ providedIn: 'root', @@ -129,7 +129,7 @@ export class DeviceInstancesDialogService { }); } - openDeviceEditDialog(device: DeviceInstancesModel): void { + openDeviceEditDialog(device: DeviceInstancesModel) { const dialogConfig = new MatDialogConfig(); dialogConfig.disableClose = false; dialogConfig.data = { @@ -138,20 +138,27 @@ export class DeviceInstancesDialogService { const editDialogRef = this.dialog.open(DeviceInstancesEditDialogComponent, dialogConfig); - editDialogRef.afterClosed().subscribe((deviceOut: DeviceInstancesModel) => { - if (deviceOut !== undefined) { - this.deviceInstancesService - .updateDeviceInstance(this.convertDeviceInstance(deviceOut)) - .subscribe((deviceResp: DeviceInstancesUpdateModel | null) => { - if (deviceResp === null) { - this.snackBar.open('Error while updating the device instance!', 'close', { panelClass: 'snack-bar-error' }); - } else { - Object.assign(device, deviceOut); - this.snackBar.open('Device instance updated successfully.', undefined, {duration: 2000}); - } - }); - } - }); + return editDialogRef.afterClosed().pipe( + concatMap((deviceOut: DeviceInstancesModel) => { + if (deviceOut !== undefined) { + return this.deviceInstancesService + .updateDeviceInstance(this.convertDeviceInstance(deviceOut)) + .pipe( + map((deviceResp: DeviceInstancesUpdateModel | null) => { + if (deviceResp === null) { + this.snackBar.open('Error while updating the device instance!', 'close', { panelClass: 'snack-bar-error' }); + } else { + Object.assign(device, deviceOut); + this.snackBar.open('Device instance updated successfully.', undefined, {duration: 2000}); + return deviceOut; + } + return null; + }) + ); + } + return of(null); + }) + ); } openDeviceCreateDialog(deviceType?: DeviceTypePermSearchModel, device?: DeviceInstancesModel): void {