From 703239aac65565df3bf7d4f61d8f4ce7123f8741 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 19 Apr 2023 18:03:05 +0100 Subject: [PATCH] Bug 33484: Add save state option to table settings Amended-by: Jonathan Druart Drop changes to admin/columns_settings.yml to avoid conflict. Just assume that 1 is the default (see next patch) Add +x to atomicupdate Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Utils/DataTables/TablesSettings.pm | 11 ++++++++--- admin/columns_settings.pl | 5 ++++- installer/data/mysql/atomicupdate/bug_33484.pl | 17 +++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/includes/columns_settings.inc | 4 ++++ .../prog/en/modules/admin/columns_settings.tt | 10 ++++++++++ koha-tmpl/intranet-tmpl/prog/js/datatables.js | 3 +++ t/db_dependent/TablesSettings.t | 4 ++++ 8 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_33484.pl diff --git a/C4/Utils/DataTables/TablesSettings.pm b/C4/Utils/DataTables/TablesSettings.pm index 71ec3f3f7b..28e1b257c5 100644 --- a/C4/Utils/DataTables/TablesSettings.pm +++ b/C4/Utils/DataTables/TablesSettings.pm @@ -103,7 +103,9 @@ sub get_table_settings { default_display_length => $rs ? $rs->default_display_length : $list->{modules}{$module}{$page}{$tablename}{default_display_length}, default_sort_order => $rs ? $rs->default_sort_order - : $list->{modules}{$module}{$page}{$tablename}{default_sort_order} + : $list->{modules}{$module}{$page}{$tablename}{default_sort_order}, + default_save_state => $rs ? $rs->default_save_state + : $list->{modules}{$module}{$page}{$tablename}{default_save_state}, }; } @@ -153,10 +155,11 @@ sub update_columns { C4::Utils::DataTables::TablesSettings::update_table_settings( { module => $module, - pag => $page, + page => $page, tablename => $tablename, default_display_length => $default_display_length, - default_sort_order => $default_sort_order + default_sort_order => $default_sort_order, + default_save_state => $default_save_state, } ); @@ -171,6 +174,7 @@ sub update_table_settings { my $tablename = $params->{tablename}; my $default_display_length = $params->{default_display_length}; my $default_sort_order = $params->{default_sort_order}; + my $default_save_state = $params->{default_save_state}; my $schema = Koha::Database->new->schema; @@ -181,6 +185,7 @@ sub update_table_settings { tablename => $tablename, default_display_length => $default_display_length, default_sort_order => $default_sort_order, + default_save_state => $default_save_state, } ); } diff --git a/admin/columns_settings.pl b/admin/columns_settings.pl index 96d591d7bb..02e563882f 100755 --- a/admin/columns_settings.pl +++ b/admin/columns_settings.pl @@ -50,11 +50,13 @@ if ( $op eq 'cud-save' ) { next unless $table_id =~ m{^([^\|]*)\|(.*)$}; my $default_display_length = $input->param( $table_id . '_default_display_length' ); my $default_sort_order = $input->param( $table_id . '_default_sort_order' ); + my $default_save_state = $input->param( $table_id . '_default_save_state' ); undef $default_display_length if defined $default_display_length && $default_display_length eq ""; undef $default_sort_order if defined $default_sort_order && $default_sort_order eq ""; + $default_save_state = 0 if !defined($default_save_state); - if ( defined $default_display_length || defined $default_sort_order ) + if ( defined $default_display_length || defined $default_sort_order || defined $default_save_state ) { C4::Utils::DataTables::TablesSettings::update_table_settings( { @@ -63,6 +65,7 @@ if ( $op eq 'cud-save' ) { tablename => $2, default_display_length => $default_display_length, default_sort_order => $default_sort_order, + default_save_state => $default_save_state, } ); } diff --git a/installer/data/mysql/atomicupdate/bug_33484.pl b/installer/data/mysql/atomicupdate/bug_33484.pl new file mode 100755 index 0000000000..6107368cb9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_33484.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "33484", + description => "Add state save as an option to datatables", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + if ( !column_exists( 'tables_settings', 'default_save_state' ) ) { + $dbh->do(q{ + ALTER TABLE tables_settings + ADD COLUMN default_save_state tinyint(1) DEFAULT NULL AFTER default_sort_order + }); + say $out "Added column 'tables_settings.default_save_state'"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 562723efd0..df6f7a75ff 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -6296,6 +6296,7 @@ CREATE TABLE `tables_settings` ( `tablename` varchar(255) NOT NULL, `default_display_length` smallint(6) DEFAULT NULL, `default_sort_order` varchar(255) DEFAULT NULL, + `default_save_state` tinyint(1) DEFAULT NULL, PRIMARY KEY (`module`(191),`page`(191),`tablename`(191)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; 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 1e45ef30f5..e3f98e6d17 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -45,6 +45,10 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { } counter++; }); + + if ( table_settings.hasOwnProperty('default_save_state') && table_settings['default_save_state'] === 0 ) { + localStorage.removeItem(table_key); + } } var exportColumns = ":visible:not(.noExport)"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt index 28a3b2a0ea..5e7cc7e6d3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt @@ -148,6 +148,16 @@

[% END %] + [% IF table_settings.default_save_state.defined %] +

+ Save state on page change: + [%- IF table_settings.default_save_state -%] + + [%- ELSE -%] + + [%- END -%] +

+ [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 38a7fe7f79..a66ed803ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1035,6 +1035,9 @@ function _dt_get_saved_state( localstorage_config, columns_settings ){ if ( table_settings.hasOwnProperty('default_sort_order') && table_settings['default_sort_order'] != null ) { settings["order"] = [[ table_settings['default_sort_order'], 'asc' ]]; } + if ( table_settings.hasOwnProperty('default_save_state') && table_settings['default_save_state'] === 0 ) { + localStorage.removeItem(table_key); + } } var table = $(this).dataTable(settings); diff --git a/t/db_dependent/TablesSettings.t b/t/db_dependent/TablesSettings.t index 97121093b4..ab7593ba1f 100755 --- a/t/db_dependent/TablesSettings.t +++ b/t/db_dependent/TablesSettings.t @@ -25,6 +25,7 @@ $module->mock( 'currencies-table' => { default_display_length => 20, default_sort_order => 1, + default_save_state => 1, columns => [ { columnname => 'currency', @@ -125,6 +126,7 @@ my $modules_expected = { 'currencies-table' => { default_display_length => 20, default_sort_order => 1, + default_save_state => 1, columns => [ { columnname => 'currency', @@ -192,10 +194,12 @@ for my $m ( keys %$modules ) { { default_display_length => $table_settings->{default_display_length}, default_sort_order => $table_settings->{default_sort_order} + default_save_state => $table_settings->{default_save_state} }, { default_display_length => $modules->{$m}{$p}{$t}{default_display_length}, default_sort_order => $modules->{$m}{$p}{$t}{default_sort_order}, + default_save_state => $modules->{$m}{$p}{$t}{default_save_state}, } ); } -- 2.39.5