From a2422dab00595b1beb7dc7d6a7f5fc151ec0b23f Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 21 Jun 2022 16:05:10 +0300 Subject: [PATCH 1/2] UI: Fixed permission check in show alarm details --- .../home/components/alarm/alarm-table-config.ts | 11 +++++++++-- .../home/components/alarm/alarm-table.component.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts index d35f82daf8..f9b0502d2d 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts @@ -44,9 +44,15 @@ import { AlarmDetailsDialogData } from '@home/components/alarm/alarm-details-dialog.component'; import { DAY, historyInterval } from '@shared/models/time/time.models'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; +import { Authority } from '@shared/models/authority.enum'; export class AlarmTableConfig extends EntityTableConfig { + private authUser = getCurrentAuthUser(this.store); + searchStatus: AlarmSearchStatus; constructor(private alarmService: AlarmService, @@ -55,7 +61,8 @@ export class AlarmTableConfig extends EntityTableConfig private datePipe: DatePipe, private dialog: MatDialog, public entityId: EntityId = null, - private defaultSearchStatus: AlarmSearchStatus = AlarmSearchStatus.ANY) { + private defaultSearchStatus: AlarmSearchStatus = AlarmSearchStatus.ANY, + private store: Store) { super(); this.loadDataOnInit = false; this.tableTitle = ''; @@ -102,7 +109,7 @@ export class AlarmTableConfig extends EntityTableConfig { name: this.translate.instant('alarm.details'), icon: 'more_horiz', - isEnabled: () => true, + isEnabled: (entity) => this.authUser.authority !== Authority.CUSTOMER_USER || entity.customerId.id === this.authUser.customerId, onAction: ($event, entity) => this.showAlarmDetails(entity) } ); diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-table.component.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-table.component.ts index cf8c66c93a..d642bcef7a 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-table.component.ts @@ -24,6 +24,8 @@ import { DialogService } from '@core/services/dialog.service'; import { AlarmTableConfig } from './alarm-table-config'; import { AlarmSearchStatus } from '@shared/models/alarm.models'; import { AlarmService } from '@app/core/http/alarm.service'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; @Component({ selector: 'tb-alarm-table', @@ -68,7 +70,8 @@ export class AlarmTableComponent implements OnInit { private dialogService: DialogService, private translate: TranslateService, private datePipe: DatePipe, - private dialog: MatDialog) { + private dialog: MatDialog, + private store: Store) { } ngOnInit() { @@ -80,7 +83,8 @@ export class AlarmTableComponent implements OnInit { this.datePipe, this.dialog, this.entityIdValue, - AlarmSearchStatus.ANY + AlarmSearchStatus.ANY, + this.store ); } From d05712d3e2973cadd0faed6c5004674af5bbb128 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 21 Jun 2022 17:14:03 +0300 Subject: [PATCH 2/2] UI: Improvement alarm details dialog --- .../alarm/alarm-details-dialog.component.ts | 37 ++++++++++++++----- .../components/alarm/alarm-table-config.ts | 8 ++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-details-dialog.component.ts index dc88580177..be3aff8c50 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-details-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-details-dialog.component.ts @@ -35,7 +35,8 @@ import { DatePipe } from '@angular/common'; import { TranslateService } from '@ngx-translate/core'; export interface AlarmDetailsDialogData { - alarmId: string; + alarmId?: string; + alarm?: AlarmInfo; allowAcknowledgment: boolean; allowClear: boolean; displayDetails: boolean; @@ -48,6 +49,7 @@ export interface AlarmDetailsDialogData { }) export class AlarmDetailsDialogComponent extends DialogComponent implements OnInit { + alarmId: string; alarmFormGroup: FormGroup; allowAcknowledgment: boolean; @@ -93,12 +95,17 @@ export class AlarmDetailsDialogComponent extends DialogComponent this.loadAlarmSubject.next(alarm) ); } @@ -140,15 +147,25 @@ export class AlarmDetailsDialogComponent extends DialogComponent { this.alarmUpdated = true; this.loadAlarm(); } - ); + if (this.alarmId) { + this.alarmService.ackAlarm(this.alarmId).subscribe( + () => { + this.alarmUpdated = true; + this.loadAlarm(); + } + ); + } } clear(): void { - this.alarmService.clearAlarm(this.data.alarmId).subscribe( - () => { this.alarmUpdated = true; this.loadAlarm(); } - ); + if (this.alarmId) { + this.alarmService.clearAlarm(this.alarmId).subscribe( + () => { + this.alarmUpdated = true; + this.loadAlarm(); + } + ); + } } } diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts index f9b0502d2d..6cc51857e7 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts @@ -109,7 +109,7 @@ export class AlarmTableConfig extends EntityTableConfig { name: this.translate.instant('alarm.details'), icon: 'more_horiz', - isEnabled: (entity) => this.authUser.authority !== Authority.CUSTOMER_USER || entity.customerId.id === this.authUser.customerId, + isEnabled: () => true, onAction: ($event, entity) => this.showAlarmDetails(entity) } ); @@ -121,6 +121,7 @@ export class AlarmTableConfig extends EntityTableConfig } showAlarmDetails(entity: AlarmInfo) { + const isPermissionWrite = this.authUser.authority !== Authority.CUSTOMER_USER || entity.customerId.id === this.authUser.customerId; this.dialog.open (AlarmDetailsDialogComponent, { @@ -128,8 +129,9 @@ export class AlarmTableConfig extends EntityTableConfig panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], data: { alarmId: entity.id.id, - allowAcknowledgment: true, - allowClear: true, + alarm: entity, + allowAcknowledgment: isPermissionWrite, + allowClear: isPermissionWrite, displayDetails: true } }).afterClosed().subscribe(