From bdee83ef937262cfd504edb643f9b32bbcf8ad41 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 25 May 2022 13:33:35 +0200 Subject: [PATCH] Bug 32030: Link eHolding with packages Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/EHolding.pm | 28 ++++- Koha/ERM/EHolding/Package.pm | 58 +++++++++ Koha/ERM/EHolding/Packages.pm | 49 ++++++++ Koha/REST/V1/ERM/EHoldings.pm | 8 ++ api/v1/swagger/definitions/erm_eholding.yaml | 5 + .../definitions/erm_eholding_package.yaml | 27 ++++ api/v1/swagger/paths/erm_eholdings.yaml | 6 +- .../vue/components/ERM/EHoldingPackages.vue | 117 ++++++++++++++++++ .../vue/components/ERM/EHoldingsFormAdd.vue | 7 ++ koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 6 +- 10 files changed, 306 insertions(+), 5 deletions(-) create mode 100644 Koha/ERM/EHolding/Package.pm create mode 100644 Koha/ERM/EHolding/Packages.pm create mode 100644 api/v1/swagger/definitions/erm_eholding_package.yaml create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingPackages.vue diff --git a/Koha/ERM/EHolding.pm b/Koha/ERM/EHolding.pm index 1af43cda8b..058bda1abb 100644 --- a/Koha/ERM/EHolding.pm +++ b/Koha/ERM/EHolding.pm @@ -21,8 +21,7 @@ use Koha::Database; use base qw(Koha::Object); -use Koha::ERM::Packages; -use Koha::Acquisition::Booksellers; +use Koha::ERM::EHolding::Packages; =head1 NAME @@ -32,6 +31,31 @@ Koha::ERM::EHolding - Koha ERM EHolding Object class =head2 Class Methods +=head3 eholding_packages + +Returns the eholding_packages link for this eHolding + +=cut + +sub eholding_packages { + my ( $self, $eholding_packages ) = @_; + + if ( $eholding_packages ) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->eholding_packages->delete; + + for my $eholding_package (@$eholding_packages) { + $self->_result->add_to_erm_eholdings_packages($eholding_package); + } + } + ); + } + my $eholding_packages_rs = $self->_result->erm_eholdings_packages; + return Koha::ERM::EHolding::Packages->_new_from_dbic($eholding_packages_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/EHolding/Package.pm b/Koha/ERM/EHolding/Package.pm new file mode 100644 index 0000000000..0f9e04a357 --- /dev/null +++ b/Koha/ERM/EHolding/Package.pm @@ -0,0 +1,58 @@ +package Koha::ERM::EHolding::Package; + +# 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 . + +use Modern::Perl; + +use Koha::Database; + +use Koha::ERM::Package; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::ERM::EHolding::Package - Koha EHolding Package Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 package + +Return the package for this link + +=cut + +sub package { + my ( $self ) = @_; + my $package_rs = $self->_result->package; + return Koha::ERM::Package->_new_from_dbic($package_rs); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'ErmEholdingsPackage'; +} + +1; diff --git a/Koha/ERM/EHolding/Packages.pm b/Koha/ERM/EHolding/Packages.pm new file mode 100644 index 0000000000..46d1ba60b2 --- /dev/null +++ b/Koha/ERM/EHolding/Packages.pm @@ -0,0 +1,49 @@ +package Koha::ERM::EHolding::Packages; + +# 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 . + +use Modern::Perl; + + +use Koha::Database; + +use Koha::ERM::EHolding::Package; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ERM::EHolding::Packages- Koha EHolding EHolding Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ErmEholdingsPackage'; +} + +sub object_class { + return 'Koha::ERM::EHolding::Package'; +} + +1; diff --git a/Koha/REST/V1/ERM/EHoldings.pm b/Koha/REST/V1/ERM/EHoldings.pm index 01acab0b14..8860940652 100644 --- a/Koha/REST/V1/ERM/EHoldings.pm +++ b/Koha/REST/V1/ERM/EHoldings.pm @@ -91,8 +91,12 @@ sub add { my $body = $c->validation->param('body'); + my $eholding_packages = delete $body->{eholding_packages} // []; + my $eholding = Koha::ERM::EHolding->new_from_api($body)->store; + $eholding->eholding_packages($eholding_packages); + $c->res->headers->location($c->req->url->to_string . '/' . $eholding->eholding_id); return $c->render( status => 201, @@ -163,8 +167,12 @@ sub update { my $body = $c->validation->param('body'); + my $eholding_packages = delete $body->{eholding_packages} // []; + $eholding->set_from_api($body)->store; + $eholding->eholding_packages($eholding_packages); + $c->res->headers->location($c->req->url->to_string . '/' . $eholding->eholding_id); return $c->render( status => 200, diff --git a/api/v1/swagger/definitions/erm_eholding.yaml b/api/v1/swagger/definitions/erm_eholding.yaml index ce7417cbf5..36ce4b74e9 100644 --- a/api/v1/swagger/definitions/erm_eholding.yaml +++ b/api/v1/swagger/definitions/erm_eholding.yaml @@ -128,6 +128,11 @@ properties: type: - string - "null" + eholding_packages: + type: array + description: packages containing this title + items: + $ref: erm_eholding_package.yaml additionalProperties: false required: diff --git a/api/v1/swagger/definitions/erm_eholding_package.yaml b/api/v1/swagger/definitions/erm_eholding_package.yaml new file mode 100644 index 0000000000..46fdc8a755 --- /dev/null +++ b/api/v1/swagger/definitions/erm_eholding_package.yaml @@ -0,0 +1,27 @@ +--- +type: object +properties: + eholding_id: + type: integer + description: Internal related eHolding identifier + package_id: + type: integer + description: Internal package identifier + started_on: + description: Start date + type: + - string + - "null" + ended_on: + description: End date + type: + - string + - "null" + proxy: + description: Proxy + type: + - string + - "null" +additionalProperties: false +required: + - package_id diff --git a/api/v1/swagger/paths/erm_eholdings.yaml b/api/v1/swagger/paths/erm_eholdings.yaml index de67b8ab64..b7d769d240 100644 --- a/api/v1/swagger/paths/erm_eholdings.yaml +++ b/api/v1/swagger/paths/erm_eholdings.yaml @@ -269,7 +269,8 @@ permissions: erm: 1 x-koha-embed: - - agreements + - eholding_packages + - eholding_packages.package put: x-mojo-to: ERM::EHoldings#update operationId: updateErmEHoldings @@ -324,7 +325,8 @@ permissions: erm: 1 x-koha-embed: - - agreements + - eholding_packages + - eholding_packages.package delete: x-mojo-to: ERM::EHoldings#delete operationId: deleteErmEHoldings diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingPackages.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingPackages.vue new file mode 100644 index 0000000000..62024c4793 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingPackages.vue @@ -0,0 +1,117 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsFormAdd.vue index d7ebb4885f..bdb3d0090c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsFormAdd.vue @@ -345,6 +345,10 @@ :placeholder="$t('Access type')" /> + +
@@ -362,6 +366,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js index 44e73796bf..d8b596df58 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js @@ -145,7 +145,11 @@ export const fetchEHolding = async function (eholding_id) { if (!eholding_id) return; const apiUrl = "/api/v1/erm/eholdings/" + eholding_id; let erm_eholding; - await fetch(apiUrl) + await fetch(apiUrl, { + headers: { + "x-koha-embed": "eholding_packages,eholding_packages.package", + }, + }) .then(checkError) .then( (result) => { -- 2.39.5