Bug 38010: Add basket page

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2024-10-15 13:48:44 +00:00 committed by Katrin Fischer
parent 533ab23c27
commit 1aa45fb9b8
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
6 changed files with 295 additions and 26 deletions

View File

@ -1,7 +1,7 @@
[% IF ( booksellerid ) %]
<div id="vendor-menu" class="sidebar_menu">
<ul>
[% IF ( CAN_user_acquisition_order_manage ) %]<li><a href="/cgi-bin/koha/vendors/[% booksellerid | uri %]">Baskets</a></li>[% END %]
[% IF ( CAN_user_acquisition_order_manage ) %]<li><a href="/cgi-bin/koha/vendors/[% booksellerid | uri %]/baskets">Baskets</a></li>[% END %]
[% IF ( CAN_user_acquisition_group_manage ) %]<li><a href="/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=[% booksellerid | uri %]">Basket groups</a></li>[% END %]
[% IF ( CAN_user_acquisition_contracts_manage ) %]<li><a href="/cgi-bin/koha/admin/aqcontract.pl?booksellerid=[% booksellerid | uri %]">Contracts</a></li>[% END %]
[% IF ( CAN_user_acquisition_issue_manage ) %]<li><a href="/cgi-bin/koha/acqui/vendor_issues.pl?booksellerid=[% booksellerid | uri %]">Vendor issues</a></li>[% END %]

View File

@ -12,7 +12,7 @@ export class AcquisitionAPIClient {
endpoint: "vendors/" + id,
headers: {
"x-koha-embed":
"baskets,aliases,subscriptions,interfaces,contacts,contracts",
"aliases,subscriptions,interfaces,contacts,contracts",
},
}),
getAll: (query, params) =>
@ -50,6 +50,21 @@ export class AcquisitionAPIClient {
}),
};
}
get baskets() {
return {
count: (query = {}) =>
this.count({
endpoint:
"baskets?" +
new URLSearchParams({
_page: 1,
_per_page: 1,
...(query && { q: JSON.stringify(query) }),
}),
}),
};
}
}
export default AcquisitionAPIClient;

View File

@ -0,0 +1,218 @@
<template>
<div id="vendor_baskets">
<div v-if="parseInt(basketCount) > 0" class="page-section">
<KohaTable
ref="table"
v-bind="tableOptions"
@show="doShow"
@edit="doEdit"
@delete="doDelete"
@select="doSelect"
></KohaTable>
</div>
<div v-else class="alert alert-info">
{{ $__("There are no baskets defined") }}
</div>
</div>
</template>
<script>
import { inject, ref } from "vue";
import { storeToRefs } from "pinia";
import KohaTable from "../KohaTable.vue";
export default {
setup() {
const vendorStore = inject("vendorStore");
const { vendors } = storeToRefs(vendorStore);
const { setConfirmationDialog, setMessage } = inject("mainStore");
const table = ref();
return {
vendors,
table,
setConfirmationDialog,
setMessage,
escape_str,
};
},
data() {
return {
fp_config: flatpickr_defaults,
initialized: false,
tableOptions: {
columns: this.getTableColumns(),
url: () => this.tableURL(),
add_filters: true,
// filters_options: {
// 1: [
// { _id: 0, _str: this.$__("Inactive") },
// { _id: 1, _str: this.$__("Active") },
// ],
// ...(this.map_av_dt_filter("vendor_types").length && {
// 2: () => this.map_av_dt_filter("vendor_types"),
// }),
// },
actions: {
"-1": ["edit", "delete"],
},
},
before_route_entered: false,
building_table: false,
};
},
methods: {
doShow({ id }, dt, event) {
event.preventDefault();
this.$router.push({
name: "VendorShow",
params: { vendor_id: id },
});
},
doEdit({ id }, dt, event) {
this.$router.push({
name: "VendorFormAddEdit",
params: { vendor_id: id },
});
},
doDelete(vendor, dt, event) {
this.setConfirmationDialog(
{
title: this.$__(
"Are you sure you want to remove this vendor?"
),
message: vendor.name,
accept_label: this.$__("Yes, delete"),
cancel_label: this.$__("No, do not delete"),
},
() => {
const client = APIClient.acquisition;
client.vendors.delete(vendor.id).then(
success => {
this.setMessage(
this.$__("Vendor %s deleted").format(
vendor.name
),
true
);
dt.draw();
},
error => {}
);
}
);
},
doSelect(vendor, dt, event) {
this.$emit("select-vendor", vendor.id);
this.$emit("close");
},
tableURL() {
let url =
"/api/v1/acquisitions/baskets?q=" +
JSON.stringify({ vendor_id: this.vendorId });
return url;
},
getTableColumns() {
const escape_str = this.escape_str;
const get_lib_from_av = this.get_lib_from_av;
return [
{
title: __("Name"),
data: "me.name:me.basket_id",
searchable: true,
orderable: true,
render(data, type, row, meta) {
return (
'<a href="/cgi-bin/koha/acqui/basket.pl?basket_id=' +
row.basket_id +
'" class="show">' +
escape_str(`${row.name} (#${row.basket_id})`) +
"</a>"
);
},
},
{
title: __("Item count"),
data: "name",
searchable: true,
orderable: true,
render(data, type, row, meta) {
return escape_str(row.name);
},
},
{
title: __("Bibliographic record count"),
data: "name",
searchable: true,
orderable: true,
render(data, type, row, meta) {
return escape_str(row.name);
},
},
{
title: __("Items expected"),
data: "name",
searchable: true,
orderable: true,
render(data, type, row, meta) {
return escape_str(row.name);
},
},
{
title: __("Created by"),
data: "creator_id",
searchable: true,
orderable: true,
},
{
title: __("Date"),
data: "creation_date",
searchable: true,
orderable: true,
},
{
title: __("Basket group"),
data: "basket_group_id",
searchable: true,
orderable: true,
},
{
title: __("Internal note"),
data: "note",
searchable: true,
orderable: true,
},
{
title: __("Close"),
data: "close_date",
searchable: true,
orderable: true,
},
];
},
},
components: { KohaTable },
props: {
basketCount: {
type: String,
default: "0",
},
vendorId: {
type: Number,
},
},
name: "VendorBaskets",
emits: ["select-vendor", "close"],
};
</script>
<style scoped>
.filters > label[for="by_mine_filter"],
.filters > input[type="checkbox"],
.filters > input[type="button"] {
margin-left: 1rem;
}
</style>

