From 852d5d51320ad35eba3a9a31d70a9ce4146572ad Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 May 2022 20:01:02 +0200 Subject: [PATCH] Bug 32030: ERM - related agreement - Vue 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 | 34 +++++ cypress/integration/Agreements_spec.ts | 1 + .../components/ERM/AgreementRelationships.vue | 116 ++++++++++++++++++ .../vue/components/ERM/AgreementsFormAdd.vue | 14 +++ .../js/vue/components/ERM/AgreementsShow.vue | 26 ++++ koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 2 +- .../prog/js/vue/stores/authorised_values.js | 23 ++++ 7 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index 611906a282..fa789d6e86 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -123,12 +123,32 @@ sub agreement_relationships { if ( $relationships ) { my $schema = $self->_result->result_source->schema; + # FIXME naming - is "back link" ok? + my $back_links = { + 'supersedes' => 'is-superseded-by', + 'is-superseded-by' => 'supersedes', + 'provides_post-cancellation_access_for' => 'has-post-cancellation-access-in', + 'has-post-cancellation-access-in' => 'provides_post-cancellation_access_for', + 'tracks_demand-driven_acquisitions_for' => 'has-demand-driven-acquisitions-in', + 'has-demand-driven-acquisitions-in' => 'tracks_demand-driven_acquisitions_for', + 'has_backfile_in' => 'has_frontfile_in', + 'has_frontfile_in' => 'has_backfile_in', + 'related_to' => 'related_to', + }; $schema->txn_do( sub { $self->agreement_relationships->delete; + $self->agreement_back_relationships->delete; for my $relationship (@$relationships) { $self->_result->add_to_erm_agreement_relationships_agreements($relationship); + my $back_link = { + agreement_id => $relationship->{related_agreement_id}, + related_agreement_id => $self->agreement_id, + relationship => $back_links->{$relationship->{relationship}}, + notes => $relationship->{notes}, # FIXME Is it correct, do we keep the note here? + }; + $self->_result->add_to_erm_agreement_relationships_related_agreements($back_link); } } ); @@ -137,6 +157,20 @@ sub agreement_relationships { return Koha::ERM::Agreement::Relationships->_new_from_dbic($related_agreements_rs); } +=head3 agreement_back_relationships + +# FIXME Naming - how is it called? +Returns the reverse relationship + +=cut + +sub agreement_back_relationships { + my ( $self ) = @_; + my $rs = $self->_result->erm_agreement_relationships_related_agreements; + return Koha::ERM::Agreement::Relationships->_new_from_dbic($rs); +} + + =head2 Internal methods =head3 _type diff --git a/cypress/integration/Agreements_spec.ts b/cypress/integration/Agreements_spec.ts index 0a6c030d16..873021896b 100644 --- a/cypress/integration/Agreements_spec.ts +++ b/cypress/integration/Agreements_spec.ts @@ -35,6 +35,7 @@ function get_agreement() { ], user_roles: [], agreement_licenses: [], + agreement_relationships: [], }; } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue new file mode 100644 index 0000000000..a475e4c1df --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue @@ -0,0 +1,116 @@ + + + \ 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 4c012c824f..1e7cff7bda 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 @@ -179,6 +179,13 @@ av_agreement_license_location " /> +
@@ -199,6 +206,7 @@ import AgreementPeriods from './AgreementPeriods.vue' import AgreementUserRoles from './AgreementUserRoles.vue' import AgreementLicenses from './AgreementLicenses.vue' +import AgreementRelationships from './AgreementRelationships.vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" import { setMessage, setError } from "../../messages" @@ -217,6 +225,7 @@ export default { av_agreement_user_roles, av_agreement_license_statuses, av_agreement_license_location, + av_agreement_relationships, } = storeToRefs(AVStore) return { @@ -227,6 +236,7 @@ export default { av_agreement_user_roles, av_agreement_license_statuses, av_agreement_license_location, + av_agreement_relationships, } }, data() { @@ -244,6 +254,7 @@ export default { periods: [], user_roles: [], agreement_licenses: [], + agreement_relationships: [], }, initialized: false, } @@ -290,6 +301,8 @@ export default { agreement.agreement_licenses = agreement.agreement_licenses.map(({ license, agreement_id, agreement_license_id, ...keepAttrs }) => keepAttrs) + agreement.agreement_relationships = agreement.agreement_relationships.map(({ related_agreement, ...keepAttrs }) => keepAttrs) + const options = { method: method, body: JSON.stringify(agreement), @@ -328,6 +341,7 @@ export default { AgreementPeriods, AgreementUserRoles, AgreementLicenses, + AgreementRelationships, }, name: "AgreementsFormAdd", } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue index cc8336c4eb..f2fbf44bda 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue @@ -166,6 +166,30 @@ + +
  • + +
    + {{ + relationship.related_agreement.name + }} + {{ + get_lib_from_av( + av_agreement_relationships, + relationship.relationship + ) + }} + {{ agreement.name }} +
    +
  • @@ -209,6 +233,7 @@ export default { av_agreement_user_roles, av_agreement_license_statuses, av_agreement_license_location, + av_agreement_relationships, } = storeToRefs(AVStore) return { @@ -222,6 +247,7 @@ export default { av_agreement_user_roles, av_agreement_license_statuses, av_agreement_license_location, + av_agreement_relationships, } }, data() { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js index 1b02ba556b..9a11469eed 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", + "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement", }, }) .then((res) => res.json()) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js index 287e027ca5..845a55602b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js @@ -10,6 +10,29 @@ export const useAVStore = defineStore("authorised_values", { av_license_statuses: [], av_agreement_license_statuses: [], av_agreement_license_location: [], + av_agreement_relationships: [ + { authorised_value: "supersedes", lib: "supersedes" }, + { authorised_value: "is-superseded-by", lib: "is superseded by" }, + { + authorised_value: "provides_post-cancellation_access_for", + lib: "provides_post-cancellation_access_for", + }, + { + authorised_value: "has-post-cancellation-access-in", + lib: "has-post-cancellation-access-in", + }, + { + authorised_value: "tracks_demand-driven_acquisitions_for", + lib: "tracks_demand-driven_acquisitions_for", + }, + { + authorised_value: "has-demand-driven-acquisitions-in", + lib: "has-demand-driven-acquisitions-in", + }, + { authorised_value: "has_backfile_in", lib: "has_backfile_in" }, + { authorised_value: "has_frontfile_in", lib: "has_frontfile_in" }, + { authorised_value: "related_to", lib: "related_to" }, + ], }), // FIXME We could move get_lib_from_av here }); -- 2.39.5