Bugzilla – Attachment 188635 Details for
Bug 18148
Make list of lists in OPAC sortable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18148: Make list of lists in OPAC sortable
Bug-18148-Make-list-of-lists-in-OPAC-sortable.patch (text/plain), 9.23 KB, created by
Laura Escamilla
on 2025-10-30 12:44:53 UTC
(
hide
)
Description:
Bug 18148: Make list of lists in OPAC sortable
Filename:
MIME Type:
Creator:
Laura Escamilla
Created:
2025-10-30 12:44:53 UTC
Size:
9.23 KB
patch
obsolete
>From 25a8e342f709d64838769f77000f3ca4d9a2d14d Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Mon, 27 Oct 2025 05:06:00 +0000 >Subject: [PATCH] Bug 18148: Make list of lists in OPAC sortable > >This patch adds sorting to lists of lists in the OPAC. > >The mechanism used here for op=list is similar to the one >used in op=view, so it's stylistically and functionally >consistent with the rest of the Lists module in the OPAC. > >Test plan: >0. Apply the patch and restart Plack (ie koha-plack --restart kohadev) >1. Create 20+ public lists and 20+ private lists for a particular user >you control (try to use names that range throughout the alphabet) >2. Using SQL, update the Modification date for at least 1 public >list and 1 private list >3. As an anonymous (ie not logged in user), go to >/cgi-bin/koha/opac-shelves.pl?op=list&public=0 >4. Note you cannot see any lists >5. Go to http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=list&public=1 >6, Note you can see public lists with a toolbar with the button "Sort" >below the alert "Log in to create a new list" >7. Using the "Sort" option, try out all the different sort options >for default, "List name", and "Modification date" >8. After sorting, try paging through the list of lists. You should >note that the sorting is retained through the paging. >9. prove t/db_dependent/Virtualshelves.t >10. Celebrate! > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com> >--- > Koha/Virtualshelves.pm | 35 +++++++++++++++++-- > .../bootstrap/en/modules/opac-shelves.tt | 24 +++++++++++-- > opac/opac-shelves.pl | 14 ++++++-- > 3 files changed, 65 insertions(+), 8 deletions(-) > >diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm >index f3da2c7099..8546d0ac1f 100644 >--- a/Koha/Virtualshelves.pm >+++ b/Koha/Virtualshelves.pm >@@ -87,6 +87,9 @@ sub get_private_shelves { > my $rows = $params->{rows}; > my $borrowernumber = $params->{borrowernumber} || 0; > >+ my $sort_by = $params->{sort_by}; >+ my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); >+ > $self->search( > { > public => 0, >@@ -98,7 +101,7 @@ sub get_private_shelves { > { > join => ['virtualshelfshares'], > distinct => 'shelfnumber', >- order_by => 'shelfname', >+ order_by => $order_by, > ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), > } > ); >@@ -113,18 +116,46 @@ sub get_public_shelves { > my $page = $params->{page}; > my $rows = $params->{rows}; > >+ my $sort_by = $params->{sort_by}; >+ my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); >+ > $self->search( > { > public => 1, > }, > { > distinct => 'shelfnumber', >- order_by => 'shelfname', >+ order_by => $order_by, > ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), > } > ); > } > >+=head3 _prepare_order_by_for_shelves >+ >+Create an "order_by" statement when sorting lists of lists >+ >+=cut >+ >+sub _prepare_order_by_for_shelves { >+ my ($args) = @_; >+ my $sort_by = $args->{sort_by}; >+ my $order_by_dir = '-asc'; >+ my $order_by_col = 'shelfname'; >+ if ($sort_by) { >+ my $sortfield = $sort_by->{sortfield}; >+ my $direction = $sort_by->{direction}; >+ if ( $direction eq 'asc' || $direction eq 'desc' ) { >+ $order_by_dir = '-' . $direction; >+ } >+ if ( $sortfield eq 'shelfname' || $sortfield eq 'lastmodified' ) { >+ $order_by_col = $sortfield; >+ } >+ } >+ my $order_by = { $order_by_dir => $order_by_col }; >+ return $order_by; >+} >+ > =head3 get_some_shelves > > =cut >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >index 875a88da23..60e609a856 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt >@@ -751,11 +751,10 @@ > <div id="publicshelves" class="tab-pane active" role="tabpanel" aria-labelledby="public_lists"> </div> > [% END %] > >+ [% SET show_new_list = 0 %] > [% IF !public || Koha.Preference('OpacAllowPublicListCreation') %] > [% IF loggedinusername %] >- <div id="toolbar" class="toolbar" >- ><a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-plus" aria-hidden="true"></i> New list</a></div >- > >+ [% show_new_list = 1 %] > [% ELSE %] > [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] > <div class="alert alert-info"><a href="/cgi-bin/koha/opac-shelves.pl?op=add_form">Log in to create a new list</a></div> >@@ -764,6 +763,25 @@ > [% END %] > > [% IF shelves.count %] >+ <div id="toolbar" class="toolbar"> >+ [% IF ( show_new_list ) %] >+ <a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-plus" aria-hidden="true"></i> New list</a> <span class="sep">|</span> >+ [% END %] >+ <div class="btn-group dropdown"> >+ <button type="button" class="btn btn-link dropdown-toggle" data-bs-toggle="dropdown" id="sortmenu" aria-haspopup="true" aria-expanded="false" >+ ><i class="fa fa-sort" aria-hidden="true"></i> Sort</button >+ > >+ <div class="dropdown-menu dropdown-menu-end" aria-labelledby="sortmenu"> >+ <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=">Default sorting</a> >+ <span class="dropdown-header">List name</span> >+ <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=shelfname&direction=asc">List name (A-Z)</a> >+ <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=shelfname&direction=desc">List name (Z-A)</a> >+ <span class="dropdown-header">Modification date</span> >+ <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=lastmodified&direction=desc">Modification date (newest to oldest)</a> >+ <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=lastmodified&direction=asc">Modification date (oldest to newest)</a> >+ </div> >+ </div> >+ </div> > <table class="table"> > [% IF !public %] > <caption class="sr-only">Your lists</caption> >diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl >index 77f7ffb034..1f999d827c 100755 >--- a/opac/opac-shelves.pl >+++ b/opac/opac-shelves.pl >@@ -518,13 +518,17 @@ if ( $op eq 'view' ) { > push @messages, { type => 'error', code => 'does_not_exist' }; > } > } elsif ( $op eq 'list' ) { >+ my $direction = $query->param('direction') || 'asc'; >+ my $sortfield = $query->param('sortfield') || 'shelfname'; >+ my $sort_by = { sortfield => $sortfield, direction => $direction }; >+ > my $shelves; > my ($rows) = (20); > if ( !$public ) { > $shelves = Koha::Virtualshelves->get_private_shelves( >- { page => $page, rows => $rows, borrowernumber => $loggedinuser, } ); >+ { page => $page, rows => $rows, borrowernumber => $loggedinuser, sort_by => $sort_by, } ); > } else { >- $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, } ); >+ $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, sort_by => $sort_by, } ); > } > > my $pager = $shelves->pager; >@@ -532,7 +536,11 @@ if ( $op eq 'view' ) { > shelves => $shelves, > pagination_bar => pagination_bar( > q||, $pager->last_page - $pager->first_page + 1, >- $page, "page", { op => 'list', public => $public, } >+ $page, "page", >+ { >+ op => 'list', public => $public, sortfield => $sortfield, >+ direction => $direction, >+ } > ), > ); > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18148
:
188459
|
188460
|
188470
|
188471
| 188635 |
188636