Bugzilla – Attachment 177161 Details for
Bug 35560
Use the REST API for holds history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35560: Use the REST API for holds
Bug-35560-Use-the-REST-API-for-holds.patch (text/plain), 15.18 KB, created by
Jonathan Druart
on 2025-01-27 09:01:32 UTC
(
hide
)
Description:
Bug 35560: Use the REST API for holds
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-01-27 09:01:32 UTC
Size:
15.18 KB
patch
obsolete
>From b179d7b6dfbc7fac6b16c66b38d4fe03310ab760 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 25 Mar 2024 17:23:00 +0100 >Subject: [PATCH] Bug 35560: Use the REST API for holds > >This patch uses the new REST API endpoint to retrieve the old holds. > >We can now have 2 tables, one for the current holds and one for the old >ones. > >Test plan: >Have several holds with several statuses. >Notice that you see the holds in the respective tables. Test the usual sorting >filtering DT feature and confirm that everything works as expected. > >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > .../prog/en/modules/members/holdshistory.tt | 255 ++++++++++++------ > members/holdshistory.pl | 45 +--- > 2 files changed, 191 insertions(+), 109 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >index f224391bec1..c7ea8fd253a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >@@ -49,82 +49,61 @@ > <div class="alert alert-warning">Staff members are not allowed to access patron's holds history</div> > [% ELSIF is_anonymous %] > <div class="alert alert-warning">This is the anonymous patron, so no holds history is displayed.</div> >-[% ELSIF ( !holds ) %] >- <div class="alert alert-info">This patron has no holds history.</div> > [% ELSE %] > >-[% SET show_itemtype_column = Koha.Preference('AllowHoldItemTypeSelection') %] >+ [% SET show_itemtype_column = Koha.Preference('AllowHoldItemTypeSelection') %] > >-<div id="holdshistory" class="page-section"> >- <table id="table_holdshistory"> >- <thead> >- <tr> >- <th class="anti-the">Title</th> >- <th>Author</th> >- <th>Barcode</th> >- <th>Call number</th> >- <th>Library</th> >- <th>Hold date</th> >- <th>Expiration date</th> >- <th>Waiting date</th> >- <th>Cancellation date</th> >- [% IF show_itemtype_column %] >- <th>Requested item type</th> >+ <div id="holdshistory" class="page-section"> >+ <h2>Current holds</h2> >+ [% IF patron.holds.count %] >+ <table id="table_holdshistory"> >+ <thead> >+ <tr> >+ <th class="anti-the">Title</th> >+ <th>Author</th> >+ <th>Barcode</th> >+ <th>Call number</th> >+ <th>Library</th> >+ <th>Hold date</th> >+ <th>Expiration date</th> >+ <th>Waiting date</th> >+ <th>Cancellation date</th> >+ [% IF show_itemtype_column %] >+ <th>Requested item type</th> >+ [% END %] >+ <th>Status</th> >+ </tr> >+ </thead> >+ </table> >+ [% ELSE %] >+ <div class="dialog message">This patron has no current holds.</div> > [% END %] >- <th>Status</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH hold IN holds %] >- <tr> >- <td>[% INCLUDE 'biblio-title.inc' biblio=hold.biblio link = 1 %]</td> >- <td>[% hold.biblio.author | html %]</td> >- <td>[% hold.item.barcode | html %]</td> >- <td>[% hold.item.itemcallnumber | html %]</td> >- <td>[% Branches.GetName( hold.branchcode ) | html %]</td> >- <td data-order="[% hold.reservedate | html %]">[% hold.reservedate | $KohaDates %]</td> >- <td data-order="[% hold.expirationdate | html %]"> >- [% hold.expirationdate | $KohaDates %] >- </td> >- <td data-order="[% hold.waitingdate | html %]"> >- [% hold.waitingdate | $KohaDates %] >- </td> >- <td data-order="[% hold.cancellationdate | html %]"> >- [% hold.cancellationdate | $KohaDates %] >- </td> >- [% IF show_itemtype_column %] >- <td> >- [% IF hold.itemtype %] >- [% ItemTypes.GetDescription( hold.itemtype ) | html %] >- [% ELSE %] >- <span>Any item type</span> >- [% END %] >- </td> >- [% END %] >- <td> >- [% IF hold.found == 'F' %] >- <span>Fulfilled</span> >- [% ELSIF hold.cancellationdate %] >- <span>Cancelled</span> >- [% IF hold.cancellation_reason %] >- ([% AuthorisedValues.GetByCode('HOLD_CANCELLATION', hold.cancellation_reason) | html %]) >- [% END %] >- [% ELSIF hold.found == 'W' %] >- <span>Waiting</span> >- [% ELSIF hold.found == 'P' %] >- <span>Processing</span> >- [% ELSIF hold.found == 'T' %] >- <span>In transit</span> >- [% ELSE %] >- <span>Pending</span> >- [% END %] >- </td> >- </tr> >- [% END %] >- </tbody> >- </table> >-</div> > >+ <h2>Historical holds</h2> >+ [% IF patron.old_holds.count %] >+ <table id="table_oldholdshistory"> >+ <thead> >+ <tr> >+ <th class="anti-the">Title</th> >+ <th>Author</th> >+ <th>Barcode</th> >+ <th>Call number</th> >+ <th>Library</th> >+ <th>Hold date</th> >+ <th>Expiration date</th> >+ <th>Waiting date</th> >+ <th>Cancellation date</th> >+ [% IF show_itemtype_column %] >+ <th>Requested item type</th> >+ [% END %] >+ <th>Status</th> >+ </tr> >+ </thead> >+ </table> >+ [% ELSE %] >+ <div class="dialog message">This patron has no historical holds.</div> >+ [% END %] >+ </div> > [% END %] > > </main> >@@ -142,6 +121,7 @@ > [% INCLUDE 'columns_settings.inc' %] > [% INCLUDE 'str/members-menu.inc' %] > [% Asset.js("js/members-menu.js") | $raw %] >+ [% INCLUDE 'js-biblio-format.inc' %] > <script> > $(document).ready(function() { > var table_settings = [% TablesSettings.GetTableSettings('members', 'holdshistory', 'holdshistory-table', 'json') | $raw %]; >@@ -149,10 +129,135 @@ > //Remove item type column settings > table_settings['columns'] = table_settings['columns'].filter(function(c){return c['columnname'] != 'itemtype';}); > [% END %] >- var table = KohaTable("table_holdshistory", { >- "pagingType": "full", >- "order": [[4, 'desc']] >- }, table_settings); >+ build_holds_table("#table_holdshistory"); >+ build_holds_table("#table_oldholdshistory", 1); >+ function build_holds_table(table_id, old){ >+ let table_url = '/api/v1/patrons/[% patron.borrowernumber | uri %]/holds'; >+ if (old){table_url += '?old=1'} >+ $(table_id).kohaTable({ >+ ajax: { >+ url: table_url, >+ }, >+ order: [], >+ embed: ['biblio', 'item', 'pickup_library', 'pickup_library.branchname'], >+ columns: [ >+ { >+ data: "biblio.title:biblio.subtitle:biblio.medium", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return $biblio_to_html(row.biblio, { link: 1 }); >+ } >+ }, >+ { >+ data: "biblio.author", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return row.biblio.author; >+ } >+ }, >+ { >+ data: "item.external_id", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return row.item ? row.item.external_id : ""; >+ } >+ }, >+ { >+ data: "item.callnumber", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return row.item ? row.item.callnumber: ""; >+ } >+ }, >+ { >+ data: "pickup_library_id:pickup_library.branchname", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return row.pickup_library.name; >+ } >+ }, >+ { >+ data: "hold_date", >+ type: "date", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return $date(row.hold_date); >+ } >+ }, >+ { >+ data: "expiration_date", >+ type: "date", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return $date(row.expiration_date) >+ } >+ }, >+ { >+ data: "waiting_date", >+ type: "date", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return $date(row.waiting_date) >+ } >+ }, >+ { >+ data: "cancellation_date", >+ type: "date", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ return $date(row.cancellation_date) >+ } >+ }, >+ [% IF show_itemtype_column %] >+ { >+ data: "item_type.item_type", >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ if ( row.item_type ) { >+ return row.item_type.item_type; >+ } else { >+ return _("Any item type"); >+ } >+ } >+ }, >+ [% END %] >+ { >+ data: "found", // FIXME filter with dropdown list >+ searchable: true, >+ orderable: true, >+ render: function (data, type, row, meta) { >+ if ( row.status == 'F' ) { >+ return _("Fulfilled"); >+ } else if (row.cancellation_date) { >+ let r = _("Cancelled"); >+ if (row.cancellation_reason){ >+ r += "(%s)".format("FIXME"); //FIXME Add HOLD_CANCELLATION description >+ } >+ return r; >+ } else if (row.status == 'W') { >+ return _("Waiting"); >+ } else if (row.status == 'P') { >+ return _("Processing"); >+ } else if (row.status == 'T') { >+ return _("In transit"); >+ } >+ >+ return _("Pending"); >+ } >+ }, >+ ], >+ }, table_settings); >+ } > }); > </script> > [% END %] >diff --git a/members/holdshistory.pl b/members/holdshistory.pl >index 8564c09a699..c77501ab3d8 100755 >--- a/members/holdshistory.pl >+++ b/members/holdshistory.pl >@@ -26,56 +26,33 @@ use Koha::Patrons; > > my $input = CGI->new; > >-my $borrowernumber; >-my $cardnumber; >-my @all_holds; >- >-my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/holdshistory.tt", >- query => $input, >- type => "intranet", >- flagsrequired => {borrowers => 'edit_borrowers'}, >- }); >- >-my $patron; >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "members/holdshistory.tt", >+ query => $input, >+ type => "intranet", >+ flagsrequired => { borrowers => 'edit_borrowers' }, >+ } >+); > >-if ($input->param('cardnumber')) { >- $cardnumber = $input->param('cardnumber'); >- $patron = Koha::Patrons->find( { cardnumber => $cardnumber } ); >-} >-if ($input->param('borrowernumber')) { >- $borrowernumber = $input->param('borrowernumber'); >- $patron = Koha::Patrons->find( $borrowernumber ); >-} >+my $cardnumber = $input->param('cardnumber'); >+my $borrowernumber = $input->param('borrowernumber'); >+my $patron = Koha::Patrons->find( $cardnumber ? { cardnumber => $cardnumber } : $borrowernumber ); > > unless ( $patron ) { > print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); > exit; > } > >-my $holds; >-my $old_holds; >- > if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){ > # use of 'eq' in the above comparison is intentional -- the > # system preference value could be blank > $template->param( is_anonymous => 1 ); >-} else { >- $holds = $patron->holds; >- $old_holds = $patron->old_holds; >- >- while (my $hold = $holds->next) { >- push @all_holds, $hold; >- } >- >- while (my $hold = $old_holds->next) { >- push @all_holds, $hold; >- } > } > > $template->param( > holdshistoryview => 1, > patron => $patron, >- holds => \@all_holds, > ); > > output_html_with_http_headers $input, $cookie, $template->output; >-- >2.34.1
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 35560
:
160100
|
160101
|
163831
|
163832
|
164093
|
165231
|
165232
|
165233
|
177161
|
177162
|
177163
|
177200
|
177201
|
177202
|
177203
|
177792
|
177793
|
177794