Bugzilla – Attachment 147066 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: Use APIClient to fetch licenses
Bug-32939-Use-APIClient-to-fetch-licenses.patch (text/plain), 12.66 KB, created by
Matt Blenkinsop
on 2023-02-21 16:15:37 UTC
(
hide
)
Description:
Bug 32939: Use APIClient to fetch licenses
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-02-21 16:15:37 UTC
Size:
12.66 KB
patch
obsolete
>From 09f30864ae357e872fecf379fccd580ed266b08a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 21 Feb 2023 10:04:53 +0100 >Subject: [PATCH] Bug 32939: Use APIClient to fetch licenses > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > .../vue/components/ERM/AgreementLicenses.vue | 12 +++- > .../js/vue/components/ERM/LicensesFormAdd.vue | 56 ++++++++----------- > .../ERM/LicensesFormConfirmDelete.vue | 40 +++++-------- > .../js/vue/components/ERM/LicensesList.vue | 13 +++-- > .../js/vue/components/ERM/LicensesShow.vue | 13 +++-- > .../prog/js/vue/fetch/erm-api-client.js | 34 +++++++++++ > .../intranet-tmpl/prog/js/vue/fetch/erm.js | 19 ------- > 7 files changed, 100 insertions(+), 87 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue >index 5461aff5d19..d383b43c244 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue >@@ -101,7 +101,8 @@ > </template> > > <script> >-import { fetchLicenses } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" >+ > export default { > name: "AgreementLicenses", > data() { >@@ -115,7 +116,14 @@ export default { > agreement_licenses: Array, > }, > beforeCreate() { >- fetchLicenses().then(licenses => (this.licenses = licenses)) >+ const client = APIClient.erm >+ client.licenses.getAll.then( >+ licenses => { >+ this.licenses = licenses >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > methods: { > addLicense() { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue >index 038c657e9ba..14b42290f15 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue >@@ -149,8 +149,8 @@ import { inject } from "vue" > import flatPickr from "vue-flatpickr-component" > import UserRoles from "./UserRoles.vue" > import Documents from "./Documents.vue" >-import { setMessage, setError, setWarning } from "../../messages" >-import { fetchLicense, checkError } from "../../fetch/erm.js" >+import { setMessage, setWarning } from "../../messages" >+import { APIClient } from "../../fetch/api-client.js" > import { storeToRefs } from "pinia" > > export default { >@@ -199,9 +199,11 @@ export default { > }, > methods: { > async getLicense(license_id) { >- const license = await fetchLicense(license_id) >- this.license = license >- this.initialized = true >+ const client = APIClient.erm >+ client.licenses.get(license_id).then(license => { >+ this.license = license >+ this.initialized = true >+ }) > }, > checkForm(license) { > let errors = [] >@@ -229,6 +231,7 @@ export default { > e.preventDefault() > > let license = JSON.parse(JSON.stringify(this.license)) // copy >+ let license_id = license.license_id > > if (!this.checkForm(license)) { > return false >@@ -256,35 +259,24 @@ export default { > ({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs > ) > >- const options = { >- method: method, >- body: JSON.stringify(license), >- headers: { >- "Content-Type": "application/json;charset=utf-8", >- }, >- } >- >- fetch(apiUrl, options) >- .then(response => checkError(response, 1)) >- .then( >- response => { >- if (response.status == 200) { >- this.$router.push("/cgi-bin/koha/erm/licenses") >- setMessage(this.$__("License updated")) >- } else if (response.status == 201) { >- this.$router.push("/cgi-bin/koha/erm/licenses") >- setMessage(this.$__("License created")) >- } else { >- setError(response.message || response.statusText) >- } >+ const client = APIClient.erm >+ if (license_id) { >+ client.licenses.update(license, license_id).then( >+ success => { >+ setMessage(this.$__("License updated")) >+ this.$router.push("/cgi-bin/koha/erm/licenses") > }, >- error => { >- setError(error) >- } >+ error => {} > ) >- .catch(e => { >- console.log(e) >- }) >+ } else { >+ client.licenses.create(license).then( >+ success => { >+ setMessage(this.$__("License created")) >+ this.$router.push("/cgi-bin/koha/erm/licenses") >+ }, >+ error => {} >+ ) >+ } > }, > }, > components: { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue >index 404409d5ee3..0bf3dbfefa1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue >@@ -35,8 +35,8 @@ > </template> > > <script> >-import { fetchLicense, checkError } from "../../fetch/erm.js" >-import { setMessage, setError } from "../../messages" >+import { APIClient } from "../../fetch/api-client.js" >+import { setMessage } from "../../messages" > > export default { > data() { >@@ -53,35 +53,23 @@ export default { > }, > methods: { > async getLicense(license_id) { >- const license = await fetchLicense(license_id) >- this.license = license >- this.initialized = true >+ const client = APIClient.erm >+ client.licenses.get(license_id).then(data => { >+ this.license = data >+ this.initialized = true >+ }) > }, > onSubmit(e) { > e.preventDefault() > >- let apiUrl = "/api/v1/erm/licenses/" + this.license.license_id >- >- const options = { >- method: "DELETE", >- headers: { >- "Content-Type": "application/json;charset=utf-8", >+ const client = APIClient.erm >+ client.licenses.delete(this.license.license_id).then( >+ success => { >+ setMessage(this.$__("License deleted")) >+ this.$router.push("/cgi-bin/koha/erm/licenses") > }, >- } >- >- fetch(apiUrl, options) >- .then(response => checkError(response, 1)) >- .then(response => { >- if (response.status == 204) { >- this.$router.push("/cgi-bin/koha/erm/licenses") >- setMessage(this.$__("License deleted")) >- } else { >- setError(response.message || response.statusText) >- } >- }) >- .catch(error => { >- setError(error) >- }) >+ error => {} >+ ) > }, > }, > name: "LicensesFormConfirmDelete", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >index 4f441e401f9..84eb25bf441 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >@@ -15,7 +15,7 @@ > import Toolbar from "./LicensesToolbar.vue" > import { inject, createVNode, render } from "vue" > import { storeToRefs } from "pinia" >-import { fetchLicenses } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { useDataTable } from "../../composables/datatables" > > export default { >@@ -49,9 +49,14 @@ export default { > }, > methods: { > async getLicenses() { >- const licenses = await fetchLicenses() >- this.licenses = licenses >- this.initialized = true >+ const client = APIClient.erm >+ await client.licenses.getAll().then( >+ licenses => { >+ this.licenses = licenses >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > show_license: function (license_id) { > this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id) >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue >index b072e965ef2..bf77b9f613e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue >@@ -145,7 +145,7 @@ > > <script> > import { inject } from "vue" >-import { fetchLicense } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > > export default { > setup() { >@@ -185,9 +185,14 @@ export default { > }, > methods: { > async getLicense(license_id) { >- const license = await fetchLicense(license_id) >- this.license = license >- this.initialized = true >+ const client = APIClient.erm >+ client.licenses.get(license_id).then( >+ license => { >+ this.license = license >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > }, > components: {}, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >index e16e35b2b55..5650e19442d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >@@ -38,6 +38,40 @@ export class ERMAPIClient extends HttpClient { > //count: () => this.count("agreements"), //TODO: Implement count method > }; > } >+ >+ get licenses() { >+ return { >+ get: (id) => >+ this.get({ >+ endpoint: "licenses/" + id, >+ headers: { >+ "x-koha-embed": >+ "user_roles,user_roles.patron,vendor,documents" >+ }, >+ }), >+ getAll: (query) => >+ this.get({ >+ endpoint: "licenses?" + (query || "_per_page=-1"), >+ headers: { >+ "x-koha-embed": "vendor.name", >+ }, >+ }), >+ delete: (id) => >+ this.delete({ >+ endpoint: "licenses/" + id, >+ }), >+ create: (license) => >+ this.post({ >+ endpoint: "licenses", >+ body: license, >+ }), >+ update: (license, id) => >+ this.put({ >+ endpoint: "licenses/" + id, >+ body: license, >+ }), >+ }; >+ } > } > > export default ERMAPIClient; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js >index 54e47337979..15268533301 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js >@@ -2,25 +2,6 @@ import { setError } from "../messages"; > > //TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient > >-export const fetchLicense = function (license_id) { >- if (!license_id) return; >- const apiUrl = "/api/v1/erm/licenses/" + license_id; >- return myFetch(apiUrl, { >- headers: { >- "x-koha-embed": "user_roles,user_roles.patron,vendor,documents", >- }, >- }); >-}; >- >-export const fetchLicenses = function () { >- const apiUrl = "/api/v1/erm/licenses?_per_page=-1"; >- return myFetch(apiUrl, { >- headers: { >- "x-koha-embed": "vendor.name", >- }, >- }); >-}; >- > export const fetchPatron = function (patron_id) { > if (!patron_id) return; > const apiUrl = "/api/v1/patrons/" + patron_id; >-- >2.37.1 (Apple Git-137.1)
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