Bugzilla – Attachment 146470 Details for
Bug 32939
Have generic fetch functions in vue modules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32939: Have a generic fetch function for POST and PUT requests in vue modules
Bug-32939-Have-a-generic-fetch-function-for-POST-a.patch (text/plain), 3.80 KB, created by
Pedro Amorim
on 2023-02-10 12:22:55 UTC
(
hide
)
Description:
Bug 32939: Have a generic fetch function for POST and PUT requests in vue modules
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-02-10 12:22:55 UTC
Size:
3.80 KB
patch
obsolete
>From c1f1d089d39325557628d08f3304ccae56e40dec Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Fri, 10 Feb 2023 11:19:08 -0100 >Subject: [PATCH] Bug 32939: Have a generic fetch function for POST and PUT > requests in vue modules > >In bug 32925 it's discussed the possibility of having a generic fetch function to handle basic CRUD creates and edits for vuejs modules in the future and move all common POST+PUT async requests workflow in there, like the 'Submitting...' loading behaviour. >This POC illustrates this and it's intent is to start discussion, plan on iterating further to the rest of ERM if agreed upon. >--- > .../vue/components/ERM/AgreementsFormAdd.vue | 28 ++++++++----------- > .../intranet-tmpl/prog/js/vue/fetch/fetch.js | 26 +++++++++++++++++ > 2 files changed, 37 insertions(+), 17 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/fetch/fetch.js > >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 d2330b754e..471f70d50d 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 >@@ -198,6 +198,7 @@ import { > submitted, > } from "../../messages" > import { fetchAgreement } from "../../fetch/erm.js" >+import { submitToAPI } from "../../fetch/fetch.js" > import { storeToRefs } from "pinia" > > export default { >@@ -390,23 +391,16 @@ export default { > }, > } > >- isSubmitting() >- fetch(apiUrl, options) >- .then(response => { >- if (response.status == 200) { >- this.$router.push("/cgi-bin/koha/erm/agreements") >- setMessage(this.$__("Agreement updated")) >- } else if (response.status == 201) { >- this.$router.push("/cgi-bin/koha/erm/agreements") >- setMessage(this.$__("Agreement created")) >- } else { >- setError(response.message || response.statusText) >- } >- }) >- .catch(error => { >- setError(error) >- }) >- .then(() => submitted()) >+ submitToAPI( >+ { >+ apiUrl: apiUrl, >+ options: options, >+ success_redirect: '/cgi-bin/koha/erm/agreements', >+ created_message: this.$__("Agreement created"), >+ updated_message: this.$__("Agreement updated"), >+ router: this.$router >+ } >+ ) > }, > onStatusChanged(e) { > if (e.authorised_value != "closed") { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/fetch.js >new file mode 100644 >index 0000000000..ba6aabdbe7 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/fetch.js >@@ -0,0 +1,26 @@ >+import { >+ setMessage, >+ setError, >+ isSubmitting, >+ submitted, >+} from "../messages" >+ >+export const submitToAPI = async function (args) { >+ isSubmitting() >+ await fetch(args.apiUrl, args.options) >+ .then(response => { >+ if (response.status == 200) { >+ args.router.push(args.success_redirect) >+ setMessage(args.updated_message) >+ } else if (response.status == 201) { >+ args.router.push(args.success_redirect) >+ setMessage(args.created_message) >+ } else { >+ setError(response.message || response.statusText) >+ } >+ }) >+ .catch(error => { >+ setError(error) >+ }) >+ .then(() => submitted()) >+}; >-- >2.30.2
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 32939
:
146470
|
146509
|
146642
|
146644
|
146645
|
146668
|
146669
|
146670
|
146671
|
146672
|
146674
|
146675
|
146676
|
146677
|
146678
|
146679
|
146680
|
146681
|
146682
|
147029
|
147030
|
147031
|
147032
|
147033
|
147034
|
147035
|
147036
|
147037
|
147038
|
147039
|
147040
|
147041
|
147042
|
147043
|
147044
|
147056
|
147057
|
147059
|
147060
|
147061
|
147062
|
147063
|
147064
|
147065
|
147066
|
147067
|
147068
|
147069
|
147070
|
147071
|
147072
|
147073
|
147306
|
147307
|
147308
|
147309
|
147310
|
147311
|
147312
|
147313
|
147314
|
147315
|
147316
|
147317
|
147318
|
147319
|
147320
|
147321
|
147322
|
147332
|
149441