File

src/app/audit/audit-record/audit-record.component.ts

Description

Main entry point to the Apps Module. Provides a paginated list of AppRegistrations and also provides operations to unregister AppRegistrations, displays versions control if skipper is enabled.

Implements

OnInit OnDestroy

Example

Metadata

selector app-audit-record
templateUrl ./audit-record.component.html

Index

Properties
Methods
Accessors

Constructor

constructor(auditRecordService: AuditRecordService, notificationService: NotificationService, loggerService: LoggerService, router: Router)

Constructor

Parameters :
Name Type Optional Description
auditRecordService AuditRecordService
notificationService NotificationService
loggerService LoggerService
router Router

Methods

applyAction
applyAction(action: string, args?: any)

Apply Action

Parameters :
Name Type Optional Description
action string
args any true
Returns : void
applySort
applySort(sort: SortParams)

Apply sort Triggered on column header click

Parameters :
Name Type Optional Description
sort SortParams
Returns : void
auditActions
auditActions(index: number)

Return a list of action for an audit record

Parameters :
Name Type Optional Description
index number
Returns : {}
changePaginationPager
changePaginationPager(params: )

Update event from the Paginator Pager

Parameters :
Name Type Optional Description
params
Returns : void
getDateRange
getDateRange()

Get Date Range formatted

Returns : string
loadAuditRecords
loadAuditRecords()

Load a paginated list of AuditRecords. Build the form checkboxes (persist selection)

Returns : void
ngOnDestroy
ngOnDestroy()

On Destroy operations

Returns : void
ngOnInit
ngOnInit()

As soon as the page loads we retrieve a list of AppRegistrations after init the context.

Returns : void
refresh
refresh()

Refresh the page Work around: invalidate the cache applications

Returns : void
search
search(value: AuditRecordListParams)

Run the search

Parameters :
Name Type Optional Description
value AuditRecordListParams
Returns : void
updateContext
updateContext()

Write the context in the service.

Returns : void
viewDetails
viewDetails(auditRecord: AuditRecord)

Navigate to the page that provides a detail view for the passed-in AuditRecord.

Parameters :
Name Type Optional Description
auditRecord AuditRecord
Returns : void

Properties

auditRecords
auditRecords: Page<AuditRecord>
Type : Page<AuditRecord>

Current AuditRecord items

Public auditRecordService
auditRecordService: AuditRecordService
Type : AuditRecordService
context
context: any
Type : any

Storage context

itemsSelected
itemsSelected: Array<string>
Type : Array<string>

Contain a key application of each selected application

listBar
listBar: AuditRecordListBarComponent
Type : AuditRecordListBarComponent
Decorators : ViewChild

List Bar Component

Private ngUnsubscribe$
ngUnsubscribe$: Subject<any>
Type : Subject<any>

Unsubscribe

params
params: AuditRecordListParams
Type : AuditRecordListParams

State of App List Params

Accessors

operationTypes
getoperationTypes()

Returns all supported AuditOperationTypes.

Returns : Subject<[]>
actionTypes
getactionTypes()

Returns all supported AuditActionTypes.

Returns : Subject<[]>
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { SortParams } from '../../shared/components/shared.interface';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { AppError } from '../../shared/model/error.model';
import { AuditRecord, AuditOperationType, AuditActionType } from '../../shared/model/audit-record.model';
import { AuditRecordService } from '../audit-record.service';
import { Page } from '../../shared/model';
import { AuditRecordListParams } from '../components/audit.interface';
import { AuditRecordListBarComponent } from '../components/audit-record-list-bar/audit-record-list-bar.component';

/**
 * Main entry point to the Apps Module. Provides
 * a paginated list of {@link AppRegistration}s and
 * also provides operations to unregister {@link AppRegistration}s,
 * displays versions control if skipper is enabled.
 *
 * @author Gunnar Hillert
 */
@Component({
  selector: 'app-audit-record',
  templateUrl: './audit-record.component.html'
})
export class AuditRecordComponent implements OnInit, OnDestroy {

  /**
   * Current AuditRecord items
   */
  auditRecords: Page<AuditRecord>;

  /**
   * Unsubscribe
   */
  private ngUnsubscribe$: Subject<any> = new Subject();

  /**
   * State of App List Params
   * @type {SortParams}
   */
  params: AuditRecordListParams = null;

  /**
   * Contain a key application of each selected application
   * @type {Array}
   */
  itemsSelected: Array<string> = [];

  /**
   * Storage context
   */
  context: any;

