Skip to content

Commit

Permalink
show device updates in list directly after editing; fix #SNRGY-3137
Browse files Browse the repository at this point in the history
  • Loading branch information
hahahannes committed Feb 26, 2024
1 parent 1bb17fa commit 44c8009
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class DeviceInstancesEditDialogComponent implements OnInit {
origin: this.nicknameAttributeOrigin,
value: this.displayname
} as Attribute);
this.device.display_name = this.displayname;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -129,7 +129,7 @@ export class DeviceInstancesDialogService {
});
}

openDeviceEditDialog(device: DeviceInstancesModel): void {
openDeviceEditDialog(device: DeviceInstancesModel) {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.data = {
Expand All @@ -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 {
Expand Down

0 comments on commit 44c8009

Please sign in to comment.