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> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
2d86a671f2
commit
7e58b6d74c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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 => {}
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
this.$router.push(
|
||||
"/cgi-bin/koha/erm/eholdings/local/packages"
|
||||
)
|
||||
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"))
|
||||
} else if (response) {
|
||||
setError(response.message || response.statusText)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
createPackage(erm_package).then(response => {
|
||||
if (response && response.status == 201) {
|
||||
this.$router.push(
|
||||
"/cgi-bin/koha/erm/eholdings/local/packages"
|
||||
)
|
||||
},
|
||||
error => {}
|
||||
)
|
||||
} else {
|
||||
client.localPackages.create(erm_package).then(
|
||||
success => {
|
||||
setMessage(this.$__("Package created"))
|
||||
} else if (response) {
|
||||
setError(response.message || response.statusText)
|
||||
}
|
||||
})
|
||||
this.$router.push(
|
||||
"/cgi-bin/koha/erm/eholdings/local/packages"
|
||||
)
|
||||
},
|
||||
error => {}
|
||||
)
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue