Jonathan Druart
a294c5e901
... and fix cypress tests The main problem was that there were no more checkError call for fetchLocalTitleCount and the error was not displayed on the UI. This commit is doing several things: - Refactor fetch.js to call the same fetch method (myFetch) in order to deal with the error in a single place - Have a new myFetchTotal JS function to get the X-Total-Count header from the response and get the benefit of the previous refactoring - Rename fetchCountLocalPackages with fetchLocalPackagesCount to match fetchLocalTitleCount - Use fetchLocalPackagesCount on the Package list view - Use checkError from components using fetch directly. Ideally the could should be moved to fetch.js and myFetch should be used. - checkError get a new flag in parameter to ask for the response instead of the result (ie. the JSON of the response). That's useful when we need the response status or the headers - Make checkError throw a proper exception to stop propation. This modify the error we display on the UI, it's why we have the following changes in cypress tests: - "Something went wrong: Internal Server Error" + "Something went wrong: Error: Internal Server Error" That's not ideal, we should have our own JS exception to avoid that "Error" (coming from the toString call on the error) Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
89 lines
2.7 KiB
Vue
89 lines
2.7 KiB
Vue
<template>
|
|
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
|
<div v-else id="licenses_confirm_delete">
|
|
<h2>{{ $__("Delete license") }}</h2>
|
|
<div>
|
|
<form @submit="onSubmit($event)">
|
|
<fieldset class="rows">
|
|
<ol>
|
|
<li>
|
|
{{ $__("License name") }}:
|
|
{{ license.name }}
|
|
</li>
|
|
<li>
|
|
{{ $__("Description") }}:
|
|
{{ license.description }}
|
|
</li>
|
|
</ol>
|
|
</fieldset>
|
|
<fieldset class="action">
|
|
<input
|
|
type="submit"
|
|
variant="primary"
|
|
:value="$__('Yes, delete')"
|
|
/>
|
|
<router-link
|
|
to="/cgi-bin/koha/erm/licenses"
|
|
role="button"
|
|
class="cancel"
|
|
>{{ $__("No, do not delete") }}</router-link
|
|
>
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { fetchLicense, checkError } from "../../fetch"
|
|
import { setMessage, setError } from "../../messages"
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
license: {},
|
|
initialized: false,
|
|
}
|
|
},
|
|
beforeRouteEnter(to, from, next) {
|
|
next(vm => {
|
|
vm.license = vm.getLicense(to.params.license_id)
|
|
vm.initialized = true
|
|
})
|
|
},
|
|
methods: {
|
|
async getLicense(license_id) {
|
|
const license = await fetchLicense(license_id)
|
|
this.license = license
|
|
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",
|
|
},
|
|
}
|
|
|
|
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)
|
|
})
|
|
},
|
|
},
|
|
name: "LicensesFormConfirmDelete",
|
|
}
|
|
</script>
|