  /**
   * List Bar Component
   */
  @ViewChild('listBar', { static: true })
  listBar: AuditRecordListBarComponent;

  /**
   * Constructor
   *
   * @param {AuditRecordService} auditRecordService
   * @param {NotificationService} notificationService
   * @param {LoggerService} loggerService
   * @param {Router} router
   */
  constructor(public auditRecordService: AuditRecordService,
              private notificationService: NotificationService,
              private loggerService: LoggerService,
              private router: Router) {
  }

  /**
   * As soon as the page loads we retrieve a list of {@link AppRegistration}s
   * after init the context.
   */
  ngOnInit() {
    this.context = this.auditRecordService.auditContext;
    this.params = { ...this.context };
    this.loadAuditRecords();
    this.itemsSelected = this.context.itemsSelected || [];
    this.auditRecordService.loadAuditActionTypes().subscribe();
    this.auditRecordService.loadAuditOperationTypes().subscribe();
  }

  /**
   * On Destroy operations
   */
  ngOnDestroy() {
    this.updateContext();
    this.ngUnsubscribe$.next();
    this.ngUnsubscribe$.complete();
  }

  /**
   * Return a list of action for an audit record
   * @param {number} index
   */
  auditActions(index: number) {
    return [
      {
        id: 'viewDetails' + index,
        icon: 'info-circle',
        action: 'viewDetails',
        title: 'Show details',
        isDefault: true
      }
    ];
  }

  /**
   * Apply Action
   * @param action
   * @param args
   */
  applyAction(action: string, args?: any) {
    switch (action) {
      case 'viewDetails':
        this.viewDetails(args);
        break;
    }
  }

  /**
   * Load a paginated list of {@link AuditRecord}s.
   * Build the form checkboxes (persist selection)
   */
  loadAuditRecords() {
    this.auditRecordService.getAuditRecords(this.params)
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe((page: Page<AuditRecord>) => {
          if (page.items.length === 0 && this.params.page > 0) {
            this.params.page = 0;
            return;
          }
          this.auditRecords = page;
          this.updateContext();
        },
        error => {
          this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
        });
  }

  /**
   * Refresh the page
   * Work around: invalidate the cache applications
   */
  refresh() {
    this.loadAuditRecords();
  }

  /**
   * Write the context in the service.
   */
  updateContext() {
    this.context.q = this.params.q;
    this.context.action = this.params.action;
    this.context.operation = this.params.operation;
    this.context.fromDate = this.params.fromDate;
    this.context.toDate = this.params.toDate;
    this.context.sort = this.params.sort;
    this.context.order = this.params.order;
    this.context.page = this.params.page;
    this.context.size = this.params.size;
    this.context.itemsSelected = this.itemsSelected;
  }

  /**
   * Apply sort
   * Triggered on column header click
   *
   * @param {SortParams} sort
   */
  applySort(sort: SortParams) {
    this.params.sort = sort.sort;
    this.params.order = sort.order;
    this.loadAuditRecords();
  }

  /**
   * Get Date Range formatted
   */
  getDateRange() {
    if (this.params.fromDate && this.params.toDate) {
      return this.params.fromDate.toISODate() + ' - ' + this.params.toDate.toISODate();
    }
    return null;
  }

  /**
   * Run the search
   */
  search(value: AuditRecordListParams) {
    this.params.q = value.q;
    this.params.action = value.action;
    this.params.operation = value.operation;
    this.params.page = 0;
    this.loadAuditRecords();
  }

  /**
   * Update event from the Paginator Pager
   * @param params
   */
  changePaginationPager(params) {
    this.params.page = params.page;
    this.params.size = params.size;
    this.updateContext();
    this.loadAuditRecords();
  }

  /**
   * Navigate to the page that provides a detail view for the
   * passed-in {@link AuditRecord}.
   *
   * @param {AuditRecord} auditRecord
   */
  viewDetails(auditRecord: AuditRecord) {
    this.loggerService.log(`View audit record ${auditRecord.auditRecordId}.`, auditRecord);
    this.router.navigate(['audit-records/' + auditRecord.auditRecordId]);
  }

  /**
   * Returns all supported {@link AuditOperationType}s.
   */
  public get operationTypes(): Subject<AuditOperationType[]> {
    return this.auditRecordService.auditOperationTypes$;
  }

