From ff2bf0d5a350336b6c11ba149e62e1becdd329d0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 May 2022 16:13:14 +0200 Subject: [PATCH] Bug 32030: ERM - link licenses to an agreement Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Agreement.pm | 26 ++++ Koha/ERM/Agreement/License.pm | 4 +- Koha/REST/V1/ERM/Agreements.pm | 4 + api/v1/swagger/definitions/erm_agreement.yaml | 6 + .../definitions/erm_agreement_license.yaml | 30 ++++ .../definitions/erm_license_agreement.yaml | 1 - api/v1/swagger/paths/erm_agreements.yaml | 3 + .../intranet-tmpl/prog/en/modules/erm/erm.tt | 3 + .../vue/components/ERM/AgreementLicenses.vue | 147 ++++++++++++++++++ .../vue/components/ERM/AgreementUserRoles.vue | 4 +- .../prog/js/vue/components/ERM/Agreements.vue | 36 +++-- .../vue/components/ERM/AgreementsFormAdd.vue | 39 +++-- .../js/vue/components/ERM/AgreementsList.vue | 41 ++--- .../js/vue/components/ERM/AgreementsShow.vue | 10 +- .../prog/js/vue/components/ERM/Licenses.vue | 16 +- .../js/vue/components/ERM/LicensesFormAdd.vue | 8 +- .../js/vue/components/ERM/LicensesList.vue | 20 +-- .../js/vue/components/ERM/LicensesShow.vue | 8 +- 18 files changed, 324 insertions(+), 82 deletions(-) create mode 100644 api/v1/swagger/definitions/erm_agreement_license.yaml create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index 5ca06e3be8..1e4c073562 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -23,6 +23,7 @@ use base qw(Koha::Object); use Koha::ERM::Agreement::Periods; use Koha::ERM::Agreement::UserRoles; +use Koha::ERM::Agreement::Licenses; =head1 NAME @@ -85,6 +86,31 @@ sub user_roles { return Koha::ERM::Agreement::UserRoles->_new_from_dbic($user_roles_rs); } +=head3 agreement_licenses + +Returns the agreement_licenses for this agreement + +=cut + +sub agreement_licenses { + my ( $self, $agreement_licenses ) = @_; + + if ( $agreement_licenses ) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->agreement_licenses->delete; + + for my $agreement_license (@$agreement_licenses) { + $self->_result->add_to_erm_agreement_licenses($agreement_license); + } + } + ); + } + my $agreement_licenses_rs = $self->_result->erm_agreement_licenses; + return Koha::ERM::Agreement::Licenses->_new_from_dbic($agreement_licenses_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/Agreement/License.pm b/Koha/ERM/Agreement/License.pm index 9f34ae4b94..35ae9c3a3f 100644 --- a/Koha/ERM/Agreement/License.pm +++ b/Koha/ERM/Agreement/License.pm @@ -19,8 +19,8 @@ use Modern::Perl; use Koha::Database; -use Koha::Agreements; -use Koha::Licenses; +use Koha::ERM::Agreements; +use Koha::ERM::Licenses; use base qw(Koha::Object); diff --git a/Koha/REST/V1/ERM/Agreements.pm b/Koha/REST/V1/ERM/Agreements.pm index 999881f180..09110f5f62 100644 --- a/Koha/REST/V1/ERM/Agreements.pm +++ b/Koha/REST/V1/ERM/Agreements.pm @@ -93,10 +93,12 @@ sub add { my $periods = delete $body->{periods} // []; my $user_roles = delete $body->{user_roles} // []; + my $agreement_licenses = delete $body->{agreement_licenses} // []; my $agreement = Koha::ERM::Agreement->new_from_api($body)->store; $agreement->periods($periods); $agreement->user_roles($user_roles); + $agreement->agreement_licenses($agreement_licenses); $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id); return $c->render( @@ -170,10 +172,12 @@ sub update { my $periods = delete $body->{periods} // []; my $user_roles = delete $body->{user_roles} // []; + my $agreement_licenses = delete $body->{agreement_licenses} // []; $agreement->set_from_api($body)->store; $agreement->periods($periods); $agreement->user_roles($user_roles); + $agreement->agreement_licenses($agreement_licenses); $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id); return $c->render( diff --git a/api/v1/swagger/definitions/erm_agreement.yaml b/api/v1/swagger/definitions/erm_agreement.yaml index 7451901d90..2c23a499c8 100644 --- a/api/v1/swagger/definitions/erm_agreement.yaml +++ b/api/v1/swagger/definitions/erm_agreement.yaml @@ -49,6 +49,12 @@ properties: description: role for users items: $ref: erm_agreement_user_role.yaml + agreement_licenses: + type: array + description: agreement licenses + items: + $ref: erm_agreement_license.yaml + additionalProperties: false required: - agreement_id diff --git a/api/v1/swagger/definitions/erm_agreement_license.yaml b/api/v1/swagger/definitions/erm_agreement_license.yaml new file mode 100644 index 0000000000..69ca7227a5 --- /dev/null +++ b/api/v1/swagger/definitions/erm_agreement_license.yaml @@ -0,0 +1,30 @@ +--- +type: object +properties: + agreement_license_id: + type: integer + description: Internal agreement license identifier + agreement_id: + type: integer + description: Internal agreement identifier + license_id: + type: integer + description: Internal license identifier + status: + type: string + physical_location: + type: + - string + - "null" + notes: + type: + - string + - "null" + uri: + type: + - string + - "null" +additionalProperties: false +required: + - license_id + - status diff --git a/api/v1/swagger/definitions/erm_license_agreement.yaml b/api/v1/swagger/definitions/erm_license_agreement.yaml index 873bc9bd78..c99847a3e6 100644 --- a/api/v1/swagger/definitions/erm_license_agreement.yaml +++ b/api/v1/swagger/definitions/erm_license_agreement.yaml @@ -31,4 +31,3 @@ properties: additionalProperties: false required: - license_id - - agreement_id diff --git a/api/v1/swagger/paths/erm_agreements.yaml b/api/v1/swagger/paths/erm_agreements.yaml index 0db0606392..8c2c31bf68 100644 --- a/api/v1/swagger/paths/erm_agreements.yaml +++ b/api/v1/swagger/paths/erm_agreements.yaml @@ -187,6 +187,8 @@ - periods - user_roles - user_roles.patron + - agreement_licenses + - agreement_licenses.license put: x-mojo-to: ERM::Agreements#update operationId: updateErmAgreements @@ -244,6 +246,7 @@ x-koha-embed: - periods - user_roles + - agreement_licenses delete: x-mojo-to: ERM::Agreements#delete operationId: deleteErmAgreements diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt index 2960f8d670..f6f75b2aab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/erm.tt @@ -60,6 +60,9 @@ licenses_table_url += 'q='+ encodeURIComponent(JSON.stringify(license_name_filter)); [% END %] + const agreement_license_statuses = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_LICENSE_STATUS')) | $raw %]; + const agreement_license_location = [% To.json(AuthorisedValues.Get('ERM_AGREEMENT_LICENSE_LOCATION')) | $raw %]; + [% Asset.js("js/vue/dist/main.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue new file mode 100644 index 0000000000..70a7d50c06 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue @@ -0,0 +1,147 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue index 4c8759ac5c..7257eeba24 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementUserRoles.vue @@ -30,7 +30,7 @@ - Cancel @@ -178,6 +188,7 @@