From 94ef7c6865ad7b69c91f308894f7eb653bfa1638 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 May 2022 18:35:20 +0200 Subject: [PATCH] Bug 32030: ERM - Documents - FIXME This needs to be continued... * show view * download the documents * don't embed the document content 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 | 29 ++++ Koha/ERM/Agreement/Document.pm | 44 +++++ Koha/ERM/Agreement/Documents.pm | 49 ++++++ Koha/REST/V1/ERM/Agreements.pm | 4 + cypress/integration/Agreements_spec.ts | 1 + .../vue/components/ERM/AgreementDocuments.vue | 151 ++++++++++++++++++ .../vue/components/ERM/AgreementsFormAdd.vue | 6 + koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 2 +- 8 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 Koha/ERM/Agreement/Document.pm create mode 100644 Koha/ERM/Agreement/Documents.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementDocuments.vue diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index fa789d6e86..9aeaa90345 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -18,6 +18,7 @@ package Koha::ERM::Agreement; use Modern::Perl; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use base qw(Koha::Object); @@ -25,6 +26,7 @@ use Koha::ERM::Agreement::Periods; use Koha::ERM::Agreement::UserRoles; use Koha::ERM::Agreement::Licenses; use Koha::ERM::Agreement::Relationships; +use Koha::ERM::Agreement::Documents; =head1 NAME @@ -170,6 +172,33 @@ sub agreement_back_relationships { return Koha::ERM::Agreement::Relationships->_new_from_dbic($rs); } +=head3 documents + +Returns the documents for this agreement + +=cut + +sub documents { + my ( $self, $documents ) = @_; + + if ($documents) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->documents->delete; + for my $document (@$documents) { + if ( $document->{file_content} ) { + $document->{file_type} = 'unknown'; # FIXME How to detect file type from base64? + $document->{uploaded_on} //= dt_from_string; + } + $self->_result->add_to_erm_agreement_documents($document); + } + } + ); + } + my $documents_rs = $self->_result->erm_agreement_documents; + return Koha::ERM::Agreement::Documents->_new_from_dbic($documents_rs); +} =head2 Internal methods diff --git a/Koha/ERM/Agreement/Document.pm b/Koha/ERM/Agreement/Document.pm new file mode 100644 index 0000000000..41cae26ac7 --- /dev/null +++ b/Koha/ERM/Agreement/Document.pm @@ -0,0 +1,44 @@ +package Koha::ERM::Agreement::Document; + +# 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 base qw(Koha::Object); + +=head1 NAME + +Koha::ERM::Agreement::Document - Koha Agreement Document Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'ErmAgreementDocument'; +} + +1; diff --git a/Koha/ERM/Agreement/Documents.pm b/Koha/ERM/Agreement/Documents.pm new file mode 100644 index 0000000000..73aee775fa --- /dev/null +++ b/Koha/ERM/Agreement/Documents.pm @@ -0,0 +1,49 @@ +package Koha::ERM::Agreement::Documents; + +# 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::Agreement::Document; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ERM::Agreement::Documents- Koha Agreement Document Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ErmAgreementDocument'; +} + +sub object_class { + return 'Koha::ERM::Agreement::Document'; +} + +1; diff --git a/Koha/REST/V1/ERM/Agreements.pm b/Koha/REST/V1/ERM/Agreements.pm index 3d64e95609..53fda67988 100644 --- a/Koha/REST/V1/ERM/Agreements.pm +++ b/Koha/REST/V1/ERM/Agreements.pm @@ -95,12 +95,14 @@ sub add { my $user_roles = delete $body->{user_roles} // []; my $agreement_licenses = delete $body->{agreement_licenses} // []; my $agreement_relationships = delete $body->{agreement_relationships} // []; + my $documents = delete $body->{documents} // []; my $agreement = Koha::ERM::Agreement->new_from_api($body)->store; $agreement->periods($periods); $agreement->user_roles($user_roles); $agreement->agreement_licenses($agreement_licenses); $agreement->agreement_relationships($agreement_relationships); + $agreement->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id); return $c->render( @@ -176,12 +178,14 @@ sub update { my $user_roles = delete $body->{user_roles} // []; my $agreement_licenses = delete $body->{agreement_licenses} // []; my $agreement_relationships = delete $body->{agreement_relationships} // []; + my $documents = delete $body->{documents} // []; $agreement->set_from_api($body)->store; $agreement->periods($periods); $agreement->user_roles($user_roles); $agreement->agreement_licenses($agreement_licenses); $agreement->agreement_relationships($agreement_relationships); + $agreement->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id); return $c->render( diff --git a/cypress/integration/Agreements_spec.ts b/cypress/integration/Agreements_spec.ts index 873021896b..493dcebe92 100644 --- a/cypress/integration/Agreements_spec.ts +++ b/cypress/integration/Agreements_spec.ts @@ -36,6 +36,7 @@ function get_agreement() { user_roles: [], agreement_licenses: [], agreement_relationships: [], + documents: [], }; } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementDocuments.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementDocuments.vue new file mode 100644 index 0000000000..e528995c8d --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementDocuments.vue @@ -0,0 +1,151 @@ + + + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue index 1e7cff7bda..3997d220d0 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue @@ -186,6 +186,7 @@ av_agreement_relationships " /> +
@@ -207,6 +208,7 @@ import AgreementPeriods from './AgreementPeriods.vue' import AgreementUserRoles from './AgreementUserRoles.vue' import AgreementLicenses from './AgreementLicenses.vue' import AgreementRelationships from './AgreementRelationships.vue' +import AgreementDocuments from './AgreementDocuments.vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" import { setMessage, setError } from "../../messages" @@ -255,6 +257,7 @@ export default { user_roles: [], agreement_licenses: [], agreement_relationships: [], + documents: [], }, initialized: false, } @@ -303,6 +306,8 @@ export default { agreement.agreement_relationships = agreement.agreement_relationships.map(({ related_agreement, ...keepAttrs }) => keepAttrs) + agreement.documents = agreement.documents.map(({ document_id, ...keepAttrs }) => keepAttrs) + const options = { method: method, body: JSON.stringify(agreement), @@ -342,6 +347,7 @@ export default { AgreementUserRoles, AgreementLicenses, AgreementRelationships, + AgreementDocuments, }, name: "AgreementsFormAdd", } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js index 9a11469eed..2c1c551ba2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js @@ -7,7 +7,7 @@ export const fetchAgreement = async function (agreement_id) { await fetch(apiUrl, { headers: { "x-koha-embed": - "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement", + "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents", }, }) .then((res) => res.json()) -- 2.39.5