  /**
   * Returns all supported {@link AuditActionType}s.
   */
  public get actionTypes(): Subject<AuditActionType[]> {
    return this.auditRecordService.auditActionTypes$;
  }

}
<app-page id="applications-list">

  <app-page-head>
    <app-page-head-title><strong>Audit Records</strong></app-page-head-title>
  </app-page-head>

  <div dataflowLayoutType type="full">
    <p>
      This section gives you access to recorded audit events.
    </p>

    <app-list-bar-audit-record [params]="params" [page]="auditRecords" #listBar
                               (refresh)="refresh()" (search)="search($event)" [actions]="[]"
                               (action)="applyAction($event.action)" [operationTypes]="operationTypes"
                               [actionTypes]="actionTypes">
    </app-list-bar-audit-record>

    <table id="table" *ngIf="auditRecords?.items && auditRecords.items.length > 0"
           class="table-checkbox table table-hover">
      <thead>
      <tr>
        <th style="width: 10px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'id'" [sort]="params"
                    id="sort-id">ID
          </app-sort>
        </th>
        <th style="width: 200px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'createdOn'" [sort]="params"
                    id="sort-createdOn">Created On
          </app-sort>
        </th>
        <th style="width: 100px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'auditAction'" [sort]="params"
                    id="sort-auditAction">Action
          </app-sort>
        </th>
        <th style="width: 100px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'auditOperation'" [sort]="params"
                    id="sort-auditOperation">Operation
          </app-sort>
        </th>
        <th style="width: 200px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'correlationId'" [sort]="params"
                    id="sort-correlationId">Operation Id
          </app-sort>
        </th>
        <th style="width: 200px">
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'createdBy'" [sort]="params"
                    id="sort-createdBy">Created By
          </app-sort>
        </th>
        <th>
          <app-sort [indeterminate]="true" (change)="applySort($event)" [value]="'auditData'" [sort]="params"
                    id="sort-auditData">Data
          </app-sort>
        </th>
        <th class="text-center">&nbsp;</th>
      </tr>
      </thead>
      <tbody>
      <tr *ngFor="let item of auditRecords.items | paginate: auditRecords.getPaginationInstance(); index as i">
        <td nowrap="">
          <a style="cursor: pointer" (click)="viewDetails(item)">{{ item.auditRecordId }}</a>
        </td>
        <td nowrap="">
          {{ item.createdOn | dataflowDateTime }}
        </td>
        <td nowrap="">
          <app-audit-record-action [auditRecord]="item"></app-audit-record-action>
        </td>
        <td nowrap="">
          <app-audit-record-operation [auditRecord]="item"></app-audit-record-operation>
        </td>
        <td nowrap="">
          <strong>{{ item.correlationId }}</strong>
        </td>
        <td nowrap="">
          {{item.createdBy || 'N/A'}}
        </td>
        <td class="dataflow-truncator-width">
          <dataflow-truncator [input]="item.auditData" trailPosition="start" trail="…"></dataflow-truncator>
        </td>
        <td class="table-actions" width="10px" nowrap="">
          <app-list-row-actions [item]="item" (action)="applyAction($event.action, $event.args)"
                                [actions]="auditActions(i)"></app-list-row-actions>
        </td>
      </tr>
      </tbody>
    </table>

    <app-list-pagination [page]="auditRecords" [params]="params" (changed)="changePaginationPager($event)"
                         [item]="'audit record'" [items]="'audit records'">
    </app-list-pagination>

    <app-list-empty [page]="auditRecords" [filters]="[params.q, params.action, params.operation, params.toDate, params.fromDate]">
      <p><strong>No audit records are available</strong>, yet.</p>
      <p [dataflowAppRoles]="['ROLE_VIEW']">
        <a (click)="refresh()">Refresh</a> the page.
      </p>
    </app-list-empty>

    <app-list-no-result [page]="auditRecords" [filters]="[params.q, params.action, params.operation, params.toDate, params.fromDate]">
      <p>
        No results found for
        <strong *ngIf="params.q != ''">'{{ params.q }}'</strong><span
        *ngIf="params.q != '' && params.operation">, </span>
        <strong *ngIf="params.operation">'{{ params.operation.name }}'</strong>
        <strong *ngIf="params.action">'{{ params.action.name }}'</strong>
        <strong *ngIf="getDateRange()">'{{ getDateRange() }}'</strong>.
      </p>
      <p>
        You can <a id="search-clear" (click)="listBar.clearSearch()">clear the search</a> or <a (click)="refresh()">Refresh</a>
        the page.
      </p>
    </app-list-no-result>
  </div>
</app-page>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""