From febaedb7a2af6a46b69e7a5ea4651ac7c6201cbf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 11 Jul 2024 15:55:38 +0200 Subject: [PATCH] Bug 37301: Remove toToResource* methods to BaseResource --- .../prog/js/vue/components/BaseResource.vue | 37 +++++++++++++++++-- .../vue/components/ERM/AgreementResource.vue | 26 ++++--------- .../js/vue/components/ERM/AgreementsList.vue | 7 +--- .../js/vue/components/ERM/AgreementsShow.vue | 10 ++++- .../prog/js/vue/components/ToolbarButton.vue | 11 ++++-- 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue index 701b1056cf1..1c782bc44ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue @@ -2,15 +2,46 @@ import { inject } from "vue" export default { - setup() { + setup(props) { //global setup for all resource (list and show for now, but maybe others?) components here const { setConfirmationDialog, setMessage, setError } = inject("mainStore") - return { setConfirmationDialog, setMessage, setError } + return { ...props, setConfirmationDialog, setMessage, setError } }, methods: { - // goToResourceEdit: function () {}, + /** + * Navigates to the edit page of the given resource. + * + * @param {Object} resource - The resource to navigate to (optional) + * @return {void} + */ + goToResourceEdit: function (resource) { + this.$router.push({ + name: this.edit_component, + params: { + [this.id_attr]: resource + ? resource[this.id_attr] + : this[this.resource_name][this.id_attr], + }, + }) + }, + /** + * Navigates to the creation page of the given resource. + * + * @return {void} + */ + goToResourceAdd: function () { + this.$router.push({ + name: this.add_component, + }) + }, }, name: "BaseResource", + props: { + resource_name: String, + id_attr: String, + add_component: String, + edit_component: String, + }, } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementResource.vue index 5442eee1efb..a05a0f028f8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementResource.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementResource.vue @@ -3,28 +3,18 @@ import BaseResource from "../BaseResource.vue" export default { extends: BaseResource, - setup() { + setup(props) { return { - ...BaseResource.setup(), + ...BaseResource.setup({ + resource_name: "agreement", + id_attr: "agreement_id", + add_component: "AgreementsFormAdd", + edit_component: "AgreementsFormAddEdit", + }), //AgreementResource specific setup here } }, - methods: { - /** - * Navigates to the edit page of the given agreement. - * - * @param {Object} agreement - The agreement to navigate to (optional) - * @return {void} - */ - goToResourceEdit: function (agreement) { - let agreement_id = - agreement?.agreement_id || this.agreement.agreement_id - this.$router.push({ - name: "AgreementsFormAddEdit", - params: { agreement_id: agreement_id }, - }) - }, - }, + methods: {}, name: "AgreementResource", } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue index c14bf3eb210..d80577111f3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue @@ -4,7 +4,7 @@ @@ -173,11 +173,6 @@ export default { error => {} ) }, - add_agreement: function () { - this.$router.push({ - name: "AgreementsFormAdd", - }) - }, doShow: function ({ agreement_id }, dt, event) { event.preventDefault() this.$router.push({ 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 766269a99a9..ff415663023 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 @@ -2,8 +2,14 @@
{{ $__("Loading") }}
- - + +

diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue index d6c535284fc..c6b28d2712a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue @@ -1,16 +1,19 @@