From 519c525675eb5e132cc950243599cfa5c07d70a8 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Wed, 1 Feb 2017 09:42:20 +0000 Subject: [PATCH] Bug 18008: Make pagination generated in templates It generates pagination in bootstrap style (as bug 18005 also do) Modified pages: acqui/neworderbiblio.pl authorities/authorities-home.pl cataloguing/addbooks.pl cataloguing/value_builder/marc21_linking_section.pl cataloguing/value_builder/unimarc_field_210c.pl cataloguing/value_builder/unimarc_field_4XX.pl reports/guided_reports.pl reviews/reviewswaiting.pl tags/review.pl virtualshelves/shelves.pl Test plan: 0) Apply the patch 1) go through pages from the list above/use cataloguing plugins, and make the data to be big enough for pagination 2) confirm that pagination looks nice and behave correctly 3) git grep pagination_bar should return just C4/Output.pm and opac templates (I'll deal with it on another bugs) --- acqui/neworderbiblio.pl | 8 ++- authorities/authorities-home.pl | 11 ++-- cataloguing/addbooks.pl | 9 +++- .../value_builder/marc21_linking_section.pl | 8 --- cataloguing/value_builder/unimarc_field_210c.pl | 19 ++++--- cataloguing/value_builder/unimarc_field_4XX.pl | 8 --- .../intranet-tmpl/prog/en/includes/pagination.inc | 60 ++++++++++++++++++++++ .../prog/en/modules/acqui/neworderbiblio.tt | 4 +- .../prog/en/modules/admin/matching-rules.tt | 2 - .../prog/en/modules/admin/patron-attr-types.tt | 2 - .../en/modules/authorities/searchresultlist.tt | 4 +- .../prog/en/modules/cataloguing/addbooks.tt | 2 +- .../value_builder/unimarc_field_210c.tt | 10 ++-- .../en/modules/reports/guided_reports_start.tt | 1 - .../prog/en/modules/reviews/reviewswaiting.tt | 4 +- .../intranet-tmpl/prog/en/modules/tags/review.tt | 6 +-- .../prog/en/modules/virtualshelves/shelves.tt | 5 +- reports/guided_reports.pl | 3 +- reviews/reviewswaiting.pl | 9 +++- tags/review.pl | 7 +-- virtualshelves/shelves.pl | 12 +++-- 21 files changed, 130 insertions(+), 64 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/pagination.inc diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index f083398e4f..84f8bb2be9 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -144,6 +144,12 @@ foreach my $r (@{$budgets}) { last; } +my $pagination = { + base_url => "/cgi-bin/koha/acqui/neworderbiblio.pl?q=$query&booksellerid=$booksellerid&basketno=$basketno&page=", + pages => getnbpages( $total_hits, $results_per_page ), + current_page => $page, +}; + $template->param( has_budgets => $has_budgets, basketno => $basketno, @@ -152,7 +158,7 @@ $template->param( resultsloop => \@results, total => $total_hits, query => $query, - pagination_bar => pagination_bar( "/cgi-bin/koha/acqui/neworderbiblio.pl?q=$query&booksellerid=$booksellerid&basketno=$basketno&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ), + pagination => $pagination, ); # BUILD THE TEMPLATE diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 89142f22d6..9843b49688 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -188,11 +188,14 @@ if ( $op eq "do_search" ) { $template->param( result => $results ) if $results; + my $pagination = { + base_url => "$base_url&startfrom=", + pages => getnbpages( $total, $resultsperpage ), + current_page => $startfrom, + }; + $template->param( - pagination_bar => pagination_bar( - $base_url, int( $total / $resultsperpage ) + 1, - $startfrom, 'startfrom' - ), + pagination => $pagination, total => $total, from => $from, to => $to, diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index ae4d7acbde..a3589f1b56 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -90,11 +90,18 @@ if ($query) { # SimpleSearch() give the results per page we want, so 0 offet here my $total = @{$marcresults}; my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults ); + + my $pagination = { + base_url => "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&page=", + pages => getnbpages( $total_hits, $results_per_page ), + current_page => $page, + }; + $template->param( total => $total_hits, query => $query, resultsloop => \@newresults, - pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ), + pagination => $pagination, ); } diff --git a/cataloguing/value_builder/marc21_linking_section.pl b/cataloguing/value_builder/marc21_linking_section.pl index 0fb9b7bcfe..c4aca0dd67 100755 --- a/cataloguing/value_builder/marc21_linking_section.pl +++ b/cataloguing/value_builder/marc21_linking_section.pl @@ -274,14 +274,6 @@ my $launcher = sub { # foreach my $sort (@sort_by){ # $link.="&sort_by=".$sort."&"; # } - # $template->param( - # pagination_bar => pagination_bar( - # $link, - # getnbpages($hits, $results_per_page), - # $page, - # 'page' - # ), - # ); $template->param( result => \@arrayresults, index => scalar $query->param('index') . "", diff --git a/cataloguing/value_builder/unimarc_field_210c.pl b/cataloguing/value_builder/unimarc_field_210c.pl index f6602a0e1b..2667f90b60 100755 --- a/cataloguing/value_builder/unimarc_field_210c.pl +++ b/cataloguing/value_builder/unimarc_field_210c.pl @@ -107,18 +107,25 @@ my ($input) = @_; $template->param(result => $results) if $results; $template->param('index' => scalar $query->param('index')); + + my $pagination = { + base_url => "$link&startfrom=", + pages => getnbpages($total, $resultsperpage), + current_page => $startfrom, + }; $template->param( + startfrom=> $startfrom, + displaynext=> $displaynext, + displayprev=> $displayprev, + resultsperpage => $resultsperpage, + startfromnext => $startfrom+1, + startfromprev => $startfrom-1, total=>$total, from=>$from, to=>$to, authtypecode =>$authtypecode, resultstring =>$value[0], - pagination_bar => pagination_bar( - $link, - getnbpages($total, $resultsperpage), - $startfrom, - 'startfrom' - ), + pagination => $pagination, ); } else { ($template, $loggedinuser, $cookie) diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl index c51434954c..a6cbd446a2 100755 --- a/cataloguing/value_builder/unimarc_field_4XX.pl +++ b/cataloguing/value_builder/unimarc_field_4XX.pl @@ -476,14 +476,6 @@ sub plugin { # foreach my $sort (@sort_by){ # $link.="&sort_by=".$sort."&"; # } -# $template->param( -# pagination_bar => pagination_bar( -# $link, -# getnbpages($hits, $results_per_page), -# $page, -# 'page' -# ), -# ); $template->param( result => \@arrayresults, index => scalar $query->param('index') . "", diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/pagination.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/pagination.inc new file mode 100644 index 0000000000..5a25ddb46a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/pagination.inc @@ -0,0 +1,60 @@ +[%# this is template for generating pagination %] +[%# it needed an array named "pagination" with this structure: %] +[%# pagination.pages => total number of pages %] +[%# pagination.base_url => url with all needed parameters and with parameter specifiyng page at the end %] +[%# pagination.current_page => number of current active page %] + +[% IF pagination && ( pagination.pages > 1 ) %] + + + +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tt index 5d9a0ac331..d1d5bbcf61 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tt @@ -21,8 +21,8 @@ [% IF ( total ) %] -[% total %] results found -
[% pagination_bar %]
+ [% total %] results found + [% INCLUDE 'pagination.inc' %] [% ELSE %]

No results found

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt index a084e9d5b8..41cb555b3a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt @@ -465,8 +465,6 @@ [% END %] [% ELSE %]

There are no saved matching rules.

[% END %] -
[% pagination_bar %]
- [% END %] [% IF ( matching_rule_form ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt index 37fe6de415..b0373c77b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt @@ -20,7 +20,7 @@
[% IF ( total ) %] -
[% pagination_bar %]
+[% INCLUDE 'pagination.inc' %]

Results [% from %] to [% to %] of [% total %] @@ -70,7 +70,7 @@ -

[% pagination_bar %]
+[% INCLUDE 'pagination.inc' %] [% ELSE %] No results found diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt index 7305bd54b6..8f31dc58e5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -61,7 +61,7 @@ [% total %] result(s) found in catalog, [% breeding_count %] result(s) found in reservoir -
[% pagination_bar %]
+[% INCLUDE 'pagination.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt index 31797ada8e..0ff309ed66 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt @@ -42,9 +42,8 @@ [% IF ( total ) %]

Authority search results

-
- [% pagination_bar %] -
[% END %] + [% INCLUDE 'pagination.inc' %] + [% END %]

[% IF ( total ) %]  Results [% from %] to [% to %] of [% total %]

@@ -75,9 +74,8 @@ [% END %] - [% IF ( total ) %]

- [% pagination_bar %] -
+ [% IF ( total ) %] + [% INCLUDE 'pagination.inc' %] [% END %] [% MACRO jsinclude BLOCK %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index 28e0c17626..ebad592e09 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -713,7 +713,6 @@ canned reports and writing custom SQL reports.

-
[% pagination_bar %]
[% UNLESS ( errors ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt index 5cf457bb4d..cc29bf6b9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt @@ -60,13 +60,15 @@ [% END %]
-
[% pagination_bar %]
+ [% ELSE %] [% IF ( status ) %]

No comments have been approved.

[% ELSE %]

No comments to moderate.

[% END %] [% END %]
+[% INCLUDE 'pagination.inc' %] +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt index eacb7d8cec..3ec7574875 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt @@ -65,11 +65,7 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; } [% END %]
[% END %] - [% IF ( pagination_bar ) %] -
- [% pagination_bar %] -
- [% END %] + [% IF ( tagloop ) %]

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index d3c4ac4002..d4749774f5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -129,7 +129,7 @@ [% IF itemsloop %]

Contents of [% shelf.shelfname | html %]

-
[% pagination_bar %]
+ @@ -160,6 +160,7 @@ [% END %] + [% INCLUDE 'pagination.inc' %]
[% IF ( itemsloop ) %][% END %] @@ -243,7 +244,7 @@ [% END %]
 
-
[% pagination_bar %]
+ [% INCLUDE 'pagination.inc' %] [% END %] diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 8809b81710..46fd76219b 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -813,11 +813,11 @@ elsif ($phase eq 'Run this report'){ } } - my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0); my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&phase=Run%20this%20report&limit=$limit"; if (@sql_params) { $url = join('&sql_params=', $url, map { URI::Escape::uri_escape_utf8($_) } @sql_params); } + $template->param( 'results' => \@rows, 'sql' => $sql, @@ -827,7 +827,6 @@ elsif ($phase eq 'Run this report'){ 'name' => $name, 'notes' => $notes, 'errors' => defined($errors) ? [ $errors ] : undef, - 'pagination_bar' => pagination_bar($url, $totpages, scalar $input->param('page')), 'unlimited_total' => $total, 'sql_params' => \@sql_params, ); diff --git a/reviews/reviewswaiting.pl b/reviews/reviewswaiting.pl index 6dc51f1349..4a5b2034a6 100755 --- a/reviews/reviewswaiting.pl +++ b/reviews/reviewswaiting.pl @@ -22,6 +22,7 @@ use C4::Auth; use C4::Output; use C4::Context; use C4::Biblio; +use C4::Koha; use Koha::Biblios; use Koha::Patrons; use Koha::Reviews; @@ -81,10 +82,16 @@ for my $review ( @$reviews ) { my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status"; +my $pagination = { + base_url => "$url&page=", + pages => getnbpages( $total, $count ), + current_page => $page, +}; + $template->param( status => $status, reviews => $reviews, - pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $page, "page" ) + pagination => $pagination, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/tags/review.pl b/tags/review.pl index 353e741994..7cdcee4ae7 100755 --- a/tags/review.pl +++ b/tags/review.pl @@ -29,7 +29,7 @@ use C4::Auth qw(:DEFAULT check_cookie_auth); use C4::Context; use Koha::DateUtils; # use C4::Koha; -use C4::Output qw(:html :ajax pagination_bar); +use C4::Output qw(:html :ajax); use C4::Debug; use C4::Tags qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved); @@ -210,6 +210,7 @@ $qstring =~ s/^;+//; # remove leading delims $qstring = "limit=$pagesize" . ($qstring ? '&' . $qstring : ''); $debug and print STDERR "number of approval_rows: " . scalar(@$tagloop) . "rows\n"; (scalar @errors) and $template->param(message_loop=>\@errors); + $template->param( offset => $offset, # req'd for EXPR op => $op, @@ -217,10 +218,6 @@ $template->param( script_name => $script_name, approved => 0, # dummy value (also EXPR) tagloop => $tagloop, - pagination_bar => pagination_bar( - "$script_name?$qstring\&", - ceil($counts->{approved_total}/$pagesize), # $page, 'page' - ) ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 192580f857..73daf66752 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -327,11 +327,15 @@ if ( $op eq 'view' ) { ); if ( $page ) { my $pager = $contents->pager; + + my $pagination = { + base_url => "?op=view&shelfnumber=" . $shelf->shelfnumber . "&sortfield=$sortfield&direction=$direction&page=", + pages => $pager->last_page - $pager->first_page + 1, + current_page => $page, + }; + $template->param( - pagination_bar => pagination_bar( - q||, $pager->last_page - $pager->first_page + 1, - $page, "page", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, } - ), + pagination => $pagination, ); } } else { -- 2.14.1