2019-08-29 12:08:49 +03:00
|
|
|
///
|
2022-01-17 14:07:46 +02:00
|
|
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
2019-08-29 12:08:49 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
DateEntityTableColumn,
|
|
|
|
|
EntityTableColumn,
|
|
|
|
|
EntityTableConfig
|
|
|
|
|
} from '@home/models/entity/entities-table-config.models';
|
|
|
|
|
import { EntityType, EntityTypeResource, entityTypeTranslations } from '@shared/models/entity-type.models';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
import { DatePipe } from '@angular/common';
|
|
|
|
|
import { Direction } from '@shared/models/page/sort-order';
|
2020-02-10 13:15:29 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2019-08-29 12:08:49 +03:00
|
|
|
import { TimePageLink } from '@shared/models/page/page-link';
|
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
import { PageData } from '@shared/models/page/page-data';
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
|
|
|
|
import {
|
|
|
|
|
AlarmInfo,
|
|
|
|
|
AlarmQuery,
|
|
|
|
|
AlarmSearchStatus,
|
|
|
|
|
alarmSeverityColors,
|
|
|
|
|
alarmSeverityTranslations,
|
|
|
|
|
alarmStatusTranslations
|
|
|
|
|
} from '@app/shared/models/alarm.models';
|
|
|
|
|
import { AlarmService } from '@app/core/http/alarm.service';
|
|
|
|
|
import { DialogService } from '@core/services/dialog.service';
|
|
|
|
|
import { AlarmTableHeaderComponent } from '@home/components/alarm/alarm-table-header.component';
|
|
|
|
|
import {
|
|
|
|
|
AlarmDetailsDialogComponent,
|
|
|
|
|
AlarmDetailsDialogData
|
|
|
|
|
} from '@home/components/alarm/alarm-details-dialog.component';
|
2021-02-16 11:56:49 +02:00
|
|
|
import { DAY, historyInterval } from '@shared/models/time/time.models';
|
2022-06-21 16:05:10 +03:00
|
|
|
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';
|
2019-08-29 12:08:49 +03:00
|
|
|
|
|
|
|
|
export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink> {
|
|
|
|
|
|
2022-06-21 16:05:10 +03:00
|
|
|
private authUser = getCurrentAuthUser(this.store);
|
|
|
|
|
|
2019-08-29 12:08:49 +03:00
|
|
|
searchStatus: AlarmSearchStatus;
|
|
|
|
|
|
|
|
|
|
constructor(private alarmService: AlarmService,
|
|
|
|
|
private dialogService: DialogService,
|
|
|
|
|
private translate: TranslateService,
|
|
|
|
|
private datePipe: DatePipe,
|
|
|
|
|
private dialog: MatDialog,
|
|
|
|
|
public entityId: EntityId = null,
|
2022-06-21 16:05:10 +03:00
|
|
|
private defaultSearchStatus: AlarmSearchStatus = AlarmSearchStatus.ANY,
|
|
|
|
|
private store: Store<AppState>) {
|
2019-08-29 12:08:49 +03:00
|
|
|
super();
|
|
|
|
|
this.loadDataOnInit = false;
|
|
|
|
|
this.tableTitle = '';
|
|
|
|
|
this.useTimePageLink = true;
|
2022-01-12 17:31:30 +02:00
|
|
|
this.pageMode = false;
|
2021-02-16 11:56:49 +02:00
|
|
|
this.defaultTimewindowInterval = historyInterval(DAY * 30);
|
2019-08-29 12:08:49 +03:00
|
|
|
this.detailsPanelEnabled = false;
|
|
|
|
|
this.selectionEnabled = false;
|
|
|
|
|
this.searchEnabled = true;
|
|
|
|
|
this.addEnabled = false;
|
|
|
|
|
this.entitiesDeleteEnabled = false;
|
|
|
|
|
this.actionsColumnTitle = 'alarm.details';
|
|
|
|
|
this.entityType = EntityType.ALARM;
|
|
|
|
|
this.entityTranslations = entityTypeTranslations.get(EntityType.ALARM);
|
|
|
|
|
this.entityResources = {
|
2020-04-07 17:06:04 +03:00
|
|
|
} as EntityTypeResource<AlarmInfo>;
|
2019-08-29 12:08:49 +03:00
|
|
|
this.searchStatus = defaultSearchStatus;
|
|
|
|
|
|
|
|
|
|
this.headerComponent = AlarmTableHeaderComponent;
|
|
|
|
|
|
|
|
|
|
this.entitiesFetchFunction = pageLink => this.fetchAlarms(pageLink);
|
|
|
|
|
|
|
|
|
|
this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC};
|
|
|
|
|
|
|
|
|
|
this.columns.push(
|
|
|
|
|
new DateEntityTableColumn<AlarmInfo>('createdTime', 'alarm.created-time', this.datePipe, '150px'));
|
|
|
|
|
this.columns.push(
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<AlarmInfo>('originatorName', 'alarm.originator', '25%',
|
2019-08-29 12:08:49 +03:00
|
|
|
(entity) => entity.originatorName, entity => ({}), false));
|
|
|
|
|
this.columns.push(
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<AlarmInfo>('type', 'alarm.type', '25%'));
|
2019-08-29 12:08:49 +03:00
|
|
|
this.columns.push(
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<AlarmInfo>('severity', 'alarm.severity', '25%',
|
2019-08-29 12:08:49 +03:00
|
|
|
(entity) => this.translate.instant(alarmSeverityTranslations.get(entity.severity)),
|
|
|
|
|
entity => ({
|
|
|
|
|
fontWeight: 'bold',
|
|
|
|
|
color: alarmSeverityColors.get(entity.severity)
|
|
|
|
|
})));
|
|
|
|
|
this.columns.push(
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<AlarmInfo>('status', 'alarm.status', '25%',
|
2019-08-29 12:08:49 +03:00
|
|
|
(entity) => this.translate.instant(alarmStatusTranslations.get(entity.status))));
|
|
|
|
|
|
|
|
|
|
this.cellActionDescriptors.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('alarm.details'),
|
|
|
|
|
icon: 'more_horiz',
|
2022-06-21 16:05:10 +03:00
|
|
|
isEnabled: (entity) => this.authUser.authority !== Authority.CUSTOMER_USER || entity.customerId.id === this.authUser.customerId,
|
2019-08-29 12:08:49 +03:00
|
|
|
onAction: ($event, entity) => this.showAlarmDetails(entity)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetchAlarms(pageLink: TimePageLink): Observable<PageData<AlarmInfo>> {
|
2021-05-06 20:14:34 +03:00
|
|
|
const query = new AlarmQuery(this.entityId, pageLink, this.searchStatus, null, true);
|
2019-08-29 12:08:49 +03:00
|
|
|
return this.alarmService.getAlarms(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showAlarmDetails(entity: AlarmInfo) {
|
|
|
|
|
this.dialog.open<AlarmDetailsDialogComponent, AlarmDetailsDialogData, boolean>
|
|
|
|
|
(AlarmDetailsDialogComponent,
|
|
|
|
|
{
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
alarmId: entity.id.id,
|
|
|
|
|
allowAcknowledgment: true,
|
|
|
|
|
allowClear: true,
|
|
|
|
|
displayDetails: true
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed().subscribe(
|
|
|
|
|
(res) => {
|
|
|
|
|
if (res) {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.updateData();
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|