Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
alert.component.ts 3.96 KiB
Newer Older
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
import {
  AfterViewChecked,
  AfterViewInit,
  ChangeDetectorRef,
  Component,
  OnInit,
  TemplateRef,
  ViewChild
} from '@angular/core';
import {ColumnPicker} from '../common/column-picker/column-picker.model';
import {MatDialog} from '@angular/material/dialog';

import {AlertMessageService} from '../common/alert-message/alert-message.service';
import {AlertController} from './alert-controller';
import {HttpClient} from '@angular/common/http';
import {SmpConstants} from "../smp.constants";
import {GlobalLookups} from "../common/global-lookups";
import {SearchTableComponent} from "../common/search-table/search-table.component";
import {SecurityService} from "../security/security.service";
import {ObjectPropertiesDialogComponent} from "../common/dialogs/object-properties-dialog/object-properties-dialog.component";
@Component({
  templateUrl: './alert.component.html',
  styleUrls: ['./alert.component.css']
})
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
export class AlertComponent implements OnInit, AfterViewInit, AfterViewChecked {

  @ViewChild('rowMetadataAction') rowMetadataAction: TemplateRef<any>;
  @ViewChild('rowActions') rowActions: TemplateRef<any>;
  @ViewChild('searchTable') searchTable: SearchTableComponent;
  @ViewChild('dateTimeColumn') dateTimeColumn: TemplateRef<any>;
  @ViewChild('truncateText') truncateText: TemplateRef<any>;
  @ViewChild('credentialType') credentialType: TemplateRef<any>;
  @ViewChild('forUser') forUser: TemplateRef<any>;
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
  readonly dateTimeFormat: string = SmpConstants.DATE_TIME_FORMAT;
  readonly dateFormat: string = SmpConstants.DATE_FORMAT;

  baseUrl = SmpConstants.REST_INTERNAL_ALERT_MANAGE;
  columnPicker: ColumnPicker = new ColumnPicker();
  alertController: AlertController;
  filter: any = {};
  isSMPIntegrationOn: boolean = false;

  constructor(public securityService: SecurityService,
              protected lookups: GlobalLookups,
              protected http: HttpClient,
              protected alertService: AlertMessageService,
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
              public dialog: MatDialog,
              private changeDetector: ChangeDetectorRef) {
    this.alertController = new AlertController(this.http, this.lookups, this.dialog);
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
  }

  ngAfterViewChecked() {
    this.changeDetector.detectChanges();
  }
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
  initColumns() {
    this.columnPicker.allColumns = [
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
      {
        name: 'Alert date',
        title: "Alert date",
        prop: 'reportingTime',
        showInitially: true,
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        cellTemplate: this.dateTimeColumn,
      },
      {
        name: 'For User',
        title: "For User",
        prop: 'username',
        cellTemplate: this.forUser,
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        showInitially: true,
      },
      {
        name: 'Credential type',
        title: "Credential type.",
        prop: 'alertDetails',
        cellTemplate: this.credentialType,
        showInitially: true,
      },
      {
        name: 'Alert type',
        title: "Alert type.",
        prop: 'alertType',
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        cellTemplate: this.truncateText,
        showInitially: true,
      },
      {
        name: 'Alert status',
        title: "Alert status.",
        prop: 'alertStatus',
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        showInitially: true,
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
      },
      {
        name: 'Status desc.',
        title: "Status desc.",
        prop: 'alertStatusDesc',
        cellTemplate: this.truncateText,
        showInitially: true,

      },
      {
        name: 'Alert level',
        title: "Alert level.",
        prop: 'alertLevel',
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        showInitially: true,
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
    this.columnPicker.selectedColumns = this.columnPicker.allColumns.filter(col => col.showInitially);
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
    this.searchTable.tableColumnInit();
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
    this.initColumns();
  details(row: any) {
    this.dialog.open(ObjectPropertiesDialogComponent, {
      data: {
Joze RIHTARSIC's avatar
Joze RIHTARSIC committed
        title: "Alert details",
  // for dirty guard...
  isDirty(): boolean {
    return this.searchTable.isDirty();