View File

@ -214,12 +214,12 @@ export default {
title: __("Baskets"),
data: "baskets",
searchable: false,
orderable: true,
orderable: false,
render(data, type, row, meta) {
return row.baskets.length
? '<a href="/cgi-bin/koha/vendors/' +
row.id +
'" class="show">' +
'/baskets" class="show">' +
escape_str(
`${row.baskets.length} basket(s)`
) +
@ -231,7 +231,7 @@ export default {
title: __("Subscriptions"),
data: "subscriptions",
searchable: false,
orderable: true,
orderable: false,
render(data, type, row, meta) {
return row.subscriptions.length
? '<a href="/cgi-bin/koha/serials/serials-search.pl?bookseller_filter=' +

View File

@ -28,27 +28,36 @@
<h1>
{{ vendor.name }}
</h1>
<div class="row">
<div class="col-sm-6">
<VendorDetails :vendor="vendor" :display="true" />
<VendorOrderingInformation :vendor="vendor" :display="true" />
<VendorInterfaces
:vendor="vendor"
v-if="vendor.interfaces.length > 0"
:display="true"
/>
<template v-if="!basketView">
<div class="row">
<div class="col-sm-6">
<VendorDetails :vendor="vendor" :display="true" />
<VendorOrderingInformation
:vendor="vendor"
:display="true"
/>
<VendorInterfaces
:vendor="vendor"
v-if="vendor.interfaces.length > 0"
:display="true"
/>
</div>
<div class="col-sm-6">
<VendorContacts :vendor="vendor" :display="true" />
<VendorSubscriptions :vendor="vendor" />
</div>
</div>
<div class="col-sm-6">
<VendorContacts :vendor="vendor" :display="true" />
<VendorSubscriptions :vendor="vendor" />
<div
class="page-section rows"
v-if="vendor.contracts && vendor.contracts.length > 0"
>
<VendorContracts :vendor="vendor" />
</div>
</div>
<div
class="page-section rows"
v-if="vendor.contracts && vendor.contracts.length > 0"
>
<VendorContracts :vendor="vendor" />
</div>
</template>
<template v-if="basketView">
<h2>{{ $__("Baskets") }}</h2>
<VendorBaskets :basketCount="basketCount" :vendorId="vendor.id" />
</template>
</div>
</template>
@ -63,6 +72,7 @@ import VendorInterfaces from "./VendorInterfaces.vue";
import VendorContacts from "./VendorContacts.vue";
import VendorSubscriptions from "./VendorSubscriptions.vue";
import VendorContracts from "./VendorContracts.vue";
import VendorBaskets from "./VendorBaskets.vue";
export default {
setup() {
@ -82,17 +92,26 @@ export default {
return {
vendor: null,
initialized: false,
basketView: false,
basketCount: null,
};
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.getVendor(to.params.vendor_id);
if (to.path.includes("basket")) {
vm.basketView = true;
vm.getVendor(to.params.vendor_id).then(() =>
vm.getBasketCount(to.params.vendor_id)
);
} else {
vm.getVendor(to.params.vendor_id);
}
});
},
methods: {
async getVendor(vendor_id) {
const client = APIClient.acquisition;
client.vendors.get(vendor_id).then(
await client.vendors.get(vendor_id).then(
vendor => {
this.vendor = vendor;
this.initialized = true;
@ -100,6 +119,16 @@ export default {
error => {}
);
},
async getBasketCount(booksellerid) {
const client = APIClient.acquisition;
await client.baskets.count({ booksellerid }).then(
count => {
this.basketCount = count;
this.initialized = true;
},
error => {}
);
},
},
components: {
Toolbar,
@ -111,6 +140,7 @@ export default {
VendorContacts,
VendorSubscriptions,
VendorContracts,
VendorBaskets,
},
name: "VendorShow",
};

View File

@ -50,6 +50,12 @@ export const routes = [
component: markRaw(VendorFormAdd),
title: $__("Edit vendor"),
},
{
path: ":vendor_id/baskets",
name: "VendorShowBaskets",
component: markRaw(VendorShow),
title: $__("Baskets"),
},
],
},
],