From 3a7fab37957546b634f23916d5d397ab7a558a6e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 Nov 2024 17:29:56 +0100 Subject: [PATCH] Bug 38485: Take user's previous change into consideration for holdings tables col vis A lot happened, hard to summarize everything. Basically at this point, we have (among other things): * fixed bug 38118 (but reintroduced it with bug 36640) * fixed bug 38436 (the original report was that the is_hidden setting was no longer taken into effect on the holdings tables) Here we are trying to deal with making user's previous changes persistent across the pagination and col vis changes. Test plan: Confirm that hiding checkouts in settings hide the columns Confirm that showing checkouts then change page (*pagination*, so you need more than 20 items) and confirm that the columns are still the same Add a callnumber for an item from page 2 and confirm that the column is hidden on page 1 and shown on page 2 Hide callnumber from the settings and confirm that the column is hidden on pages 1 and 2 Show callnumber from the holdings page and confirm that the column is displayed on page 2, go page 1: hidden, go back page 2: displayed. And certainly way more other things to test, just confirm that the behaviours with this patch are consistent with what a end user would expect. Note for QA/self: this is not very nice as column-visibility.dt event can change in datatables.js and not impact this one. Also the following nice sounds good and should be added to datatables.js + if (recalc === false) return; --- .../tables/items/catalogue_detail.inc | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) 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 b669faa42e2..9fa81b87f71 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 @@ -123,9 +123,11 @@ } } - function update_columns_visibility(settings){ - let table = settings.oInstance.api(); - table.columns().every(function(){ + function update_columns_visibility(table_dt, table_settings, user_colvis){ + table_dt.columns().visible(true, false); + let hidden_ids = _dt_visibility(table_settings, table_dt); + table_dt.columns(hidden_ids).visible(false, false); + table_dt.columns().every(function(){ let i = this.index(); let is_empty = true; let nodes = this.nodes(); @@ -136,9 +138,12 @@ } }); if ( is_empty ) { - table.columns(i).visible(false, false); + table_dt.columns(i).visible(false, false); } }); + for (const [key, value] of Object.entries(user_colvis)) { + table_dt.columns(key).visible(value, false); + } } @@ -264,6 +269,7 @@ otherholdings: [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json') | $raw %], }; + let user_colvis = {holdings: {}, otherholdings: {}}; let table_nodes = { holdings: "[% PROCESS 'build_table' tab="holdings" | collapse | $tojson %]", otherholdings: "[% PROCESS 'build_table' tab="otherholdings" | collapse | $tojson %]", @@ -849,7 +855,7 @@ [% END %] if ( api.data().length ) { - update_columns_visibility(settings); + update_columns_visibility(api, items_table_settings[tab_id], user_colvis[tab_id]); } if ( drawcallback ) { drawcallback(this); } @@ -862,6 +868,15 @@ filters_options, ); + let table_dt = items_table.DataTable(); + table_dt.on("column-visibility.dt", function(e, settings, column, state, recalc ){ + if (recalc === false) return; + + _dt_add_filters(this, table_dt, filters_options); + + user_colvis[tab_id][column] = state; + + }); return items_table; } function safe_link(uri,link_text) { -- 2.34.1