Bug 32030: Add/remove packages to/from EBSCO's holdings
Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
98ab918470
commit
65cffa9619
|
|
@ -110,4 +110,21 @@ sub delete {
|
|||
}
|
||||
}
|
||||
|
||||
=head3 edit
|
||||
|
||||
Controller function that handles editing a single Koha::ERM::EHoldings::Package object
|
||||
|
||||
=cut
|
||||
|
||||
sub edit {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $provider = $c->validation->param('provider');
|
||||
if ( $provider eq 'ebsco' ) {
|
||||
return Koha::REST::V1::ERM::EHoldings::Packages::EBSCO::edit($c);
|
||||
} else {
|
||||
die "invalid action";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -104,4 +104,47 @@ sub get {
|
|||
};
|
||||
}
|
||||
|
||||
sub edit {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
return try {
|
||||
my $body = $c->validation->param('body');
|
||||
my $is_selected = $body->{is_selected};
|
||||
my ( $vendor_id, $package_id ) = split '-',
|
||||
$c->validation->param('package_id');
|
||||
|
||||
my $ebsco = Koha::ERM::Providers::EBSCO->new;
|
||||
my $t = try {
|
||||
$ebsco->request(
|
||||
PUT => '/vendors/' . $vendor_id . '/packages/' . $package_id,
|
||||
undef,
|
||||
{
|
||||
isSelected => $is_selected,
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::ObjectNotFound') ) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => { is_selected => $is_selected } # We don't want to refetch the resource to make sure it has been updated
|
||||
);
|
||||
}
|
||||
catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -295,3 +295,64 @@
|
|||
x-koha-authorization:
|
||||
permissions:
|
||||
erm: 1
|
||||
patch:
|
||||
x-mojo-to: ERM::EHoldings::Packages#edit
|
||||
operationId: editErmEHoldingsPackages
|
||||
tags:
|
||||
- eholdings
|
||||
summary: Edit a package
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: Provider name
|
||||
in: path
|
||||
name: provider
|
||||
required: true
|
||||
type: string
|
||||
- description: A JSON object containing the fields to edit
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
is_selected:
|
||||
description: Add or remove this package from remote holdings
|
||||
type: boolean
|
||||
additionalProperties: false
|
||||
- $ref: "../swagger.yaml#/parameters/eholdings_package_id_pp"
|
||||
responses:
|
||||
200:
|
||||
description: What has been modified
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
is_selected:
|
||||
description: Add or remove this package from remote holdings
|
||||
type: boolean
|
||||
additionalProperties: false
|
||||
401:
|
||||
description: Authentication required
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
403:
|
||||
description: Access forbidden
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
404:
|
||||
description: Package not found
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
500:
|
||||
description: |-
|
||||
Internal server error. Possible `error_code` attribute values:
|
||||
* `internal_server_error`
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
503:
|
||||
description: Under maintenance
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
x-koha-authorization:
|
||||
permissions:
|
||||
erm: 1
|
||||
|
|
|
|||
|
|
@ -3,6 +3,23 @@
|
|||
<div v-else-if="erm_package" id="packages_show">
|
||||
<h2>
|
||||
{{ $t("Package .id", { id: erm_package.package_id }) }}
|
||||
<span v-if="!updating_is_selected">
|
||||
<a
|
||||
v-if="!erm_package.is_selected"
|
||||
class="btn btn-default btn-xs"
|
||||
role="button"
|
||||
@click="add_to_holdings"
|
||||
><font-awesome-icon icon="plus" /> Add to holdings</a
|
||||
>
|
||||
<a
|
||||
v-else
|
||||
class="btn btn-default btn-xs"
|
||||
role="button"
|
||||
id="remove-from-holdings"
|
||||
@click="remove_from_holdings"
|
||||
><font-awesome-icon icon="minus" /> Remove from holdings</a
|
||||
> </span
|
||||
><span v-else><font-awesome-icon icon="spinner" /></span>
|
||||
</h2>
|
||||
<div>
|
||||
<fieldset class="rows">
|
||||
|
|
@ -89,7 +106,7 @@
|
|||
import EHoldingsPackageAgreements from "./EHoldingsEBSCOPackageAgreements.vue"
|
||||
import EHoldingsPackageTitlesList from "./EHoldingsEBSCOPackageTitlesList.vue"
|
||||
import { useAVStore } from "../../stores/authorised_values"
|
||||
import { fetchEBSCOPackage } from "../../fetch"
|
||||
import { fetchEBSCOPackage, checkError } from "../../fetch"
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
|
|
@ -118,6 +135,7 @@ export default {
|
|||
package_agreements: [],
|
||||
},
|
||||
initialized: false,
|
||||
updating_is_selected: false,
|
||||
}
|
||||
},
|
||||
beforeRouteEnter(to, from, next) {
|
||||
|
|
@ -133,6 +151,35 @@ export default {
|
|||
const erm_package = await fetchEBSCOPackage(package_id)
|
||||
this.erm_package = erm_package
|
||||
this.initialized = true
|
||||
this.updating_is_selected = false
|
||||
},
|
||||
edit_selected(is_selected) {
|
||||
this.updating_is_selected = true
|
||||
fetch('/api/v1/erm/eholdings/ebsco/packages/' + this.erm_package.package_id, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ is_selected }),
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
})
|
||||
.then(checkError)
|
||||
.then(
|
||||
(result) => {
|
||||
// Refresh the page. We should not need that actually.
|
||||
this.getPackage(this.erm_package.package_id)
|
||||
},
|
||||
).catch(
|
||||
(error) => {
|
||||
setError(error)
|
||||
}
|
||||
)
|
||||
},
|
||||
add_to_holdings() {
|
||||
this.edit_selected(true)
|
||||
},
|
||||
remove_from_holdings() {
|
||||
this.edit_selected(false)
|
||||
},
|
||||
refreshAgreements() {
|
||||
// FIXME We could GET /erm/eholdings/packages/$package_id/agreements instead
|
||||
|
|
@ -151,4 +198,4 @@ export default {
|
|||
fieldset.rows label {
|
||||
width: 25rem;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue