Bugzilla – Attachment 147317 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 local eHoldings
Bug-32939-Use-APIClient-to-fetch-local-eHoldings.patch (text/plain), 40.17 KB, created by
Nick Clemens (kidclamp)
on 2023-02-24 12:22:55 UTC
(
hide
)
Description:
Bug 32939: Use APIClient to fetch local eHoldings
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-02-24 12:22:55 UTC
Size:
40.17 KB
patch
obsolete
>From 278dda3e100451d782c466755f120d0118337747 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 21 Feb 2023 11:59:01 +0100 >Subject: [PATCH] Bug 32939: Use APIClient to fetch local eHoldings > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../vue/components/ERM/AgreementLicenses.vue | 2 +- > .../ERM/EHoldingsEBSCOPackageAgreements.vue | 31 ++++-- > .../ERM/EHoldingsEBSCOPackagesList.vue | 16 ++- > .../ERM/EHoldingsEBSCOTitlesList.vue | 30 +++++- > .../ERM/EHoldingsLocalPackagesFormAdd.vue | 60 ++++++----- > ...HoldingsLocalPackagesFormConfirmDelete.vue | 50 ++++------ > .../ERM/EHoldingsLocalPackagesList.vue | 12 ++- > .../ERM/EHoldingsLocalPackagesShow.vue | 15 ++- > .../ERM/EHoldingsLocalResourcesShow.vue | 15 ++- > .../ERM/EHoldingsLocalTitlesFormAdd.vue | 73 ++++++-------- > .../EHoldingsLocalTitlesFormAddResources.vue | 11 ++- > .../EHoldingsLocalTitlesFormConfirmDelete.vue | 23 +++-- > .../ERM/EHoldingsLocalTitlesFormImport.vue | 21 ++-- > .../ERM/EHoldingsLocalTitlesList.vue | 12 ++- > .../ERM/EHoldingsLocalTitlesShow.vue | 16 ++- > .../prog/js/vue/fetch/erm-api-client.js | 99 ++++++++++++++++++- > .../intranet-tmpl/prog/js/vue/fetch/erm.js | 97 ------------------ > .../prog/js/vue/fetch/http-client.js | 5 +- > 18 files changed, 332 insertions(+), 256 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 d383b43c24..7111a096ca 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 >@@ -117,7 +117,7 @@ export default { > }, > beforeCreate() { > const client = APIClient.erm >- client.licenses.getAll.then( >+ client.licenses.getAll().then( > licenses => { > this.licenses = licenses > this.initialized = true >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageAgreements.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageAgreements.vue >index ec01588404..d82d7e380c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageAgreements.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageAgreements.vue >@@ -36,7 +36,7 @@ > > <script> > import AgreementsList from "./AgreementsList.vue" >-import { createPackage, editPackage } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { setWarning, removeMessages } from "../../messages" > > export default { >@@ -71,14 +71,21 @@ export default { > ) > ) { > erm_package.package_agreements.push({ agreement_id }) >+ const client = APIClient.erm > if (this.erm_package.koha_internal_id) { >- editPackage(erm_package).then(() => { >- this.$emit("refresh-agreements") >- }) >+ client.localPackages.update(erm_package, package_id).then( >+ success => { >+ this.$emit("refresh-agreements") >+ }, >+ error => {} >+ ) > } else { >- createPackage(erm_package).then(() => { >- this.$emit("refresh-agreements") >- }) >+ client.localPackages.create(erm_package).then( >+ success => { >+ this.$emit("refresh-agreements") >+ }, >+ error => {} >+ ) > } > } else { > setWarning( >@@ -90,10 +97,14 @@ export default { > }, > deleteAgreement(counter) { > let erm_package = this.serializeAgreement() >+ const client = APIClient.erm > erm_package.package_agreements.splice(counter, 1) >- editPackage(erm_package).then(() => { >- this.$emit("refresh-agreements") >- }) >+ client.localPackages.update(erm_package, package_id).then( >+ success => { >+ this.$emit("refresh-agreements") >+ }, >+ error => {} >+ ) > }, > }, > props: { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue >index bd1f0ce79f..900c459bfb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue >@@ -62,7 +62,7 @@ > <script> > import { inject, createVNode, render } from "vue" > import { storeToRefs } from "pinia" >-import { fetchLocalPackageCount } from "./../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { > useDataTable, > build_url_params, >@@ -136,8 +136,18 @@ export default { > .DataTable() > .draw() > if (this.erm_providers.includes("local")) { >- this.local_count_packages = await fetchLocalPackageCount( >- this.filters >+ const client = APIClient.erm >+ const query = filters >+ ? { >+ "me.name": { like: "%" + filters.package_name + "%" }, >+ ...(filters.content_type >+ ? { "me.content_type": filters.content_type } >+ : {}), >+ } >+ : {} >+ client.localPackages.count(query).then( >+ count => (this.local_count_packages = count), >+ error => {} > ) > } > }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue >index 15b9ebe380..60118ff322 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue >@@ -66,7 +66,7 @@ > <script> > import { inject, createVNode, render } from "vue" > import { storeToRefs } from "pinia" >-import { fetchLocalTitleCount } from "./../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { > useDataTable, > build_url_params, >@@ -140,8 +140,32 @@ export default { > .DataTable() > .draw() > if (this.erm_providers.includes("local")) { >- this.local_title_count = await fetchLocalTitleCount( >- this.filters >+ const client = APIClient.erm >+ >+ const q = filters >+ ? { >+ ...(this.filters.publication_title >+ ? { >+ "me.publication_title": { >+ like: >+ "%" + >+ this.filters.publication_title + >+ "%", >+ }, >+ } >+ : {}), >+ ...(this.filters.publication_type >+ ? { >+ "me.publication_type": >+ this.filters.publication_type, >+ } >+ : {}), >+ } >+ : undefined >+ >+ client.localTitles.count(q).then( >+ count => (this.local_title_count = count), >+ error => {} > ) > } > } else { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue >index fdca462025..c227105e71 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue >@@ -88,12 +88,7 @@ > import { inject } from "vue" > import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue" > import { setMessage, setError, setWarning } from "../../messages" >-import { >- fetchLocalPackage, >- createPackage, >- editPackage, >- checkError, >-} from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { storeToRefs } from "pinia" > > export default { >@@ -137,10 +132,15 @@ export default { > }) > }, > methods: { >- async getPackage(package_id) { >- const erm_package = await fetchLocalPackage(package_id) >- this.erm_package = erm_package >- this.initialized = true >+ getPackage(package_id) { >+ const client = APIClient.erm >+ client.localPackages.get(package_id).then( >+ erm_package => { >+ this.erm_package = erm_package >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > checkForm(erm_package) { > let errors = [] >@@ -168,28 +168,38 @@ export default { > return false > } > >- if (erm_package.package_id) { >- editPackage(erm_package).then(response => { >- if (response && response.status == 200) { >+ let package_id = erm_package.package_id >+ delete erm_package.package_id >+ delete erm_package.resources >+ delete erm_package.vendor >+ delete erm_package.resources_count >+ delete erm_package.is_selected >+ >+ erm_package.package_agreements = erm_package.package_agreements.map( >+ ({ package_id, agreement, ...keepAttrs }) => keepAttrs >+ ) >+ >+ const client = APIClient.erm >+ if (package_id) { >+ client.localPackages.update(erm_package, package_id).then( >+ success => { >+ setMessage(this.$__("Package updated")) > this.$router.push( > "/cgi-bin/koha/erm/eholdings/local/packages" > ) >- setMessage(this.$__("Package updated")) >- } else if (response) { >- setError(response.message || response.statusText) >- } >- }) >+ }, >+ error => {} >+ ) > } else { >- createPackage(erm_package).then(response => { >- if (response && response.status == 201) { >+ client.localPackages.create(erm_package).then( >+ success => { >+ setMessage(this.$__("Package created")) > this.$router.push( > "/cgi-bin/koha/erm/eholdings/local/packages" > ) >- setMessage(this.$__("Package created")) >- } else if (response) { >- setError(response.message || response.statusText) >- } >- }) >+ }, >+ error => {} >+ ) > } > }, > }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormConfirmDelete.vue >index 9258f4bea5..352e18b01d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormConfirmDelete.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormConfirmDelete.vue >@@ -31,8 +31,8 @@ > </template> > > <script> >-import { fetchLocalPackage, checkError } from "../../fetch/erm.js" > import { setMessage, setError } from "../../messages" >+import { APIClient } from "../../fetch/api-client.js" > > export default { > data() { >@@ -47,40 +47,28 @@ export default { > }) > }, > methods: { >- async getPackage(package_id) { >- const erm_package = await fetchLocalPackage(package_id) >- this.erm_package = erm_package >- this.initialized = true >+ getPackage(package_id) { >+ const client = APIClient.erm >+ client.localPackages.get(package_id).then( >+ erm_package => { >+ this.erm_package = erm_package >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > onSubmit(e) { > e.preventDefault() >- >- let apiUrl = >- "/api/v1/erm/eholdings/local/packages/" + >- this.erm_package.package_id >- >- const options = { >- method: "DELETE", >- headers: { >- "Content-Type": "application/json;charset=utf-8", >+ const client = APIClient.erm >+ client.localPackages.delete(this.erm_package.package_id).then( >+ success => { >+ setMessage(this.$__("Package deleted")) >+ this.$router.push( >+ "/cgi-bin/koha/erm/eholdings/local/packages" >+ ) > }, >- } >- >- fetch(apiUrl, options) >- .then(response => checkError(response, 1)) >- .then(response => { >- if (response.status == 204) { >- setMessage(this.$__("Package deleted")) >- this.$router.push( >- "/cgi-bin/koha/erm/eholdings/local/packages" >- ) >- } else { >- setError(response.message || response.statusText) >- } >- }) >- .catch(error => { >- setError(error) >- }) >+ error => {} >+ ) > }, > }, > name: "EHoldingsLocalPackagesFormConfirmDelete", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >index a99e8327be..348edf92df 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >@@ -21,7 +21,7 @@ > import Toolbar from "./EHoldingsLocalPackagesToolbar.vue" > import { inject, createVNode, render } from "vue" > import { storeToRefs } from "pinia" >-import { fetchLocalPackageCount } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { useDataTable } from "../../composables/datatables" > > export default { >@@ -59,8 +59,14 @@ export default { > }, > methods: { > async getPackageCount() { >- this.package_count = await fetchLocalPackageCount() >- this.initialized = true >+ const client = APIClient.erm >+ await client.localPackages.count().then( >+ count => { >+ this.package_count = count >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > show_package: function (package_id) { > this.$router.push( >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue >index eb4d65073d..f0bdd27108 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue >@@ -106,7 +106,7 @@ > <script> > import { inject } from "vue" > import EHoldingsPackageTitlesList from "./EHoldingsLocalPackageTitlesList.vue" >-import { fetchLocalPackage } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > > export default { > setup() { >@@ -145,10 +145,15 @@ export default { > this.erm_package = this.getPackage(to.params.package_id) > }, > methods: { >- async getPackage(package_id) { >- const erm_package = await fetchLocalPackage(package_id) >- this.erm_package = erm_package >- this.initialized = true >+ getPackage(package_id) { >+ const client = APIClient.erm >+ client.localPackages.get(package_id).then( >+ erm_package => { >+ this.erm_package = erm_package >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > }, > components: { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalResourcesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalResourcesShow.vue >index 55d529fe5b..3a043cfd2c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalResourcesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalResourcesShow.vue >@@ -96,7 +96,7 @@ > > <script> > import { inject } from "vue" >-import { fetchLocalResource } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { storeToRefs } from "pinia" > export default { > setup() { >@@ -134,10 +134,15 @@ export default { > this.resource = this.getResource(to.params.resource_id) > }, > methods: { >- async getResource(resource_id) { >- const resource = await fetchLocalResource(resource_id) >- this.resource = resource >- this.initialized = true >+ getResource(resource_id) { >+ const client = APIClient.erm >+ client.localResources.get(resource_id).then( >+ resource => { >+ this.resource = resource >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > }, > name: "EHoldingsLocalResourcesShow", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue >index 14bf911711..482ada3967 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue >@@ -388,7 +388,7 @@ > import { inject } from "vue" > import EHoldingsTitlesFormAddResources from "./EHoldingsLocalTitlesFormAddResources.vue" > import { setMessage, setError, setWarning } from "../../messages" >-import { fetchLocalTitle, checkError } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { storeToRefs } from "pinia" > > export default { >@@ -450,10 +450,15 @@ export default { > }) > }, > methods: { >- async getTitle(title_id) { >- const title = await fetchLocalTitle(title_id) >- this.title = title >- this.initialized = true >+ getTitle(title_id) { >+ const client = APIClient.erm >+ client.localTitles.get(title_id).then( >+ title => { >+ this.title = title >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > checkForm(title) { > let errors = [] >@@ -481,13 +486,8 @@ export default { > if (!this.checkForm(title)) { > return false > } >- let apiUrl = "/api/v1/erm/eholdings/local/titles" > >- let method = "POST" >- if (title.title_id) { >- method = "PUT" >- apiUrl += "/" + title.title_id >- } >+ let title_id = title.title_id > delete title.title_id > delete title.biblio_id > >@@ -497,39 +497,28 @@ export default { > delete e.resource_id > }) > >- const options = { >- method: method, >- body: JSON.stringify(title), >- headers: { >- "Content-Type": "application/json;charset=utf-8", >- }, >- } >- >- fetch(apiUrl, options) >- .then(response => checkError(response, 1)) >- .then( >- response => { >- if (response && response.status == 200) { >- this.$router.push( >- "/cgi-bin/koha/erm/eholdings/local/titles" >- ) >- setMessage(this.$__("Title updated")) >- } else if (response && response.status == 201) { >- this.$router.push( >- "/cgi-bin/koha/erm/eholdings/local/titles" >- ) >- setMessage(this.$__("Title created")) >- } else if (response) { >- setError(response.message || response.statusText) >- } >+ const client = APIClient.erm >+ if (title_id) { >+ client.localTitles.update(title, title_id).then( >+ success => { >+ setMessage(this.$__("Title updated")) >+ this.$router.push( >+ "/cgi-bin/koha/erm/eholdings/local/titles" >+ ) > }, >- error => { >- setError(error) >- } >+ error => {} > ) >- .catch(e => { >- console.log(e) >- }) >+ } else { >+ client.localTitles.create(title).then( >+ success => { >+ setMessage(this.$__("Title created")) >+ this.$router.push( >+ "/cgi-bin/koha/erm/eholdings/local/titles" >+ ) >+ }, >+ error => {} >+ ) >+ } > }, > }, > components: { EHoldingsTitlesFormAddResources }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAddResources.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAddResources.vue >index 38ae7f3d5e..fe6ae050e6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAddResources.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAddResources.vue >@@ -95,7 +95,7 @@ > import { inject } from "vue" > import flatPickr from "vue-flatpickr-component" > import { storeToRefs } from "pinia" >-import { fetchLocalPackages } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > > export default { > setup() { >@@ -110,7 +110,14 @@ export default { > } > }, > beforeCreate() { >- fetchLocalPackages().then(packages => (this.packages = packages)) >+ const client = APIClient.erm >+ client.localPackages.getAll().then( >+ packages => { >+ this.packages = packages >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > methods: { > addPackage() { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormConfirmDelete.vue >index a0f426a6a1..d7206aec0b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormConfirmDelete.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormConfirmDelete.vue >@@ -8,7 +8,7 @@ > <ol> > <li> > {{ $__("Title") }}: >- {{ eholding.publication_title }} >+ {{ title.publication_title }} > </li> > </ol> > </fieldset> >@@ -31,32 +31,37 @@ > </template> > > <script> >-import { fetchLocalTitle, checkError } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { setMessage, setError } from "../../messages" > > export default { > data() { > return { >- eholding: {}, >+ title: {}, > initialized: false, > } > }, > beforeRouteEnter(to, from, next) { > next(vm => { >- vm.getEHolding(to.params.title_id) >+ vm.getTitle(to.params.title_id) > }) > }, > methods: { >- async getEHolding(title_id) { >- const eholding = await fetchLocalTitle(title_id) >- this.eholding = eholding >- this.initialized = true >+ getTitle(title_id) { >+ const client = APIClient.erm >+ client.localTitles.get(title_id).then( >+ title => { >+ this.title = title >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > onSubmit(e) { > e.preventDefault() > > let apiUrl = >- "/api/v1/erm/eholdings/local/titles/" + this.eholding.title_id >+ "/api/v1/erm/eholdings/local/titles/" + this.title.title_id > > const options = { > method: "DELETE", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >index e3533bb24a..04c9089e4c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >@@ -23,10 +23,10 @@ > </template> > > <script> >-import { setMessage, setError, setWarning } from "../../messages" >+import { setError } from "../../messages" > import { createVNode, render } from "vue" >+import { APIClient } from "../../fetch/api-client.js" > import { useDataTable } from "../../composables/datatables" >-import { checkError, fetchLocalPackages } from "../../fetch/erm.js" > > export default { > setup() { >@@ -46,12 +46,17 @@ export default { > } > }, > beforeCreate() { >- fetchLocalPackages().then(packages => { >- this.packages = packages >- if (this.packages.length) { >- this.package_id = packages[0].package_id >- } >- }) >+ const client = APIClient.erm >+ client.localPackages.getAll().then( >+ packages => { >+ this.packages = packages >+ if (this.packages.length) { >+ this.package_id = packages[0].package_id >+ } >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > methods: { > import_from_list: async function (list_id) { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >index cff383fe34..90ab757f38 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >@@ -21,7 +21,7 @@ > import Toolbar from "./EHoldingsLocalTitlesToolbar.vue" > import { inject, createVNode, render } from "vue" > import { storeToRefs } from "pinia" >-import { fetchLocalTitleCount } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" > import { useDataTable } from "../../composables/datatables" > > export default { >@@ -58,8 +58,14 @@ export default { > }, > methods: { > async getTitleCount() { >- this.title_count = await fetchLocalTitleCount() >- this.initialized = true >+ const client = APIClient.erm >+ await client.localTitles.count().then( >+ count => { >+ this.title_count = count >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > show_title: function (title_id) { > this.$router.push( >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue >index 558895cd87..59f0bf5104 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue >@@ -258,7 +258,8 @@ > <script> > import { inject } from "vue" > import EHoldingsTitlePackagesList from "./EHoldingsLocalTitlePackagesList.vue" >-import { fetchLocalTitle } from "../../fetch/erm.js" >+import { APIClient } from "../../fetch/api-client.js" >+ > export default { > setup() { > const AVStore = inject("AVStore") >@@ -311,10 +312,15 @@ export default { > this.title = this.getTitle(to.params.title_id) > }, > methods: { >- async getTitle(title_id) { >- const title = await fetchLocalTitle(title_id) >- this.title = title >- this.initialized = true >+ getTitle(title_id) { >+ const client = APIClient.erm >+ client.localTitles.get(title_id).then( >+ title => { >+ this.title = title >+ 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 5650e19442..bfe0c6eb3b 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 >@@ -46,7 +46,7 @@ export class ERMAPIClient extends HttpClient { > endpoint: "licenses/" + id, > headers: { > "x-koha-embed": >- "user_roles,user_roles.patron,vendor,documents" >+ "user_roles,user_roles.patron,vendor,documents", > }, > }), > getAll: (query) => >@@ -72,6 +72,103 @@ export class ERMAPIClient extends HttpClient { > }), > }; > } >+ >+ get localPackages() { >+ return { >+ get: (id) => >+ this.get({ >+ endpoint: "eholdings/local/packages/" + id, >+ headers: { >+ "x-koha-embed": >+ "package_agreements,package_agreements.agreement,resources+count,vendor", >+ }, >+ }), >+ getAll: (query) => >+ this.get({ >+ endpoint: >+ "eholdings/local/packages?" + (query || "_per_page=-1"), >+ headers: { >+ "x-koha-embed": "resources+count,vendor.name", >+ }, >+ }), >+ delete: (id) => >+ this.delete({ >+ endpoint: "eholdings/local/packages/" + id, >+ }), >+ create: (local_package) => >+ this.post({ >+ endpoint: "eholdings/local/packages", >+ body: local_package, >+ }), >+ update: (local_package, id) => >+ this.put({ >+ endpoint: "eholdings/local/packages/" + id, >+ body: local_package, >+ }), >+ count: (query = {}) => >+ this.count({ >+ endpoint: >+ "eholdings/local/packages?" + >+ new URLSearchParams({ >+ _page: 1, >+ _per_page: 1, >+ ...(query && { q: JSON.stringify(query) }), >+ }), >+ }), >+ }; >+ } >+ >+ get localTitles() { >+ return { >+ get: (id) => >+ this.get({ >+ endpoint: "eholdings/local/titles/" + id, >+ headers: { >+ "x-koha-embed": "resources,resources.package", >+ }, >+ }), >+ getAll: (query) => >+ this.get({ >+ endpoint: "eholdings/local/titles?" + (query || "_per_page=-1"), >+ }), >+ delete: (id) => >+ this.delete({ >+ endpoint: "eholdings/local/titles/" + id, >+ }), >+ create: (local_package) => >+ this.post({ >+ endpoint: "eholdings/local/titles", >+ body: local_package, >+ }), >+ update: (local_package, id) => >+ this.put({ >+ endpoint: "eholdings/local/titles/" + id, >+ body: local_package, >+ }), >+ count: (query = {}) => >+ this.count({ >+ endpoint: >+ "eholdings/local/titles?" + >+ new URLSearchParams({ >+ _page: 1, >+ _per_page: 1, >+ ...(query && { q: JSON.stringify(query) }), >+ }), >+ }), >+ }; >+ } >+ >+ get localResources() { >+ return { >+ get: (id) => >+ this.get({ >+ endpoint: "eholdings/local/resources/" + id, >+ headers: { >+ "x-koha-embed": "title,package,vendor", >+ }, >+ }), >+ }; >+ } > } > > 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 b76ce379d9..851a99a034 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js >@@ -2,40 +2,6 @@ import { setError } from "../messages"; > > //TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient > >-const _createEditPackage = function (method, erm_package) { >- let apiUrl = "/api/v1/erm/eholdings/local/packages"; >- >- if (method == "PUT") { >- apiUrl += "/" + erm_package.package_id; >- } >- delete erm_package.package_id; >- delete erm_package.resources; >- delete erm_package.vendor; >- delete erm_package.resources_count; >- delete erm_package.is_selected; >- >- erm_package.package_agreements = erm_package.package_agreements.map( >- ({ package_id, agreement, ...keepAttrs }) => keepAttrs >- ); >- >- const options = { >- method: method, >- body: JSON.stringify(erm_package), >- headers: { >- "Content-Type": "application/json;charset=utf-8", >- }, >- }; >- >- return myFetch(apiUrl, options, 1); >-}; >- >-export const createPackage = function (erm_package) { >- return _createEditPackage("POST", erm_package); >-}; >-export const editPackage = function (erm_package) { >- return _createEditPackage("PUT", erm_package); >-}; >- > const _fetchPackage = function (apiUrl, package_id) { > if (!package_id) return; > return myFetch(apiUrl, { >@@ -45,10 +11,6 @@ const _fetchPackage = function (apiUrl, package_id) { > }, > }); > }; >-export const fetchLocalPackage = function (package_id) { >- const apiUrl = "/api/v1/erm/eholdings/local/packages/" + package_id; >- return _fetchPackage(apiUrl, package_id); >-}; > export const fetchEBSCOPackage = function (package_id) { > const apiUrl = "/api/v1/erm/eholdings/ebsco/packages/" + package_id; > return _fetchPackage(apiUrl, package_id); >@@ -61,34 +23,11 @@ export const _fetchPackages = function (apiUrl) { > }, > }); > }; >-export const fetchLocalPackages = function () { >- const apiUrl = "/api/v1/erm/eholdings/local/packages?_per_page=-1"; >- return _fetchPackages(apiUrl); >-}; > export const fetchEBSCOPackages = function () { > const apiUrl = "/api/v1/erm/eholdings/ebsco/packages"; > return _fetchPackages(apiUrl); > }; > >-export const fetchLocalPackageCount = function (filters) { >- const q = filters >- ? { >- "me.name": { like: "%" + filters.package_name + "%" }, >- ...(filters.content_type >- ? { "me.content_type": filters.content_type } >- : {}), >- } >- : {}; >- >- const params = { >- _page: 1, >- _per_page: 1, >- q: JSON.stringify(q), >- }; >- var apiUrl = "/api/v1/erm/eholdings/local/packages"; >- return myFetchTotal(apiUrl + "?" + new URLSearchParams(params)); >-}; >- > export const _fetchTitle = function (apiUrl, title_id) { > if (!title_id) return; > return myFetch(apiUrl, { >@@ -97,39 +36,11 @@ export const _fetchTitle = function (apiUrl, title_id) { > }, > }); > }; >-export const fetchLocalTitle = function (title_id) { >- const apiUrl = "/api/v1/erm/eholdings/local/titles/" + title_id; >- return _fetchTitle(apiUrl, title_id); >-}; > export const fetchEBSCOTitle = function (title_id) { > const apiUrl = "/api/v1/erm/eholdings/ebsco/titles/" + title_id; > return _fetchTitle(apiUrl, title_id); > }; > >-export const fetchLocalTitleCount = function (filters) { >- const q = filters >- ? { >- ...(filters.publication_title >- ? { >- "me.publication_title": { >- like: "%" + filters.publication_title + "%", >- }, >- } >- : {}), >- ...(filters.publication_type >- ? { "me.publication_type": filters.publication_type } >- : {}), >- } >- : undefined; >- const params = { >- _page: 1, >- _per_page: 1, >- ...(q ? { q: JSON.stringify(q) } : {}), >- }; >- var apiUrl = "/api/v1/erm/eholdings/local/titles"; >- return myFetchTotal(apiUrl + "?" + new URLSearchParams(params)); >-}; >- > export const _fetchResource = function (apiUrl, resource_id) { > if (!resource_id) return; > return myFetch(apiUrl, { >@@ -138,10 +49,6 @@ export const _fetchResource = function (apiUrl, resource_id) { > }, > }); > }; >-export const fetchLocalResource = function (resource_id) { >- const apiUrl = "/api/v1/erm/eholdings/local/resources/" + resource_id; >- return _fetchResource(apiUrl, resource_id); >-}; > export const fetchEBSCOResource = function (resource_id) { > const apiUrl = "/api/v1/erm/eholdings/ebsco/resources/" + resource_id; > return _fetchResource(apiUrl, resource_id); >@@ -151,10 +58,6 @@ export const _fetchResources = async function (apiUrl) { > return await myFetch(apiUrl); > }; > >-export const fetchLocalResources = function () { >- const apiUrl = "/api/v1/erm/eholdings/local/resources"; >- return _fetchResources(apiUrl); >-}; > export const fetchEBSCOResources = function () { > const apiUrl = "/api/v1/erm/eholdings/ebsco/resources"; > return _fetchResources(apiUrl); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >index 84311cb0c2..41a938cd77 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >@@ -72,17 +72,16 @@ class HttpClient { > > count(params = {}) { > let res; >- this._fetchJSON(params.endpoint, params.headers, 1).then( >+ return this._fetchJSON(params.endpoint, params.headers, {}, 1).then( > (response) => { > if (response) { >- res = response.headers.get("X-Total-Count"); >+ return response.headers.get("X-Total-Count"); > } > }, > (error) => { > setError(error.toString()); > } > ); >- return res; > } > > checkError(response, return_response = 0) { >-- >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