import { Component, OnInit, ViewChild, inject } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort, MatSortHeader } from '@angular/material/sort'; import { MatTableDataSource, MatTable, MatColumnDef, MatHeaderCellDef, MatHeaderCell, MatCellDef, MatCell, MatHeaderRowDef, MatHeaderRow, MatRowDef, MatRow } from '@angular/material/table'; import { MatChipsModule } from '@angular/material/chips'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatTooltip } from '@angular/material/tooltip'; import { NgClass, DatePipe } from '@angular/common'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { SanctionsLogsService } from './sanctions-logs.service'; @Component({ selector: 'mifosx-sanctions-logs', templateUrl: './sanctions-logs.component.html', styleUrls: ['./sanctions-logs.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, MatTable, MatSort, MatColumnDef, MatHeaderCellDef, MatHeaderCell, MatSortHeader, MatCellDef, MatCell, MatHeaderRowDef, MatHeaderRow, MatRowDef, MatRow, MatPaginator, MatChipsModule, MatProgressBarModule, MatTooltip, NgClass, DatePipe, FaIconComponent ] }) export class SanctionsLogsComponent implements OnInit { private sanctionsLogsService = inject(SanctionsLogsService); displayedColumns: string[] = [ 'screenedName', 'screeningResult', 'matchCount', 'screenedBy', 'screenedAt' ]; dataSource = new MatTableDataSource(); searchName = ''; activeFilter: string | null = null; loading = false; @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatSort, { static: true }) sort: MatSort; ngOnInit() { this.loadLogs(); } loadLogs() { this.loading = true; const filters: any = {}; if (this.activeFilter) { filters.result = this.activeFilter; } if (this.searchName?.trim()) { filters.name = this.searchName.trim(); } this.sanctionsLogsService.getLogs(filters).subscribe({ next: (data: any) => { this.dataSource = new MatTableDataSource(data || []); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; this.loading = false; }, error: () => { this.dataSource = new MatTableDataSource([]); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; this.loading = false; } }); } applySearch(value: string) { this.searchName = value; this.loadLogs(); } filterByResult(result: string | null) { this.activeFilter = this.activeFilter === result ? null : result; this.loadLogs(); } clearFilters() { this.searchName = ''; this.activeFilter = null; this.loadLogs(); } }