Merge pull request #6775 from vvlladd28/improvement/alarm-details/show-permision
[3.4] UI: Fixed permission check in show alarm details
This commit is contained in:
commit
fc90105efb
@ -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<AlarmDetailsDialogComponent, boolean> implements OnInit {
|
||||
|
||||
alarmId: string;
|
||||
alarmFormGroup: FormGroup;
|
||||
|
||||
allowAcknowledgment: boolean;
|
||||
@ -93,12 +95,17 @@ export class AlarmDetailsDialogComponent extends DialogComponent<AlarmDetailsDia
|
||||
}
|
||||
);
|
||||
|
||||
this.loadAlarm();
|
||||
|
||||
if (!this.data.alarm) {
|
||||
this.alarmId = this.data.alarmId;
|
||||
this.loadAlarm();
|
||||
} else {
|
||||
this.alarmId = this.data.alarm?.id?.id;
|
||||
this.loadAlarmSubject.next(this.data.alarm);
|
||||
}
|
||||
}
|
||||
|
||||
loadAlarm() {
|
||||
this.alarmService.getAlarmInfo(this.data.alarmId).subscribe(
|
||||
this.alarmService.getAlarmInfo(this.alarmId).subscribe(
|
||||
alarm => this.loadAlarmSubject.next(alarm)
|
||||
);
|
||||
}
|
||||
@ -140,15 +147,25 @@ export class AlarmDetailsDialogComponent extends DialogComponent<AlarmDetailsDia
|
||||
}
|
||||
|
||||
acknowledge(): void {
|
||||
this.alarmService.ackAlarm(this.data.alarmId).subscribe(
|
||||
() => { 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();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<AlarmInfo, TimePageLink> {
|
||||
|
||||
private authUser = getCurrentAuthUser(this.store);
|
||||
|
||||
searchStatus: AlarmSearchStatus;
|
||||
|
||||
constructor(private alarmService: AlarmService,
|
||||
@ -55,7 +61,8 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
|
||||
private datePipe: DatePipe,
|
||||
private dialog: MatDialog,
|
||||
public entityId: EntityId = null,
|
||||
private defaultSearchStatus: AlarmSearchStatus = AlarmSearchStatus.ANY) {
|
||||
private defaultSearchStatus: AlarmSearchStatus = AlarmSearchStatus.ANY,
|
||||
private store: Store<AppState>) {
|
||||
super();
|
||||
this.loadDataOnInit = false;
|
||||
this.tableTitle = '';
|
||||
@ -114,6 +121,7 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
|
||||
}
|
||||
|
||||
showAlarmDetails(entity: AlarmInfo) {
|
||||
const isPermissionWrite = this.authUser.authority !== Authority.CUSTOMER_USER || entity.customerId.id === this.authUser.customerId;
|
||||
this.dialog.open<AlarmDetailsDialogComponent, AlarmDetailsDialogData, boolean>
|
||||
(AlarmDetailsDialogComponent,
|
||||
{
|
||||
@ -121,8 +129,9 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
|
||||
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(
|
||||
|
||||
@ -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<AppState>) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@ -80,7 +83,8 @@ export class AlarmTableComponent implements OnInit {
|
||||
this.datePipe,
|
||||
this.dialog,
|
||||
this.entityIdValue,
|
||||
AlarmSearchStatus.ANY
|
||||
AlarmSearchStatus.ANY,
|
||||
this.store
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user