Bugzilla – Attachment 192995 Details for
Bug 38122
Cannot sort holdings table by status
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38122: (follow-up) Correct item regrouping behavior
Bug-38122-follow-up-Correct-item-regrouping-behavi.patch (text/plain), 8.38 KB, created by
Ayoub Glizi-Vicioso
on 2026-02-11 21:44:56 UTC
(
hide
)
Description:
Bug 38122: (follow-up) Correct item regrouping behavior
Filename:
MIME Type:
Creator:
Ayoub Glizi-Vicioso
Created:
2026-02-11 21:44:56 UTC
Size:
8.38 KB
patch
obsolete
>From c965db17959104924b44340983f54e6c9c581e6d Mon Sep 17 00:00:00 2001 >From: Ayoub Glizi-Vicioso <ayoub.glizi-vicioso@inLibro.com> >Date: Wed, 11 Feb 2026 16:35:56 -0500 >Subject: [PATCH] Bug 38122: (follow-up) Correct item regrouping behavior > >--- > Koha/REST/V1/Biblios.pm | 24 ++-- > .../tables/items/catalogue_detail.inc | 108 ++++++++++++++++-- > 2 files changed, 116 insertions(+), 16 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index d9e689850b..d85a60fa02 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -271,17 +271,25 @@ sub get_items { > > if ($group_by_status) { > $c->req->params->remove('_order_by'); >- my @item_ids; >- for my $status ( >- qw( available checked_out local_use in_transit lost withdrawn damaged not_for_loan on_hold recalled in_bundle restricted ) >- ) >- { >- push @item_ids, $items_rs->search( { _status => $status } )->get_column('itemnumber'); >- } > $items_rs = $items_rs->search( > {}, > { >- order_by => [ \[ sprintf( "field(me.itemnumber, %s)", join( ', ', map { qq{'$_'} } @item_ids ) ) ] ] >+ order_by => [ >+ \[ "CASE >+ WHEN (withdrawn != 0) THEN '10_Withdrawn' >+ WHEN (itemlost != 0) THEN '09_Lost' >+ WHEN (damaged != 0) THEN '08_Damaged' >+ WHEN (notforloan = 3) THEN '07_In bundle' >+ WHEN (notforloan != 0) THEN '06_Not for loan' >+ WHEN EXISTS (SELECT 1 FROM issues WHERE itemnumber = me.itemnumber AND onsite_checkout = 1) THEN '05_Local use' >+ WHEN (onloan IS NOT NULL) THEN '04_Checked out' >+ WHEN (SELECT COUNT(*) FROM branchtransfers WHERE itemnumber = me.itemnumber AND datearrived IS NULL) > 0 THEN '03_In transit' >+ WHEN (SELECT COUNT(*) FROM reserves WHERE itemnumber = me.itemnumber AND (found IS NULL OR found = 'W')) > 0 THEN '02_On hold' >+ ELSE '01_Available' >+ END ASC" ], >+ { -asc => 'me.itemlost' }, >+ { -asc => 'me.notforloan' }, >+ ] > } > ); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc >index a9ac561d15..4c8ecc3d87 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc >@@ -301,19 +301,111 @@ > holdings: false, > otherholdings: false, > }; >- $(".GroupByStatus").on("click",function(e){ >+ >+ function get_display_status(row, forSort = false) { >+ let status = ""; >+ let priority = ""; >+ >+ if (!row._status) row._status = []; >+ >+ if (row.withdrawn != 0) { >+ status = _("Withdrawn"); >+ priority = "10"; >+ } else if (row.lost_status != 0) { >+ let lost_text = av_lost.get(row.lost_status.toString()) || _("Lost"); >+ status = lost_text; >+ if (forSort) { >+ if (lost_text.toLowerCase().includes("paid")) priority = "09c"; >+ else if (lost_text.toLowerCase().includes("overdue")) priority = "09b"; >+ else priority = "09a"; >+ } else { >+ priority = "09"; >+ } >+ } >+ else if (row.damaged_status != 0) { >+ status = _("Damaged"); >+ priority = "08"; >+ } >+ else if (row.not_for_loan_status == 3) { >+ status = _("In bundle"); >+ priority = "07"; >+ } else if (row.not_for_loan_status != 0) { >+ status = _("Not for loan"); >+ priority = "06"; >+ } >+ else if (row._status.includes('local_use')) { >+ status = _("Local use"); >+ priority = "05"; >+ } >+ else if (row._status.includes('checked_out')) { >+ status = _("Checked out"); >+ priority = "04"; >+ } >+ else if (row._status.includes('in_transit')) { >+ status = _("In transit"); >+ priority = "03"; >+ } >+ else if (row._status.includes('on_hold') || row._status.includes('waiting')) { >+ status = _("On hold"); >+ priority = "02"; >+ } >+ else if (row._status.includes('available') || (row.lost_status == 0 && row.withdrawn == 0)) { >+ status = _("Available"); >+ priority = "01"; >+ } >+ else { >+ status = _("Undefined"); >+ priority = "99"; >+ } >+ >+ status = status.trim(); >+ >+ if (forSort) { >+ if (priority.startsWith("09")) { >+ return "09_" + _("Lost"); >+ } >+ return priority + "_" + status; >+ } >+ >+ return status; >+ } >+ >+ $(".GroupByStatus").on("click", function(e) { > e.preventDefault(); > let tab_id = $(this).data("tab"); >- let was_grouped = group_by_status_values[tab_id]; >- group_by_status_values[tab_id] = !was_grouped; >+ group_by_status_values[tab_id] = !group_by_status_values[tab_id]; >+ let is_grouping = group_by_status_values[tab_id]; >+ >+ var dt_options = { >+ "destroy": true, >+ }; > >- build_items_table(tab_id, true, { destroy: true }, build_items_table_drawncallback ); >+ if (is_grouping) { >+ dt_options["rowGroup"] = { >+ "dataSrc": function(row) { >+ return get_display_status(row, true); >+ }, >+ "startRender": function (rows, group) { >+ let displayTitle = group.indexOf('_') !== -1 ? group.split('_')[1] : group; >+ >+ let groupColor = "#007bff"; >+ >+ if (group.startsWith("01")) { >+ groupColor = "#28a745"; >+ } else if (group.startsWith("08") || group.startsWith("09") || group.startsWith("10")) { >+ groupColor = "#dc3545"; >+ } >+ >+ return $('<tr class="group-header"><td colspan="30" style="background-color:#f8f9fa; font-weight:bold; border-left:5px solid ' + groupColor + '; padding:10px;">' >+ + displayTitle + ' (' + rows.count() + ')</td></tr>'); >+ } >+ }; > >- if ( was_grouped ) { >- $(this).html('<i class="fa fa-object-group"></i> ' + _("Group by status") + '</button>'); >+ $(this).html('<i class="fa fa-object-ungroup"></i> ' + _("Ungroup by status") + '</button>'); > } else { >- $(this).html('<i class="fa fa-object-ungroup"></i> '+ _("Ungroup by status") + '</button>'); >+ $(this).html('<i class="fa fa-object-group"></i> '+ _("Group by status") + '</button>'); > } >+ build_items_table(tab_id, true, dt_options, build_items_table_drawncallback, { group_by_status: is_grouping ? 1 : 0 }); > }); > > function build_items_table (tab_id, add_filters, dt_options, drawcallback) { >@@ -570,7 +662,7 @@ > } > > if ( status == 'lost' ) { >- let lost_lib = av_lost.get(row.lost_status.toString()) || _("Unavailable (lost or missing"); >+ let lost_lib = av_lost.get(row.lost_status.toString()) || _("Unavailable (lost or missing)"); > nodes += '<span class="lost">%s</span>'.format(escape_str(lost_lib)); > > const hasReturnClaims = row.return_claims && row.return_claims.filter(rc => !rc.resolution).length > 0 ? true : false >-- >2.52.0
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 38122
:
183789
|
184550
|
187227
|
187410
|
191419
|
191420
|
191421
|
191423
|
191424
|
191425
|
191426
|
191529
|
191530
|
191531
|
191532
|
192992
|
192993
|
192994
|
192995
|
193149
|
193150
|
193151
|
193152
|
193153