Bugzilla – Attachment 158209 Details for
Bug 32730
Add patron lists tab to patron details and circulation pages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32730: Add Patron Lists tab to patron details and circulation pages
Bug-32730-Add-Patron-Lists-tab-to-patron-details-a.patch (text/plain), 18.25 KB, created by
Tomás Cohen Arazi (tcohen)
on 2023-11-01 19:15:37 UTC
(
hide
)
Description:
Bug 32730: Add Patron Lists tab to patron details and circulation pages
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2023-11-01 19:15:37 UTC
Size:
18.25 KB
patch
obsolete
>From 90856cd48c8ddb9dc1cf8856d176bf5506b9b207 Mon Sep 17 00:00:00 2001 >From: Michael Hafen <michael.hafen@washk12.org> >Date: Fri, 27 Jan 2023 11:14:32 -0700 >Subject: [PATCH] Bug 32730: Add Patron Lists tab to patron details and > circulation pages > >Test Plan: >1. Apply patch >2. create a patron list if there aren't any >3. search for a patron >4. observe the "Patron lists" tab showing the list that the patron is not in >5. try adding the patron to the list and removing them from the list to > be sure the feature has full operation >6. click "Check Out" on the side bar menu to navigate to the circulation > page for this patron >7. observe the "Patron lists" tab, and verify it operates as it did on the > patron details page > >Bug 32730: (follow-up) Minor corrections > by Owen Leonard > >This patch corrects an instance of an incorrect capital letter >("Patron Lists" -> "Patron lists") and makes minor tweaks to >indentation. > >Signed-off-by: Stina Hallin <stina.hallin@ub.lu.se> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Edit: (tcohen) new files should be run through perltidy ALWAYS. Did it >and squashed it here. >--- > Koha/Patron.pm | 23 +++ > circ/circulation.pl | 7 +- > .../prog/en/includes/patron-detail-tabs.inc | 12 ++ > .../modules/patron_lists/patron-lists-tab.tt | 136 ++++++++++++++++++ > .../prog/js/pages/circulation.js | 7 + > members/moremember.pl | 2 + > patron_lists/patron-lists-tab.pl | 92 ++++++++++++ > t/db_dependent/PatronLists.t | 8 +- > 8 files changed, 285 insertions(+), 2 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt > create mode 100755 patron_lists/patron-lists-tab.pl > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index e5a2798bc10..5a71b56c036 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1642,6 +1642,29 @@ sub get_enrollable_clubs { > return Koha::Clubs->get_enrollable($params); > } > >+ >+=head3 get_lists_with_patron >+ >+my @lists = $patron->get_lists_with_patron; >+ >+=cut >+ >+sub get_lists_with_patron { >+ my ( $self ) = @_; >+ my $borrowernumber = $self->borrowernumber; >+ >+ return Koha::Database->new()->schema()->resultset('PatronList')->search( >+ { >+ 'patron_list_patrons.borrowernumber' => $borrowernumber, >+ }, >+ { >+ join => 'patron_list_patrons', >+ collapse => 1, >+ order_by => 'name', >+ } >+ ); >+} >+ > =head3 account_locked > > my $is_locked = $patron->account_locked >diff --git a/circ/circulation.pl b/circ/circulation.pl >index d68eb1ce5f8..7f8c0ef080f 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -638,7 +638,11 @@ if ( C4::Context->preference("ExportCircHistory") ) { > $template->param(csv_profiles => Koha::CsvProfiles->search({ type => 'marc' })); > } > >-my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count; >+my ( $has_modifications, $patron_lists_count); >+if ( $patron ) { >+ $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count; >+ $patron_lists_count = $patron->get_lists_with_patron->count(); >+} > $template->param( > debt_confirmed => $debt_confirmed, > SpecifyDueDate => $duedatespec_allow, >@@ -646,6 +650,7 @@ $template->param( > today_due_date_and_time => dt_from_string()->set(hour => 23)->set(minute => 59), > restriction_types => scalar Koha::Patron::Restriction::Types->search(), > has_modifications => $has_modifications, >+ patron_lists_count => $patron_lists_count, > override_high_holds => $override_high_holds, > nopermission => scalar $query->param('nopermission'), > autoswitched => $autoswitched, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >index 78ce636879f..ba4fd3ee268 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc >@@ -77,6 +77,12 @@ > <span>Clubs ([% enrollments.count | html %]/[% enrollable.count | html %])</span> > [% END %] > [% END %] >+ >+ [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] >+ [% WRAPPER tab_item tabname="pat_lists" %] >+ <span>Patron lists ([% patron_lists_count | html %])</span> >+ [% END %] >+ [% END %] > [% END # /WRAPPER tabs_nav %] > > >@@ -130,6 +136,12 @@ > [% END # /tab_panel# %] > [% END %] > >+ [% IF CAN_user_tools_manage_patron_lists || patron_lists_count %] >+ [% WRAPPER tab_panel tabname="pat_lists" %] >+ Loading... >+ [% END # /tab_panel# %] >+ [% END %] >+ > [% WRAPPER tab_panel tabname="reldebarments" %] > [% INCLUDE 'patron-restrictions-tab.inc' %] > [% END # /tab_panel# %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt >new file mode 100644 >index 00000000000..57397629775 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/patron-lists-tab.tt >@@ -0,0 +1,136 @@ >+[% USE KohaDates %] >+ >+[% IF no_access_to_patron %] >+ <span class="blocker">Patron not in your library group</span> >+[% END %] >+ >+[% IF in_lists %] >+<div class="patroninfo-section"> >+ <h4>Patron lists with this patron</h4> >+ >+ <table id="table_inlists"> >+ <thead> >+ <tr> >+ <th>Name</th> >+ <th>Patrons in list</th> >+ <th>Shared</th> >+ [% IF CAN_user_tools_manage_patron_lists %] >+ <th class="NoSort">Actions</th> >+ [% END %] >+ </tr> >+ </thead> >+ >+ <tbody> >+ [% FOREACH l IN in_lists %] >+ [% SET shared_by_other = l.owner.id != logged_in_user.id %] >+ <tr> >+ <td> >+ [% IF CAN_user_tools_manage_patron_lists %] >+ <a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]">[% l.name | html %]</a> >+ [% ELSE %] >+ [% l.name | html %] >+ [% END %] >+ </td> >+ <td>[% l.patron_list_patrons_rs.count || 0 | html %]</td> >+ <td> >+ [% IF l.shared %] >+ [% IF shared_by_other %] >+ by <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% l.owner.id | uri %]">[% INCLUDE 'patron-title.inc' patron=l.owner %]</a> >+ [% ELSE %] >+ by you >+ [% END %] >+ [% END %] >+ </td> >+ [% IF CAN_user_tools_manage_patron_lists %] >+ <td> >+ <div class="btn-group dropup"> >+ <a class="btn btn-default btn-xs dropdown-toggle" id="listactions[% l.patron_list_id | html %]" role="button" data-toggle="dropdown" href="#"> >+ Actions <b class="caret"></b> >+ </a> >+ <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="listactions[% l.patron_list_id | html %]"> >+ <li><a onclick="removeFromList('[% l.patron_list_id | html %]','[% list_id_lookup.${l.patron_list_id} | html %]')"><i class="fa fa-remove"></i> Remove patron from list</a></li> >+ <li class="divider"></li> >+ <li><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]"><i class="fa fa-user"></i> Add patrons</a></li> >+ [% UNLESS shared_by_other %] >+ <li><a href="/cgi-bin/koha/patron_lists/add-modify.pl?patron_list_id=[% l.patron_list_id | uri %]"><i class="fa fa-pencil"></i> Edit list</a></li> >+ <li><a class="delete_patron" href="/cgi-bin/koha/patron_lists/delete.pl?patron_list_id=[% l.patron_list_id | html %]" data-list-name="[% l.name | html %]"><i class="fa fa-trash"></i> Delete list</a></li> >+ [% END %] >+ [% IF ( l.patron_list_patrons_rs.count ) %] >+ <li class="divider"></li> >+ <li> >+ <a class="print_cards" href="/cgi-bin/koha/patroncards/print.pl?patronlist_id=[% l.patron_list_id | html %]" data-patron_list_id="[% l.patron_list_id | html %]"><i class="fa fa-print"></i> Print patron cards</a> >+ </li> >+ [% IF CAN_user_tools_edit_patrons %] >+ <li> >+ <a href="/cgi-bin/koha/tools/modborrowers.pl?patron_list_id=[% l.patron_list_id | uri %]&op=show"> >+ <i class="fa fa-pencil"></i> Batch edit patrons >+ </a> >+ </li> >+ [% END %] >+ [% IF CAN_user_tools_delete_anonymize_patrons %] >+ <li> >+ <a href="/cgi-bin/koha/tools/cleanborrowers.pl?step=2&patron_list_id=[% l.patron_list_id | uri %]&checkbox=borrower"> >+ <i class="fa fa-trash"></i> Batch delete patrons >+ </a> >+ </li> >+ [% END %] >+ [% END %] >+ </ul> >+ </div> >+ </td> >+ [% END %] >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+</div> >+ >+[% IF available_lists %] >+<hr> >+[% END %] >+[% END %] >+ >+[% IF available_lists && CAN_user_tools_manage_patron_lists %] >+<div class="h4"> >+ <span>Add patron to list</span> >+ <select name="patron_list_id" id="add_to_patron_list_id_select"> >+ <option value=""></option> >+ [%- FOREACH l IN available_lists %] >+ <option value="[% l.patron_list_id | html %]">[% l.name | html %]</option> >+ [%- END %] >+ </select> >+ <a onclick="addToList()"><i class="fa fa-plus"></i> >+</div> >+[% END %] >+ >+<script> >+ $("#table_listnopatron, #table_inlists").dataTable($.extend(true, {}, dataTablesDefaults, { >+ "columnDefs": [ >+ { 'sortable': false, "bSearchable": false, 'targets': [ 'NoSort' ] } >+ ], >+ "sPaginationType": "full" >+ })); >+ >+ [% IF CAN_user_tools_manage_patron_lists %] >+ function addToList() { >+ var list_id = $("#add_to_patron_list_id_select").val(); >+ $('#pat_lists_panel').text(_("Loading...")); >+ $("body").css("cursor", "progress"); >+ $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% borrowernumber | html %]&patron_list_id=' + list_id + '&patrons_to_add=[% cardnumber | html %]', function() { >+ $("body").css("cursor", "default"); >+ }); >+ >+ return false; >+ } >+ >+ function removeFromList( list_id, patron_list_patron_id ) { >+ $('#pat_lists_panel').text(_("Loading...")); >+ $("body").css("cursor", "progress"); >+ $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=[% borrowernumber | html %]&patron_list_id=' + list_id + '&patrons_to_remove=' + patron_list_patron_id, function() { >+ $("body").css("cursor", "default"); >+ }); >+ >+ return false; >+ } >+ [% END %] >+</script> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js b/koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js >index d05d87b5bc4..574f3f90a2a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js >@@ -99,6 +99,13 @@ $(document).ready(function() { > $('#clubs_panel').load('/cgi-bin/koha/clubs/patron-clubs-tab.pl?borrowernumber=' + borrowernumber ); > }); > } >+ >+ if ( $('#pat_lists_panel').length ) { >+ $('#pat_lists-tab').on('click', function() { >+ $('#pat_lists_panel').text(_("Loading...")); >+ $('#pat_lists_panel').load('/cgi-bin/koha/patron_lists/patron-lists-tab.pl?borrowernumber=' + borrowernumber ); >+ }); >+ } > }); > > function export_checkouts(format) { >diff --git a/members/moremember.pl b/members/moremember.pl >index 97703648047..7a419e9fb93 100755 >--- a/members/moremember.pl >+++ b/members/moremember.pl >@@ -287,6 +287,7 @@ elsif ( $patron->is_going_to_expire ) { > > > my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count; >+my $patron_lists_count = $patron->get_lists_with_patron->count(); > > $template->param( > patron => $patron, >@@ -303,6 +304,7 @@ $template->param( > logged_in_user => $logged_in_user, > files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) ->GetFilesInfo(), > has_modifications => $has_modifications, >+ patron_lists_count => $patron_lists_count, > ); > > if ( C4::Context->preference('UseRecalls') ) { >diff --git a/patron_lists/patron-lists-tab.pl b/patron_lists/patron-lists-tab.pl >new file mode 100755 >index 00000000000..c7c3e2a5f27 >--- /dev/null >+++ b/patron_lists/patron-lists-tab.pl >@@ -0,0 +1,92 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Washington County School District >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use CGI; >+ >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_html_with_http_headers ); >+ >+use Koha::Patrons; >+use Koha::List::Patron qw( GetPatronLists AddPatronsToList DelPatronsFromList ); >+ >+my $cgi = CGI->new; >+ >+my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( >+ { >+ template_name => "patron_lists/patron-lists-tab.tt", >+ query => $cgi, >+ type => "intranet", >+ flagsrequired => [ >+ { circulate => 'circulate_remaining_permissions' }, { borrowers => '*' }, { tools => 'manage_patron_lists' } >+ ], >+ } >+); >+ >+my $logged_in_user = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); >+my $patronnumber = $cgi->param('borrowernumber'); >+my $patron = Koha::Patrons->find($patronnumber); >+my ( @in_lists, %list_id_lookup, @available_lists ); >+ >+my $list_id = $cgi->param('patron_list_id'); >+my @patrons_to_add = $cgi->multi_param('patrons_to_add'); >+my @patrons_to_remove = $cgi->multi_param('patrons_to_remove'); >+ >+if ( !$logged_in_user->can_see_patron_infos($patron) ) { >+ $template->param( 'no_access_to_patron' => 1 ); >+} else { >+ my $has_perms = C4::Auth::haspermission( $logged_in_user->userid, { 'tools' => 'manage_patron_lists' } ); >+ if ( $list_id && $has_perms ) { >+ my ($list) = GetPatronLists( { patron_list_id => $list_id } ); >+ >+ if (@patrons_to_add) { >+ AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } ); >+ } >+ >+ if (@patrons_to_remove) { >+ DelPatronsFromList( { list => $list, patron_list_patrons => \@patrons_to_remove } ); >+ } >+ } >+ >+ if ($patron) { >+ @in_lists = $patron->get_lists_with_patron; >+ foreach my $list (@in_lists) { >+ my @existing = $list->patron_list_patrons; >+ for my $plp (@existing) { >+ if ( $plp->borrowernumber->borrowernumber == $patronnumber ) { >+ $list_id_lookup{ $list->patron_list_id } = $plp->patron_list_patron_id; >+ last; >+ } >+ } >+ } >+ } >+ @available_lists = GetPatronLists(); >+ @available_lists = grep { !$list_id_lookup{ $_->patron_list_id } } @available_lists; >+} >+ >+$template->param( >+ in_lists => \@in_lists, >+ list_id_lookup => \%list_id_lookup, >+ available_lists => \@available_lists, >+ borrowernumber => $patronnumber, >+ cardnumber => $patron->cardnumber, >+); >+ >+output_html_with_http_headers( $cgi, $cookie, $template->output ); >diff --git a/t/db_dependent/PatronLists.t b/t/db_dependent/PatronLists.t >index 82bab67c857..b2edc8d8ff4 100755 >--- a/t/db_dependent/PatronLists.t >+++ b/t/db_dependent/PatronLists.t >@@ -17,13 +17,14 @@ > > use Modern::Perl; > >-use Test::More tests => 11; >+use Test::More tests => 12; > use t::lib::TestBuilder; > use t::lib::Mocks; > > use Koha::Database; > use Koha::List::Patron > qw( AddPatronList AddPatronsToList DelPatronList DelPatronsFromList GetPatronLists ModPatronList ); >+use Koha::Patrons; > > my $schema = Koha::Database->schema; > $schema->storage->txn_begin; >@@ -98,6 +99,11 @@ DelPatronsFromList( > $list1->discard_changes(); > is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' ); > >+my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+AddPatronsToList({list => $list2,borrowernumbers => [ $patron->borrowernumber ]}); >+@lists = $patron->get_lists_with_patron; >+is( scalar @lists, 1, 'get_lists_with_patron works' ); >+ > @lists = GetPatronLists( { owner => $owner } ); > is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' ); > >-- >2.42.0
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 32730
:
145668
|
145710
|
145744
|
145745
|
145768
|
145977
|
146039
|
147981
|
147982
|
149477
|
154672
|
155575
|
155589
|
157992
| 158209 |
158210
|
158211