Bug 32030: Link eHolding with packages

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:
Jonathan Druart 2022-05-25 13:33:35 +02:00 committed by Tomas Cohen Arazi
parent 88b738828b
commit bdee83ef93
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
10 changed files with 306 additions and 5 deletions

View file

@ -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

View file

@ -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 <http://www.gnu.org/licenses>.
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;

View file

@ -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 <http://www.gnu.org/licenses>.
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;

View file

@ -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,

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,117 @@
<template>
<fieldset class="rows" id="eholding_packages">
<legend>{{ $t("Packages") }}</legend>
<fieldset
class="rows"
v-for="(eholding_package, counter) in eholding_packages"
v-bind:key="counter"
>
<legend>
{{ $t("Package.counter", { counter: counter + 1 }) }}
<a href="#" @click.prevent="deletePackage(counter)"
><i class="fa fa-trash"></i>
{{ $t("Remove from this package") }}</a
>
</legend>
<ol>
<li>
<label
:for="`eholding_package_id_${counter}`"
class="required"
>{{ $t("Package:") }}
</label>
<select
v-model="eholding_package.package_id"
:id="`eholding_package_id_${counter}`"
required
>
<option value=""></option>
<option
v-for="p in packages"
:key="p.package_id"
:value="p.package_id"
:selected="
p.package_id == eholding_package.package_id
? true
: false
"
>
{{ p.name }}
</option>
</select>
<span class="required">{{ $t("Required") }}</span>
</li>
<li>
<label :for="`started_on_${counter}`"
>{{ $t("Start date:") }}
</label>
<flat-pickr
:id="`started_on_${counter}`"
v-model="eholding_package.started_on"
:config="fp_config"
:data-date_to="`ended_on_${counter}`"
/>
</li>
<li>
<label :for="`ended_on_${counter}`">{{
$t("End date:")
}}</label>
<flat-pickr
:id="`ended_on_${counter}`"
v-model="eholding_package.ended_on"
:config="fp_config"
/>
</li>
<li>
<label :for="`${counter}`">{{ $t("Proxy:") }}</label>
<input
:id="`proxy_${counter}`"
v-model="eholding_package.proxy"
:placeholder="$t('Proxy')"
/>
</li>
</ol>
</fieldset>
<a v-if="packages.length" class="btn btn-default" @click="addPackage"
><font-awesome-icon icon="plus" />
{{ $t("Add to another package") }}</a
>
<span v-else>{{ $t("There are no packages created yet") }}</span>
</fieldset>
</template>
<script>
import flatPickr from 'vue-flatpickr-component'
import { fetchPackages } from "../../fetch"
export default {
data() {
return {
packages: [],
fp_config: flatpickr_defaults,
dates_fixed: 0,
}
},
beforeCreate() {
fetchPackages().then((packages) => this.packages = packages)
},
methods: {
addPackage() {
this.eholding_packages.push({
package_id: null,
started_on: null,
ended_on: null,
proxy: '',
})
},
deletePackage(counter) {
this.eholding_packages.splice(counter, 1)
},
},
props: {
eholding_packages: Array,
},
components: { flatPickr },
name: 'EHoldingPackages',
}
</script>

View file

@ -345,6 +345,10 @@
:placeholder="$t('Access type')"
/>
</li>
<EHoldingPackages
:eholding_packages="eholding.eholding_packages"
/>
</ol>
</fieldset>
<fieldset class="action">
@ -362,6 +366,7 @@
</template>
<script>
import EHoldingPackages from "./EHoldingPackages.vue"
import { setMessage, setError } from "../../messages"
import { fetchEHolding } from '../../fetch'
@ -397,6 +402,7 @@ export default {
parent_publication_title_id: '',
preceeding_publication_title_id: '',
access_type: '',
eholding_packages: [],
},
initialized: false,
}
@ -453,6 +459,7 @@ export default {
}).catch(e => { console.log(e) })
},
},
components: { EHoldingPackages },
name: "EHoldingsFormAdd",
}
</script>

View file

@ -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) => {