Add pagination to logs table (25 per page)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -75,12 +75,24 @@ sub show_list {
|
||||
return;
|
||||
}
|
||||
|
||||
# Pagination
|
||||
my $per_page = 25;
|
||||
my $total = scalar @files;
|
||||
my $page = int($form->{'page'} // 1);
|
||||
$page = 1 if $page < 1;
|
||||
my $total_pages = int(($total + $per_page - 1) / $per_page);
|
||||
$page = $total_pages if $page > $total_pages;
|
||||
my $start = ($page - 1) * $per_page;
|
||||
my $end = $start + $per_page - 1;
|
||||
$end = $#files if $end > $#files;
|
||||
my @page_files = @files[$start .. $end];
|
||||
|
||||
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100">\n};
|
||||
print qq{<table class="table">\n};
|
||||
print qq{<thead><tr><th>Filename</th><th>Type</th><th>Date</th><th>Size</th><th></th></tr></thead>\n};
|
||||
print qq{<tbody>\n};
|
||||
|
||||
for my $f (@files) {
|
||||
for my $f (@page_files) {
|
||||
my $esc_name = GnizaWHM::UI::esc($f->{name});
|
||||
my $badge = $f->{type} eq 'Cron' ? 'badge-neutral' : 'badge-info';
|
||||
my $date = _format_time($f->{mtime});
|
||||
@@ -97,6 +109,22 @@ sub show_list {
|
||||
}
|
||||
|
||||
print qq{</tbody>\n</table>\n</div>\n};
|
||||
|
||||
# Pagination controls
|
||||
if ($total_pages > 1) {
|
||||
print qq{<div class="flex items-center justify-center gap-2 mt-4">\n};
|
||||
if ($page > 1) {
|
||||
my $prev = $page - 1;
|
||||
print qq{ <button type="button" class="btn btn-sm" onclick="location.href='logs.cgi?page=$prev'">« Prev</button>\n};
|
||||
}
|
||||
print qq{ <span class="text-sm">Page $page of $total_pages ($total logs)</span>\n};
|
||||
if ($page < $total_pages) {
|
||||
my $next = $page + 1;
|
||||
print qq{ <button type="button" class="btn btn-sm" onclick="location.href='logs.cgi?page=$next'">Next »</button>\n};
|
||||
}
|
||||
print qq{</div>\n};
|
||||
}
|
||||
|
||||
print GnizaWHM::UI::page_footer();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user