You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aConnect-UX/src/app/transaction-logs/transaction-logs.component.ts

103 lines
3.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { ExcelExportService } from '../shared/services/excel-export.service';
import { TRANSACTION_LOGS_FILE_NAME } from '../utils/app.constants';
import { pageSizeOptions } from '../utils/app.constants';
import { NgSelectModule } from '@ng-select/ng-select';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TableFilterPipe } from '../shared/pipes/table-filter.pipe';
import {TransactionLog} from "../models/user"
import { URIKey } from '../utils/uri-enums';
import { HttpParams } from '@angular/common/http';
import { HttpURIService } from '../app.http.uri.service';
@Component({
selector: 'app-transaction-logs',
templateUrl: './transaction-logs.component.html',
imports: [CommonModule, TranslateModule, NgSelectModule, FormsModule, ReactiveFormsModule, TableFilterPipe ]
})
export class TransactionLogsComponent implements OnInit {
onPageSizeChange(arg0: number) {
throw new Error('Method not implemented.');
}
currentPage: number = 1;
totalCount: number = 0;
renewalDataExpanded: boolean = true;
pageSizeOptions = pageSizeOptions;
itemsPerPage: number = 5;
transactionLog: TransactionLog[] = [];
isLoading = false;
pagedItems: any[] = [];
errorMessage: string = '';
searchText: string = '';
allItems: any;
constructor(
private excelExportService: ExcelExportService,
private httpService: HttpURIService,
) {}
ngOnInit(): void {
this.loadTransactionLogs();
}
loadTransactionLogs(): void {
this.isLoading = true;
const params = new HttpParams();
this.httpService
.requestGET<any>(URIKey.TRANSACTION_LOGS, params)
.subscribe({
next: (res) => {
const logs = Array.isArray(res) ? res : res?.data;
this.transactionLog = logs ?? [];
this.allItems = [...this.transactionLog];
this.totalCount = this.transactionLog.length;
this.updatePagedItems();
this.isLoading = false;
},
error: (err) => {
console.error('Error fetching logging details data:', err);
this.transactionLog = [];
this.isLoading = false;
}
});
}
itemsPerPageChanged(): void {
this.currentPage = 1;
this.updatePagedItems();
}
onSearch(value: string): void {
this.searchText = value;
}
totalPages(): number {
return Math.ceil(this.allItems.length / this.itemsPerPage);
}
previousPage(): void {
if (this.currentPage > 1) {
this.currentPage--;
this.updatePagedItems();
}
}
updatePagedItems(): void {
const startIndex = (this.currentPage - 1) * this.itemsPerPage;
const endIndex = startIndex + this.itemsPerPage;
this.pagedItems = this.allItems.slice(startIndex, endIndex);
}
nextPage(): void {
if (this.currentPage < this.totalPages()) {
this.currentPage++;
this.updatePagedItems();
}
}
exportDataInExcel() {
this.excelExportService.exportExcel(this.transactionLog, TRANSACTION_LOGS_FILE_NAME)
}
}