2026-05-30 19:05:23 +03:30
|
|
|
import { Component, computed, EventEmitter, Input, Output } from '@angular/core';
|
2025-12-04 21:07:18 +03:30
|
|
|
import { ButtonModule } from 'primeng/button';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-paginator',
|
|
|
|
|
templateUrl: './paginator.component.html',
|
|
|
|
|
imports: [ButtonModule],
|
|
|
|
|
})
|
|
|
|
|
export class PaginatorComponent {
|
2026-05-30 19:05:23 +03:30
|
|
|
@Input() totalPages: number = 1;
|
2025-12-04 21:07:18 +03:30
|
|
|
@Input() currentPage: number = 1;
|
|
|
|
|
@Input() perPage: number = 10;
|
|
|
|
|
@Input() loading: boolean = false;
|
|
|
|
|
@Output() onChange = new EventEmitter<number>();
|
|
|
|
|
|
2026-05-30 19:05:23 +03:30
|
|
|
pagesToShow = computed(() => {
|
|
|
|
|
const maxVisible = 5;
|
2025-12-04 21:07:18 +03:30
|
|
|
|
2026-05-30 19:05:23 +03:30
|
|
|
if (this.totalPages <= maxVisible) {
|
|
|
|
|
return Array.from({ length: this.totalPages }, (_, i) => i + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let start = Math.max(1, this.currentPage - Math.floor(maxVisible / 2));
|
|
|
|
|
|
|
|
|
|
let end = start + maxVisible - 1;
|
|
|
|
|
|
|
|
|
|
if (end > this.totalPages) {
|
|
|
|
|
end = this.totalPages;
|
|
|
|
|
start = end - maxVisible + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
|
|
|
});
|
2025-12-04 21:07:18 +03:30
|
|
|
|
|
|
|
|
onPageChange(newPage: number) {
|
|
|
|
|
this.onChange.emit(newPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prevPage() {
|
|
|
|
|
if (this.currentPage > 1) {
|
|
|
|
|
this.onPageChange(this.currentPage - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nextPage() {
|
2026-05-30 19:05:23 +03:30
|
|
|
if (this.currentPage < this.totalPages) {
|
2025-12-04 21:07:18 +03:30
|
|
|
this.onPageChange(this.currentPage + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|