From 9f09d3d16a5d3a2c8ee2fb0ce15eec0bb139825b Mon Sep 17 00:00:00 2001 From: Nick Clemens 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 Signed-off-by: Bob Bennhoff Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit 83d471394562b8137fce9b3a538d19efc41fa1e1) Signed-off-by: Andrew Fuerste-Henry --- Koha/Hold.pm | 14 +++++ Koha/REST/V1/Holds.pm | 32 +++++++++++ api/v1/swagger/paths.json | 3 + api/v1/swagger/paths/holds.json | 57 +++++++++++++++++++ .../prog/en/includes/holds_table.inc | 6 +- .../prog/en/modules/reserve/request.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/holds.js | 30 ++++++++++ 7 files changed, 141 insertions(+), 2 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index e8d9e0cc2c..cbac5b82ae 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -282,6 +282,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 09b7b7ed15..2b325128bb 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -393,4 +393,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 8f1af595ce..7d9f6087d9 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -53,6 +53,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 847d3b83ca..4721b1409c 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -603,5 +603,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 729db29b32..46420c6c75 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -130,9 +130,11 @@ [% IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 %] [% Branches.GetName(hold.branchcode) | html %] [% ELSE %] - + + + [% END %] [% END %] 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 c42e8e80f8..41ee0d6f9f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -938,6 +938,7 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'columns_settings.inc' %] [% Asset.js("js/circ-patron-search-results.js") | $raw %] + [% Asset.js("js/holds.js") | $raw %]