Bug 32030: ERM - related agreement - Vue

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-12 20:01:02 +02:00 committed by Tomas Cohen Arazi
parent 0e4afcc28e
commit 852d5d5132
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
7 changed files with 215 additions and 1 deletions

View file

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

View file

@ -35,6 +35,7 @@ function get_agreement() {
],
user_roles: [],
agreement_licenses: [],
agreement_relationships: [],
};
}

View file

@ -0,0 +1,116 @@
<template>
<fieldset class="rows" id="agreement_relationships">
<legend>Related agreements</legend>
<fieldset
class="rows"
v-for="(relationship, counter) in relationships"
v-bind:key="counter"
>
<legend>
Related agreement {{ counter + 1 }}
<a href="#" @click.prevent="deleteRelationship(counter)"
><i class="fa fa-trash"></i> Remove this relationship</a
>
</legend>
<ol>
<li>
<label :for="`related_agreement_id_${counter}`"
>Related agreement:
</label>
<select
v-model="relationship.related_agreement_id"
:id="`related_agreement_id_${counter}`"
>
<option value=""></option>
<option
v-for="agreement in agreements"
:key="agreement.agreement_id"
:value="agreement.agreement_id"
:selected="
agreement.agreement_id ==
relationship.related_agreement_id
? true
: false
"
>
{{ agreement.name }}
</option>
</select>
</li>
<li>
<label :for="`related_agreement_relationship_${counter}`"
>Relationship:
</label>
<select
v-model="relationship.relationship"
:id="`related_agreement_relationship_${counter}`"
required
>
<option value=""></option>
<option
v-for="r in av_agreement_relationships"
:key="r.authorised_values"
:value="r.authorised_value"
:selected="
r.authorised_value == relationship.relationship
? true
: false
"
>
{{ r.lib }}
</option>
</select>
<span class="required">Required</span>
</li>
<li>
<label :for="`related_agreement_notes${counter}`"
>Notes:</label
>
<input
:id="`related_agreement_notes_${counter}`"
v-model="relationship.notes"
placeholder="Notes"
/>
</li>
</ol>
</fieldset>
<a class="btn btn-default" @click="addRelationship"
><font-awesome-icon icon="plus" /> Add new related agreement</a
>
</fieldset>
</template>
<script>
import { fetchAgreements } from "../../fetch"
export default {
data() {
return {
agreements: [],
}
},
beforeCreate() {
fetchAgreements().then((agreements) => {
this.agreements = agreements.filter((agreement) => agreement.agreement_id !== this.agreement_id)
})
},
methods: {
addRelationship() {
this.relationships.push({
related_agreement_id: null,
relationship: null,
notes: '',
})
},
deleteRelationship(counter) {
this.relationships.splice(counter, 1)
},
},
props: {
agreement_id: Number,
av_agreement_relationships: Array,
relationships: Array,
},
name: 'AgreementRelationships',
}
</script>

View file

@ -179,6 +179,13 @@
av_agreement_license_location
"
/>
<AgreementRelationships
:agreement_id="agreement.agreement_id"
:relationships="agreement.agreement_relationships"
:av_agreement_relationships="
av_agreement_relationships
"
/>
</ol>
</fieldset>
<fieldset class="action">
@ -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",
}

View file

@ -166,6 +166,30 @@
</tbody>
</table>
</li>
<li>
<label>Related agreements</label>
<div
v-for="relationship in agreement.agreement_relationships"
v-bind:key="relationship.related_agreement_id"
>
<span
><router-link
:to="`/cgi-bin/koha/erm/agreements/${relationship.related_agreement.agreement_id}`"
>{{
relationship.related_agreement.name
}}</router-link
></span
>
{{
get_lib_from_av(
av_agreement_relationships,
relationship.relationship
)
}}
{{ agreement.name }}
</div>
</li>
</ol>
</fieldset>
<fieldset class="action">
@ -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() {

View file

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

View file

@ -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
});