From 25210805e0e338b9b5853abd6c32555067bbcced Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Wed, 7 Aug 2024 10:51:31 +0000 Subject: [PATCH] Bug 37574: Add visual indicator that bookings are expired Adds a status column to the table configuration that displays whether a booking is active or expired (at the moment). This column is conditionally shown in the 'Show Expired' state, meaning after expired bookings are loaded into the table. To test: 1) Create a couple booking for any item for a single patron. 2) Open a db shell with `koha-mysql ` 3) Update one or two of the created bookings with: update bookings set start_date = '', end_date = ' where booking_id = ''. 4) Go the the bookings tab of said item. 5) Click the 'Show Expired' option in the top left of the table. 6) Note that bookings are tagged with 'Expired' and 'Active'. 7) Repeat 5 and 6 for the bookings tab in the patron's details view. 8) Sign off. Note: the bootstrap classes for v5 are already included so they become colored once the patch is in. Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- admin/columns_settings.yml | 3 ++ .../prog/en/modules/bookings/list.tt | 24 +++++++++++++- .../intranet-tmpl/prog/js/tables/bookings.js | 33 ++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index 0a9fc82fa1..f91c6acaaf 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -1210,6 +1210,9 @@ modules: - columnname: booking_id is_hidden: 1 + - + columnname: status + is_hidden: 1 - columnname: title - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index cce9a668b9..f6d9447908 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -229,6 +229,22 @@ "title": _("Booking ID"), "visible": false }, + { + data: "", + title: __("Status"), + name: "status", + searchable: true, + orderable: true, + visible: false, + render: function (data, type, row, meta) { + let is_expired = dayjs(row.end_date).isBefore(new Date()); + if (is_expired) { + return '' + __("Expired") + ''; + } + + return '' + __("Active") + ''; + } + }, { "data": "item.external_id", "title": _("Item"), @@ -309,7 +325,13 @@ filter_expired = true; $(this).html(' '+txtActivefilter); } - bookings_table.DataTable().draw(); + + bookings_table.DataTable().ajax.reload(() => { + bookings_table + .DataTable() + .column("status:name") + .visible(!filter_expired, false); + }); $(this).toggleClass('filtered'); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js index 69ce63615d..fa3469c062 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js +++ b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js @@ -32,6 +32,31 @@ $(document).ready(function () { data: "booking_id", title: __("Booking ID"), }, + { + data: "", + title: __("Status"), + name: "status", + searchable: true, + orderable: true, + render: function (data, type, row, meta) { + let is_expired = dayjs(row.end_date).isBefore( + new Date() + ); + if (is_expired) { + return ( + '' + + __("Expired") + + "" + ); + } + + return ( + '' + + __("Active") + + "" + ); + }, + }, { data: "biblio.title", title: __("Title"), @@ -118,7 +143,13 @@ $(document).ready(function () { filter_expired = true; $(this).html(' ' + txtActivefilter); } - bookings_table.DataTable().draw(); + + bookings_table.DataTable().ajax.reload(() => { + bookings_table + .DataTable() + .column("status:name") + .visible(!filter_expired, false); + }); $(this).toggleClass("filtered"); }); }); -- 2.39.5