Bugzilla – Attachment 172713 Details for
Bug 37301
Further improve how we build Vue components
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37301: DRY delete
Bug-37301-DRY-delete.patch (text/plain), 8.78 KB, created by
Pedro Amorim
on 2024-10-14 11:54:12 UTC
(
hide
)
Description:
Bug 37301: DRY delete
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-10-14 11:54:12 UTC
Size:
8.78 KB
patch
obsolete
>From 575c26c44b342bf934c5095851427de10b7f18f9 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 14 Oct 2024 11:52:48 +0000 >Subject: [PATCH] Bug 37301: DRY delete > >--- > .../prog/js/vue/components/BaseResource.vue | 67 +++++++++++++++++++ > .../vue/components/ERM/AgreementResource.vue | 7 ++ > .../js/vue/components/ERM/AgreementsList.vue | 29 +------- > .../js/vue/components/ERM/AgreementsShow.vue | 32 +-------- > 4 files changed, 76 insertions(+), 59 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 65f93af2cef..3e083167012 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue >@@ -48,6 +48,73 @@ export default { > name: this.add_component, > }) > }, >+ /** >+ * Navigates to the list page of the given resource. >+ * >+ * @return {void} >+ */ >+ goToResourceList: function () { >+ this.$router.push({ >+ name: this.list_component, >+ }) >+ }, >+ /** >+ * Resource deletion handler. >+ * Accepts an optional callback function to run after deletion. >+ * If no callback is provided, does the following: >+ * - If deleting from show component, navigates to resource list component. >+ * - If deleting from resource list component, redraws the table. >+ * >+ * @param {Object} resource - The resource to delete (optional) >+ * @param {Object} callback - Callback to call after deletion (optional) >+ * @return {void} >+ */ >+ doResourceDelete: function (resource, callback) { >+ let resource_id = resource >+ ? resource[this.id_attr] >+ : this[this.resource_name][this.id_attr] >+ let resource_name = resource >+ ? resource[this.name_attr] >+ : this[this.resource_name][this.name_attr] >+ >+ this.setConfirmationDialog( >+ { >+ title: this.$__( >+ "Are you sure you want to remove this %s?" >+ ).format(this.i18n.display_name.toLowerCase()), >+ message: resource_name, >+ accept_label: this.$__("Yes, delete"), >+ cancel_label: this.$__("No, do not delete"), >+ }, >+ () => { >+ this.api_client.delete(resource_id).then( >+ success => { >+ this.setMessage( >+ this.$__("%s %s deleted").format( >+ this.i18n.display_name, >+ resource_name >+ ), >+ true >+ ) >+ if (typeof callback === "function") { >+ callback() >+ } else { >+ if ( >+ this.$options.name === this.list_component >+ ) { >+ this.$refs.table.redraw(this.table_url()) >+ } else if ( >+ this.$options.name === this.show_component >+ ) { >+ this.goToResourceList() >+ } >+ } >+ }, >+ error => {} >+ ) >+ } >+ ) >+ }, > }, > name: "BaseResource", > props: { >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 88025188146..6e0fd17327f 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 >@@ -1,5 +1,6 @@ > <script> > import BaseResource from "../BaseResource.vue" >+import { APIClient } from "../../fetch/api-client.js" > > export default { > extends: BaseResource, >@@ -7,10 +8,16 @@ export default { > return { > ...BaseResource.setup({ > resource_name: "agreement", >+ name_attr: "name", > id_attr: "agreement_id", > show_component: "AgreementsShow", >+ list_component: "AgreementsList", > add_component: "AgreementsFormAdd", > edit_component: "AgreementsFormAddEdit", >+ api_client: APIClient.erm.agreements, >+ i18n: { >+ display_name: __("Agreement"), >+ }, > }), > //AgreementResource specific setup here > } >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 86c5aa6a425..58a8ef19963 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 >@@ -45,7 +45,7 @@ > v-bind="tableOptions" > @show="goToResourceShow" > @edit="goToResourceEdit" >- @delete="doDelete" >+ @delete="doResourceDelete" > @select="doSelect" > ></KohaTable> > </div> >@@ -173,33 +173,6 @@ export default { > error => {} > ) > }, >- doDelete: function (agreement, dt, event) { >- this.setConfirmationDialog( >- { >- title: this.$__( >- "Are you sure you want to remove this agreement?" >- ), >- message: agreement.name, >- accept_label: this.$__("Yes, delete"), >- cancel_label: this.$__("No, do not delete"), >- }, >- () => { >- const client = APIClient.erm >- client.agreements.delete(agreement.agreement_id).then( >- success => { >- this.setMessage( >- this.$__("Agreement %s deleted").format( >- agreement.name >- ), >- true >- ) >- dt.draw() >- }, >- error => {} >- ) >- } >- ) >- }, > doSelect: function (agreement, dt, event) { > this.$emit("select-agreement", agreement.agreement_id) > this.$emit("close") >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 ff415663023..b83b752cc2f 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 >@@ -8,7 +8,7 @@ > /> > <ToolbarButton > action="delete" >- @delete_resource="delete_agreement" >+ @delete-resource="doResourceDelete" > /> > </Toolbar> > >@@ -388,36 +388,6 @@ export default { > error => {} > ) > }, >- delete_agreement: function () { >- let agreement_id = this.agreement.agreement_id >- let agreement_name = this.agreement.name >- >- this.setConfirmationDialog( >- { >- title: this.$__( >- "Are you sure you want to remove this agreement?" >- ), >- message: agreement_name, >- accept_label: this.$__("Yes, delete"), >- cancel_label: this.$__("No, do not delete"), >- }, >- () => { >- const client = APIClient.erm >- client.agreements.delete(agreement_id).then( >- success => { >- this.setMessage( >- this.$__("Agreement %s deleted").format( >- agreement_name >- ), >- true >- ) >- this.$router.push({ name: "AgreementsList" }) >- }, >- error => {} >- ) >- } >- ) >- }, > }, > components: { Toolbar, ToolbarButton }, > name: "AgreementsShow", >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37301
:
168709
|
168739
|
168740
|
168741
|
168800
|
168827
|
168828
|
168829
|
168836
|
172713
|
172911
|
172912
|
172913
|
172914
|
172915
|
172916
|
172917
|
172918
|
172919
|
172920
|
172921
|
174612
|
174613
|
174614
|
174615
|
174616
|
174617
|
174618
|
174619
|
174620
|
174621
|
174622
|
174623
|
174624
|
174625
|
174626
|
174627
|
174628
|
174629
|
174630
|
174631
|
175450
|
177173
|
177174
|
177175
|
177176
|
177177
|
177178
|
177179
|
177180
|
177181
|
177182
|
177183
|
177184
|
177185
|
177186
|
177187
|
177188
|
177189
|
177190
|
177191
|
177192
|
177193
|
177351