Bugzilla – Attachment 174821 Details for
Bug 38436
Adjust code for column visibility (after DataTables upgrade)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38436: Fix OPAC tables
Bug-38436-Fix-OPAC-tables.patch (text/plain), 16.07 KB, created by
Jonathan Druart
on 2024-11-20 09:34:59 UTC
(
hide
)
Description:
Bug 38436: Fix OPAC tables
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-11-20 09:34:59 UTC
Size:
16.07 KB
patch
obsolete
>From 28e0c762bc7d25e3913935d5c925dbdd8a44ae34 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 20 Nov 2024 10:32:13 +0100 >Subject: [PATCH] Bug 38436: Fix OPAC tables > >This patch sync columns_settings.inc for the OPAC-side > >It however removes 'api' from datatables.js as it is never used. >'api' was renamed 'kohaTable' on bug 29408 but OPAC was forgotten. > >Better to not have to deal with this unused code for now, we will >reintroduce it if needed later. >--- > .../en/includes/columns_settings.inc | 74 +++++-- > .../bootstrap/en/modules/opac-detail.tt | 10 +- > .../opac-tmpl/bootstrap/js/datatables.js | 198 ------------------ > 3 files changed, 57 insertions(+), 225 deletions(-) > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc >index 6fe51008c32..0c5317adf90 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc >@@ -1,24 +1,31 @@ > [% USE TablesSettings %] > > <script> >-function KohaTable(selector, dt_parameters, columns_settings) { >- var id = 0; >- var hidden_ids = []; >- var included_ids = []; >- $(columns_settings).each( function() { >- var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector+' th' ); >- >- var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id; >- if ( used_id == -1 ) return; >- >- if ( this['is_hidden'] == "1" ) { >- hidden_ids.push( used_id ); >- } >- if ( this['cannot_be_toggled'] == "0" ) { >- included_ids.push( used_id ); >+ >+function _dt_visibility(table_settings, table_dt){ >+ let hidden_ids = []; >+ if ( table_settings ) { >+ var columns_settings = table_settings.columns; >+ let i = 0; >+ let use_names = $(table_dt.table().node()).data('bKohaColumnsUseNames'); >+ if ( use_names ) { >+ let hidden_columns = table_settings.columns.filter(c => c.is_hidden); >+ if (!hidden_columns.length) return []; >+ table_dt.columns(hidden_columns.map(c => "[data-colname='%s']".format(c.columnname)).join(',')).every(function(){ >+ hidden_ids.push(this.index()); >+ }); >+ } else { >+ $(columns_settings).each( function(i, c) { >+ if ( c.is_hidden == '1' ) { >+ hidden_ids.push(i); >+ } >+ }); > } >- id++; >- }); >+ } >+ return hidden_ids; >+} >+ >+function KohaTable(selector, dt_parameters, table_settings) { > > // By default we include all visible columns in exports and print unless they have the "noExport" class > var exportColumns = ":visible:not(.noExport)"; >@@ -79,12 +86,31 @@ function KohaTable(selector, dt_parameters, columns_settings) { > } > ]; > >- if( included_ids.length > 0 ){ >+ // Retrieving bKohaColumnsUseNames from the options passed to the constructor, not DT settings >+ // But ideally should be retrieved using table.data() >+ let use_names = dt_parameters.bKohaColumnsUseNames; >+ let included_columns = []; >+ if (table_settings) { >+ if (use_names) { >+ // bKohaColumnsUseNames is set, identify columns by their data-colname >+ included_columns = table_settings.columns >+ .filter(c => !c.cannot_be_toggled) >+ .map(c => "[data-colname='%s']".format(c.columnname)) >+ .join(","); >+ } else { >+ // Not set, columns are ordered the same than in the columns settings >+ included_columns = table_settings.columns >+ .map((c, i) => (!c.cannot_be_toggled ? i : null)) >+ .filter(i => i !== null); >+ } >+ } >+ >+ if( included_columns.length > 0 ){ > dt_parameters[ "buttons" ].push( > { > extend: 'colvis', > fade: 100, >- columns: included_ids, >+ columns: included_columns, > className: "columns_controls", > titleAttr: _("Columns settings"), > text: '<i class="fa fa-lg fa-gear" aria-hidden="true"></i> <span class="dt-button-text">' + _("Columns") + '</span>', >@@ -96,6 +122,7 @@ function KohaTable(selector, dt_parameters, columns_settings) { > } > > var table = $(selector); >+ > var new_parameters = {} > $.extend(true, new_parameters, dataTablesDefaults, dt_parameters); > var default_column_defs = [ >@@ -109,8 +136,13 @@ function KohaTable(selector, dt_parameters, columns_settings) { > $.extend(true, new_parameters, default_column_defs); > } > >+ $(table).data('bKohaColumnsUseNames', dt_parameters.bKohaColumnsUseNames); >+ > table.dataTable(new_parameters); >- table.DataTable().on("column-visibility.dt", function () { >+ var table_dt = table.DataTable(); >+ >+ let hidden_ids = _dt_visibility(table_settings, table_dt); >+ table_dt.on("column-visibility.dt", function () { > if (typeof columnsInit == 'function') { > // This function can be created separately and used to trigger > // an event after the DataTable has loaded AND column visibility >@@ -119,8 +151,6 @@ function KohaTable(selector, dt_parameters, columns_settings) { > } > }).columns(hidden_ids).visible(false); > >- $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); >- > return table; > } > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index 0866e7dd451..38ce3032663 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -1742,7 +1742,7 @@ > }); > [% END # /IF OpacBrowseResults %] > >- var columns_settings = [% TablesSettings.GetColumns( 'opac', 'biblio-detail', 'holdingst', 'json' ) | $raw %]; >+ var table_settings = [% TablesSettings.GetTableSettings( 'opac', 'biblio-detail', 'holdingst', 'json' ) | $raw %]; > > KohaTable("#holdingst", { > dom: '<"clearfix">t', >@@ -1753,7 +1753,7 @@ > "responsive": { > "details": { "type": 'column', "target": -1 } > } >- }, columns_settings); >+ }, table_settings); > > KohaTable("#otherholdingst", { > dom: '<"clearfix">t', >@@ -1764,9 +1764,9 @@ > "responsive": { > "details": { "type": 'column', "target": -1 } > } >- }, columns_settings); >+ }, table_settings); > >- var serial_column_settings = [% TablesSettings.GetColumns( 'opac', 'biblio-detail', 'subscriptionst', 'json' ) | $raw %]; >+ var serial_table_settings = [% TablesSettings.GetTableSettings( 'opac', 'biblio-detail', 'subscriptionst', 'json' ) | $raw %]; > > KohaTable("#subscriptionst", { > dom: '<"clearfix">t', >@@ -1778,7 +1778,7 @@ > "columnDefs": [ > { "className": "dtr-control", "orderable": false, "targets": -1 } > ], >- }, serial_column_settings); >+ }, serial_table_settings); > > var dTables = $("#holdingst,#subscriptionst,#otherholdingst"); > $('a[data-bs-toggle="tab"]').on('shown.bs.tab', function (event) { >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js >index b11d57372fa..ec44f993a58 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js >@@ -117,201 +117,3 @@ $.fn.dataTable.ext.buttons.clearFilter = { > }); > > }()); >- >-(function($) { >- >- $.fn.api = function(options, columns_settings, add_filters) { >- var settings = null; >- if(options) { >- if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains'; >- options.criteria = options.criteria.toLowerCase(); >- settings = $.extend(true, {}, dataTablesDefaults, { >- "paging": true, >- 'serverSide': true, >- 'searching': true, >- 'processing': true, >- 'language': { >- 'emptyTable': (options.emptyTable) ? options.emptyTable : "No data available in table" >- }, >- 'pagingType': 'full', >- 'ajax': { >- 'type': 'GET', >- 'cache': true, >- 'dataSrc': 'data', >- 'beforeSend': function(xhr, settings) { >- this._xhr = xhr; >- if(options.embed) { >- xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed); >- } >- }, >- 'dataFilter': function(data, type) { >- var json = {data: JSON.parse(data)}; >- if(total = this._xhr.getResponseHeader('x-total-count')) { >- json.recordsTotal = total; >- json.recordsFiltered = total; >- } >- if(total = this._xhr.getResponseHeader('x-base-total-count')) { >- json.recordsTotal = total; >- } >- return JSON.stringify(json); >- }, >- 'data': function( data, settings ) { >- var length = data.length; >- var start = data.start; >- >- var dataSet = { >- _page: Math.floor(start/length) + 1, >- _per_page: length >- }; >- >- var filter = data.search.value; >- var query_parameters = settings.aoColumns >- .filter(function(col) { >- return col.bSearchable && typeof col.data == 'string' && (data.columns[col.idx].search.value != '' || filter != '') >- }) >- .map(function(col) { >- var part = {}; >- var value = data.columns[col.idx].search.value != '' ? data.columns[col.idx].search.value : filter; >- part[!col.data.includes('.')?'me.'+col.data:col.data] = options.criteria === 'exact'?value:{like: (['contains', 'ends_with'].indexOf(options.criteria) !== -1?'%':'')+value+(['contains', 'starts_with'].indexOf(options.criteria) !== -1?'%':'')}; >- return part; >- }); >- >- if(query_parameters.length) { >- query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters); >- dataSet.q = query_parameters; >- } >- >- dataSet._match = options.criteria; >- >- if(options.columns) { >- var order = data.order; >- order.forEach(function (e,i) { >- var order_col = e.column; >- var order_by = options.columns[order_col].data; >- var order_dir = e.dir == 'asc' ? '+' : '-'; >- dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by); >- }); >- } >- >- return dataSet; >- } >- } >- }, options); >- } >- >- var counter = 0; >- var hidden_ids = []; >- var included_ids = []; >- >- $(columns_settings).each( function() { >- var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' ); >- var used_id = settings.bKohaColumnsUseNames ? named_id : counter; >- if ( used_id == -1 ) return; >- >- if ( this['is_hidden'] == "1" ) { >- hidden_ids.push( used_id ); >- } >- if ( this['cannot_be_toggled'] == "0" ) { >- included_ids.push( used_id ); >- } >- counter++; >- }); >- >- var exportColumns = ":visible:not(.noExport)"; >- if( settings.hasOwnProperty("exportColumns") ){ >- // A custom buttons configuration has been passed from the page >- exportColumns = settings["exportColumns"]; >- } >- >- var export_format = { >- body: function ( data, row, column, node ) { >- var newnode = $(node); >- >- if ( newnode.find(".noExport").length > 0 ) { >- newnode = newnode.clone(); >- newnode.find(".noExport").remove(); >- } >- >- return newnode.text().replace( /\n/g, ' ' ).trim(); >- } >- }; >- >- var export_buttons = [ >- { >- extend: 'excelHtml5', >- exportOptions: { >- columns: exportColumns, >- format: export_format >- }, >- }, >- { >- extend: 'csvHtml5', >- exportOptions: { >- columns: exportColumns, >- format: export_format >- }, >- }, >- { >- extend: 'copyHtml5', >- exportOptions: { >- columns: exportColumns, >- format: export_format >- }, >- }, >- { >- extend: 'print', >- exportOptions: { >- columns: exportColumns, >- format: export_format >- }, >- } >- ]; >- >- settings[ "buttons" ] = [ >- { >- fade: 100, >- className: "dt_button_clear_filter", >- titleAttr: __("Clear filter"), >- enabled: false, >- text: '<i class="fa fa-lg fa-times"></i> <span class="dt-button-text">' + __("Clear filter") + '</span>', >- action: function ( e, dt, node ) { >- dt.search( "" ).draw("page"); >- node.addClass("disabled"); >- } >- } >- ]; >- >- if( included_ids.length > 0 ){ >- settings[ "buttons" ].push( >- { >- extend: 'colvis', >- fade: 100, >- columns: included_ids, >- className: "columns_controls", >- titleAttr: __("Columns settings"), >- text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + __("Columns") + '</span>', >- exportOptions: { >- columns: exportColumns >- } >- } >- ); >- } >- >- settings[ "buttons" ].push( >- { >- extend: 'collection', >- autoClose: true, >- fade: 100, >- className: "export_controls", >- titleAttr: __("Export or print"), >- text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + __("Export") + '</span>', >- buttons: export_buttons >- } >- ); >- >- $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); >- >- return $(this).dataTable(settings); >- }; >- >-})(jQuery); >-- >2.34.1
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 38436
:
174587
|
174588
|
174589
|
174590
|
174591
|
174592
|
174593
|
174594
|
174595
|
174634
|
174641
|
174642
|
174688
|
174689
|
174690
|
174691
|
174692
|
174693
|
174694
|
174695
|
174696
|
174697
|
174698
|
174699
|
174700
|
174701
|
174702
|
174721
|
174722
|
174723
|
174724
|
174725
|
174726
|
174727
|
174728
|
174729
|
174730
|
174731
|
174732
|
174733
|
174734
|
174735
|
174736
|
174740
|
174741
|
174742
|
174743
|
174744
|
174745
|
174746
|
174747
|
174748
|
174749
|
174750
|
174751
|
174752
|
174753
|
174754
|
174755
|
174756
|
174766
|
174767
|
174768
|
174769
|
174770
|
174771
|
174772
|
174773
|
174774
|
174775
|
174776
|
174777
|
174778
|
174779
|
174780
|
174781
|
174782
| 174821 |
174967