Debian Codegraph @

lib/Mojolicious/Plugin/Minion/resources/templates/minion/_pagination.html.ep

raw
1 % use POSIX;
2
3 % my $last_page = POSIX::ceil($total / $limit);
4 % my $current_page = int($offset / $limit) + 1;
5 % my $prev_offset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
6 % my $next_offset = $offset + $limit;
7 % my $last_offset = ($last_page - 1) * $limit;
8
9 <nav class="text-center">
10 <ul class="pagination">
11 % if ($current_page == 1) {
12 <li class="page-item disabled">
13 <a class="page-link">First</a>
14 % }
15 % else {
16 <li class="page-item">
17 % my $url = url_with->query({offset => 0});
18 <a class="page-link" href="<%= $url %>">First</a>
19 % }
20 </li>
21 % if ($current_page == 1) {
22 <li class="page-item disabled">
23 <a class="page-link">Previous</a>
24 % }
25 % else {
26 <li class="page-item">
27 % my $url = url_with->query({offset => $prev_offset});
28 <a class="page-link" href="<%= $url %>">Previous</a>
29 % }
30 </li>
31 % my $start = $current_page >= 3 ? $current_page - 2 : 1;
32 % $start = $start >= ($last_page - 4) ? $last_page - 4 : $start;
33 % $start = 1 if $start < 1;
34 % my $end = $last_page < ($start + 4) ? $last_page : $start + 4;
35 % for my $i ($start .. $end) {
36 % if ($i == $current_page) {
37 <li class="page-item active"><a class="page-link"><%= $i %></a></li>
38 % }
39 % else {
40 <li class="page-item">
41 % my $url = url_with->query({offset => ($i - 1) * $limit});
42 <a class="page-link" href="<%= $url %>"><%= $i %></a>
43 </li>
44 % }
45 % }
46 % if ($current_page >= $last_page) {
47 <li class="page-item disabled">
48 <a class="page-link">Next</a>
49 % }
50 % else {
51 <li class="page-item">
52 % my $url = url_with->query({offset => $next_offset});
53 <a class="page-link" href="<%= $url %>">Next</a>
54 % }
55 </li>
56 % if ($current_page >= $last_page) {
57 <li class="page-item disabled">
58 <a class="page-link">Last</a>
59 % }
60 % else {
61 <li class="page-item">
62 % my $url = url_with->query({offset => $last_offset});
63 <a class="page-link" href="<%= $url %>">Last</a>
64 % }
65 </li>
66 </ul>
67 </nav>