Bugzilla – Attachment 113426 Details for
Bug 26988
Defer loading the hold pickup locations until the dropdown is selected
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26988: Add API route to fetch hold pickup locations and use it in the holds table
Bug-26988-Add-API-route-to-fetch-hold-pickup-locat.patch (text/plain), 9.39 KB, created by
Andrew Fuerste-Henry
on 2020-11-10 17:18:05 UTC
(
hide
)
Description:
Bug 26988: Add API route to fetch hold pickup locations and use it in the holds table
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2020-11-10 17:18:05 UTC
Size:
9.39 KB
patch
obsolete
>From b9da3a4b098008ec039a1f3ba30426b7d1654623 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 10 Nov 2020 13:35:14 +0000 >Subject: [PATCH] Bug 26988: Add API route to fetch hold pickup locations and > use it in the holds table > >To test: >1 - Place a number of holds on a record >2 - Have different pickup locations for the holds >3 - Have some libraries that are not pickup locations >4 - Load the holds tab for the record and note libraries not pickup locations are not in dropdowns >5 - Apply patch and restart all things >6 - Reload the holds table >7 - Click on a dropdown, note the spinner, should load successfully >8 - Confirm the dropdown matches the options before the patch >9 - Confirm updating the hold location works > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org> >--- > Koha/Hold.pm | 14 ++++++ > Koha/REST/V1/Holds.pm | 32 ++++++++++++ > api/v1/swagger/paths.json | 3 ++ > api/v1/swagger/paths/holds.json | 57 ++++++++++++++++++++++ > .../intranet-tmpl/prog/en/includes/holds_table.inc | 13 ++--- > .../prog/en/modules/reserve/request.tt | 1 + > koha-tmpl/intranet-tmpl/prog/js/holds.js | 30 ++++++++++++ > 7 files changed, 141 insertions(+), 9 deletions(-) > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 4bd087d64d..1d9604ca39 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -338,6 +338,20 @@ sub biblio { > return $self->{_biblio}; > } > >+=head3 patron >+ >+Returns the related Koha::Patron object for this hold >+ >+=cut >+ >+sub patron { >+ my ($self) = @_; >+ >+ $self->{_patron} ||= Koha::Patrons->find( $self->borrowernumber() ); >+ >+ return $self->{_patron}; >+} >+ > =head3 item > > Returns the related Koha::Item object for this Hold >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index e197f32334..8239a62186 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -395,4 +395,36 @@ sub update_priority { > }; > } > >+=head3 pickup_locations >+ >+Method that returns the possible pickup_locations for a given hold >+used for building the dropdown selector >+ >+=cut >+ >+sub pickup_locations { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $hold_id = $c->validation->param('hold_id'); >+ my $hold = Koha::Holds->find($hold_id); >+ >+ unless ($hold) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Hold not found" } >+ ); >+ } >+ >+ return try { >+ my $pickup_locations = $hold->itemnumber ? >+ $hold->item->pickup_locations({ patron => $hold->patron }) : $hold->biblio->pickup_locations({ patron => $hold->patron }); >+ warn Data::Dumper::Dumper( $pickup_locations ); >+ >+ return $c->render( status => 200, openapi => $pickup_locations ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index 8ba95189dc..92e4739e02 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -59,6 +59,9 @@ > "/holds/{hold_id}/suspension": { > "$ref": "paths/holds.json#/~1holds~1{hold_id}~1suspension" > }, >+ "/holds/{hold_id}/pickup_locations": { >+ "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations" >+ }, > "/items": { > "$ref": "paths/items.json#/~1items" > }, >diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json >index 8137f16a7f..b375ea72dd 100644 >--- a/api/v1/swagger/paths/holds.json >+++ b/api/v1/swagger/paths/holds.json >@@ -613,5 +613,62 @@ > } > } > } >+ }, >+ "/holds/{hold_id}/pickup_locations": { >+ "get": { >+ "x-mojo-to": "Holds#pickup_locations", >+ "operationId": "getHoldPickupLocations", >+ "tags": ["holds"], >+ "parameters": [{ >+ "$ref": "../parameters.json#/hold_id_pp" >+ }], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Hold pickup location" >+ }, >+ "400": { >+ "description": "Missing or wrong parameters", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "401": { >+ "description": "Authentication required", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "403": { >+ "description": "Hold pickup location list not allowed", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "404": { >+ "description": "Hold not found", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "500": { >+ "description": "Internal server error", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "503": { >+ "description": "Under maintenance", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "reserveforothers": "1" >+ } >+ } >+ } > } > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >index 535623ef42..693ed97176 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >@@ -133,16 +133,11 @@ > [% IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 %] > [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" /> > [% ELSE %] >- <select name="pickup"> >- [% IF !hold.itemnumber %] >- [% IF next_available_locations == "" %] >- [% SET next_available_locations = Branches.pickup_locations( { search_params => { item => hold.itemnumber, biblio => hold.biblionumber, patron => hold.patron } } ) %] >- [% END %] >- [% PROCESS options_for_libraries libraries => next_available_locations, selected => hold.branchcode %] >- [% ELSE %] >- [% PROCESS options_for_libraries libraries => Branches.pickup_locations( { search_params => { item => hold.itemnumber, biblio => hold.biblionumber, patron => hold.patron }, selected => hold.branchcode }) %] >- [% END %] >+ <select class="pickup_location_dropdown" data-selected="[% hold.branchcode | html %]" data-hold_id="[% hold.reserve_id | html %]" name="pickup"> >+ <option selected="selected" value="[% hold.branchcode | html %]">[% Branches.GetName(hold.branchcode) | html %]</option> >+ <option value="" disabled="disabled" class="loading">Loading...</option> > </select> >+ <img class="loading_[% hold.reserve_id %]" src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" style="display:none;"/> > [% END %] > [% END %] > </td> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >index 95861f6be2..f479387c7e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >@@ -985,6 +985,7 @@ > [% INCLUDE 'columns_settings.inc' %] > [% Asset.js("lib/hc-sticky.js") | $raw %] > [% Asset.js("js/circ-patron-search-results.js") | $raw %] >+ [% Asset.js("js/holds.js") | $raw %] > <script> > var Sticky; > var biblionumber = "[% biblionumber | $raw %]"; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index 29a048914a..748aab04c9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/holds.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js >@@ -302,4 +302,34 @@ $(document).ready(function() { > }); > }); > >+ $(".pickup_location_dropdown").on( "click",function(){ >+ var this_dropdown = $(this); >+ if(this_dropdown.data('loaded')===1){ return true}; >+ var hold_id = $(this).data('hold_id'); >+ $(".loading_"+hold_id).show(); >+ var preselected = $(this).data('selected'); >+ var api_url = '/api/v1/holds/'+hold_id+'/pickup_locations'; >+ $.ajax({ >+ method: "GET", >+ url: api_url, >+ success: function( data ){ >+ var dropdown = ""; >+ $.each(data, function(index,library) { >+ if( preselected == library.branchcode ){ >+ selected = ' selected="selected" '; >+ } else { selected = ""; } >+ dropdown += '<option value="'+library.branchcode+'"'+selected+'>'+library.branchname+'</option>'; >+ }); >+ this_dropdown.html( dropdown); >+ this_dropdown.data("loaded",1); >+ $(".loading_"+hold_id).hide(); >+ }, >+ error: function( jqXHR, textStatus, errorThrown) { >+ alert('There was an error:'+textStatus+" "+errorThrown); >+ $(".loading_"+hold_id).hide(); >+ }, >+ }); >+ }); >+ >+ > }); >-- >2.11.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 26988
:
113395
|
113418
|
113426
|
113427
|
113428
|
113456
|
113457
|
113458
|
113459
|
113460
|
113502
|
113533
|
113534
|
113535
|
113536
|
113537
|
113538
|
113590
|
113601
|
113669