backend: make pager object hold only numbers

This commit is contained in:
Lucas 2023-03-23 20:26:08 +00:00
parent 46682ed7da
commit 1748621469
2 changed files with 14 additions and 10 deletions

View File

@ -9,18 +9,18 @@ use SeaweedFS::Client;
sub _pager_links ($c, $dbp)
{
my %pager;
my $page_url = sub ($p) { $c->url_with->query({page => $p}) };
$pager{first_page} = $page_url->($dbp->{first_page})
$pager{current_page} = $dbp->{current_page};
$pager{first_page} = $dbp->{first_page}
if $dbp->{first_page} != $dbp->{current_page};
$pager{previous_page} = $page_url->($dbp->{previous_page})
$pager{previous_page} = $dbp->{previous_page}
if defined($dbp->{previous_page}) &&
$dbp->{previous_page} != $dbp->{first_page};
$pager{current_page} = $dbp->{current_page};
$pager{next_page} = $page_url->($dbp->{next_page})
$pager{next_page} = $dbp->{next_page}
if defined($dbp->{next_page}) &&
$dbp->{next_page} != $dbp->{last_page};
$pager{last_page} = $page_url->($dbp->{last_page})
$pager{last_page} = $dbp->{last_page}
if $dbp->{last_page} != $dbp->{current_page};
return %pager;

View File

@ -1,11 +1,15 @@
% if (my $pager = stash("pager")) {
<footer>
<nav class="text-center">
<%= link_to "<<" => $pager->{first_page} if exists $pager->{first_page} %>
<%= link_to "<" => $pager->{previous_page} if exists $pager->{previous_page} %>
<%= link_to "<<" => url_with->query({ page => $pager->{first_page} })
if exists $pager->{first_page} %>
<%= link_to "<" => url_with->query({ page => $pager->{previous_page} })
if exists $pager->{previous_page} %>
<span><%= $pager->{current_page} %></span>
<%= link_to ">" => $pager->{next_page} if exists $pager->{next_page} %>
<%= link_to ">>" => $pager->{last_page} if exists $pager->{last_page} %>
<%= link_to ">" => url_with->query({ page => $pager->{next_page} })
if exists $pager->{next_page} %>
<%= link_to ">>" => url_with->query({ page => $pager->{last_page} })
if exists $pager->{last_page} %>
</nav>
</footer>
% }