Bugzilla – Attachment 133717 Details for
Bug 22276
Add client storage of user-selected DataTables configuration
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22276: Add client storage of user-selected DataTables configuration
Bug-22276-Add-client-storage-of-user-selected-Data.patch (text/plain), 5.34 KB, created by
Katrin Fischer
on 2022-04-24 12:46:06 UTC
(
hide
)
Description:
Bug 22276: Add client storage of user-selected DataTables configuration
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-04-24 12:46:06 UTC
Size:
5.34 KB
patch
obsolete
>From a6d04edc4496ba94d6e78d5a2f7c2bb2c0729cf4 Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Fri, 28 Jan 2022 13:00:04 +0000 >Subject: [PATCH] Bug 22276: Add client storage of user-selected DataTables > configuration >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch enables use of DataTables' built-in session storage of table >configurations. DataTables by default uses the browser's localstorage >feature to store the state of each DataTable, including which columns >have been hidden by the user. > >Our table settings system has always overridden this saved state. This >patch adds a check for a saved configuration state and if present loads >the saved state instead of the default state. > >The system is enabled in this patch on the libraries administration >page. To test, apply the patch and open go to Administration -> >Libraries. > >- Use the "Columns" button to change the visibility setting of multiple > columns. >- Navigate away from the page and then back to test that the visibility > settings have been kept. >- Go to Administration -> Table settings -> Administration and change > the visibility settings for the "libraries" table in a way that it > differs from the visibility settings you set manually. >- Return to the libraries administration page and confirm that your > manual settings are still being loaded instead of the defaults from > table settings. > >Signed-off-by: Solène Desvaux <solene.desvaux@biblibre.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > .../prog/en/includes/columns_settings.inc | 39 +++++++++++++++++++ > .../prog/en/modules/admin/branches.tt | 6 ++- > 2 files changed, 44 insertions(+), 1 deletion(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >index 42d4fb09bc..81d683b785 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >@@ -206,5 +206,44 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { > return table; > } > >+ >+/* get_columns_saved_state checks for a DataTables configuration saved >+* in the browser's local storage. If it is present, the columns >+* configuration supplied by Koha is overwritten >+* >+* It takes two parameters: >+* - localstorage_config, the DataTables saved state object from local storage >+* - columns_settings, the columns settings object supplied by the template >+* >+* An example: >+* >+* var columns_settings = [% ColumnsSettings.GetColumns( 'module', 'page', 'table', 'json' ) | $raw %]; >+* var saved_table = localStorage.getItem("DataTables_TABLE_ID_/cgi-bin/koha/PATH/TO/SCRIPT.pl"); >+* var updated_settings = get_columns_saved_state( saved_table, columns_settings ); >+* >+* KohaTable("TABLE_ID", { >+* "stateSave": true >+* }, updated_settings); >+*/ >+ >+function get_columns_saved_state( localstorage_config, columns_settings ){ >+ var tables = JSON.parse( localstorage_config ); >+ // if a table configuration was found in local storage, parse it >+ if( tables ){ >+ var stateSave_column_visibility = []; >+ $(tables.columns).each(function(){ >+ stateSave_column_visibility.push( this.visible === true ? 0 : 1 ); >+ }); >+ $.each( columns_settings, function( index, key ){ >+ if( stateSave_column_visibility[ index ] !== columns_settings[key] ){ >+ columns_settings[ index ].is_hidden = stateSave_column_visibility[ index ]; >+ } >+ }); >+ return columns_settings; >+ } else { >+ return columns_settings; >+ } >+} >+ > </script> > <!-- / columns_settings.inc --> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >index 6de1d61861..4ba1729680 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >@@ -342,6 +342,9 @@ Libraries › Administration › Koha > [% INCLUDE 'str/tinymce_i18n.inc' %] > <script> > var columns_settings = [% TablesSettings.GetColumns( 'admin', 'libraries', 'libraries', 'json' ) | $raw %]; >+ var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl"); >+ var updated_settings = get_columns_saved_state(saved_table, columns_settings); >+ > $(document).ready(function() { > > var libraries_url = '/api/v1/libraries'; >@@ -351,6 +354,7 @@ Libraries › Administration › Koha > }, > 'embed': [ 'smtp_server' ], > 'emptyTable': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>', >+ "stateSave": true, > "columnDefs": [ { > "targets": [0,1,3,4,7,9,10,11,12,13,14,15,16], > "render": function (data, type, row, meta) { >@@ -514,7 +518,7 @@ Libraries › Administration › Koha > "orderable": false > } > ] >- }, columns_settings); >+ }, updated_settings); > > [% UNLESS library %] > $("#Aform").on("submit", function( event ) { >-- >2.30.2
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 22276
:
129938
|
130548
|
133717
|
133718
|
138172
|
138173