Skip to content

Commit

Permalink
SNRGY-3619 edit device instance: enable updates to local Id
Browse files Browse the repository at this point in the history
  • Loading branch information
gr-st committed Nov 25, 2024
1 parent 233d045 commit 748cca9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit {
sortDirection: SortDirection = 'asc';

userHasDeleteAuthorization = false;
userHasUpdateAuthorization = false;
userHasReadDeviceUsageAuthorization = false;
userHasUpdateDisplayNameAuthorization = false;
userHasUpdateAttributesAuthorization = false;
Expand Down Expand Up @@ -148,6 +149,7 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit {

this.userHasUpdateDisplayNameAuthorization = this.deviceInstancesService.userHasUpdateDisplayNameAuthorization();
this.userHasUpdateAttributesAuthorization = this.deviceInstancesService.userHasUpdateAttributesAuthorization();
this.userHasUpdateAuthorization = this.deviceInstancesService.userHasUpdateAuthorization();

if (this.userHasUpdateDisplayNameAuthorization || this.userHasUpdateAttributesAuthorization) {
this.displayedColumns.push('edit');
Expand Down Expand Up @@ -308,6 +310,7 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit {
editDevice(device: DeviceInstanceModel): void {
this.deviceInstancesDialogService.openDeviceEditDialog(
device,
this.userHasUpdateAuthorization,
this.userHasUpdateDisplayNameAuthorization,
this.userHasUpdateAttributesAuthorization,
(spinnerState: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class DeviceInstancesDialogService {
});
}

openDeviceEditDialog(device: DeviceInstanceModel, userHasUpdateDisplayNameAuthorization: boolean, userHasUpdateAttributesAuthorization: boolean, setSpinnerState?: (state: boolean) => void) {
openDeviceEditDialog(device: DeviceInstanceModel, userHasUpdateAuthorization: boolean, userHasUpdateDisplayNameAuthorization: boolean, userHasUpdateAttributesAuthorization: boolean, setSpinnerState?: (state: boolean) => void) {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '50vh';
dialogConfig.disableClose = false;
Expand All @@ -145,21 +145,28 @@ export class DeviceInstancesDialogService {
concatMap((newDevice: DeviceInstanceModel) => {
let obs: Observable<any> = of(null);
// Display Name is an attribute, so if someone got attribute authorization, display name is also allowed
if (newDevice.attributes !== undefined && userHasUpdateAttributesAuthorization) {
if(setSpinnerState) {
if (newDevice !== undefined && userHasUpdateAuthorization) {
if (setSpinnerState) {
setSpinnerState(true);
}
obs = this.deviceInstancesService.updateDeviceInstanceAttributes(device.id, newDevice.attributes);
}
obs = (this.deviceInstancesService.updateDeviceInstance(newDevice));
} else {
if (newDevice !== undefined && newDevice.attributes !== undefined && userHasUpdateAttributesAuthorization) {
if (setSpinnerState) {
setSpinnerState(true);
}
obs = this.deviceInstancesService.updateDeviceInstanceAttributes(device.id, newDevice.attributes);
}

if(newDevice.display_name != null && userHasUpdateDisplayNameAuthorization && !userHasUpdateAttributesAuthorization) {
if(setSpinnerState) {
setSpinnerState(true);
if (newDevice !== undefined && newDevice.display_name != null && userHasUpdateDisplayNameAuthorization && !userHasUpdateAttributesAuthorization) {
if (setSpinnerState) {
setSpinnerState(true);
}
obs = this.deviceInstancesService.updateDeviceInstanceDisplayName(device.id, newDevice.display_name);
}
obs = this.deviceInstancesService.updateDeviceInstanceDisplayName(device.id, newDevice.display_name);
}
return obs.pipe(
map((resp: (DeviceInstanceModel | null)) => {
map((resp) => {
let errorOccured = false;
if(resp === null) {
errorOccured = true;
Expand Down

0 comments on commit 748cca9

Please sign in to comment.