From 876009031eba361337759c7958cd7cb02a9c25f7 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
---
C4/Utils/DataTables/TablesSettings.pm | 11 +++-
admin/columns_settings.pl | 5 +-
admin/columns_settings.yml | 61 +++++++++++++++++++
.../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 ++
9 files changed, 112 insertions(+), 4 deletions(-)
create mode 100644 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 55ebb66e2e..682bd03bfa 100755
--- a/admin/columns_settings.pl
+++ b/admin/columns_settings.pl
@@ -50,11 +50,13 @@ if ( $action eq '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 ( $action eq 'save' ) {
tablename => $2,
default_display_length => $default_display_length,
default_sort_order => $default_sort_order,
+ default_save_state => $default_save_state,
}
);
}
diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml
index 12091f3154..c71b66bbd8 100644
--- a/admin/columns_settings.yml
+++ b/admin/columns_settings.yml
@@ -2,6 +2,7 @@ modules:
acqui:
acq_acqui-home:
accounts:
+ default_save_state: 1
columns:
-
columnname: active
@@ -32,6 +33,7 @@ modules:
histsearcht:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: order_line
@@ -72,6 +74,7 @@ modules:
late_orders:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -116,6 +119,7 @@ modules:
orders:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: basket_number
@@ -165,6 +169,7 @@ modules:
suggestions:
suggestions:
+ default_save_state: 1
columns:
-
columnname: selections
@@ -207,6 +212,7 @@ modules:
table_cities:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: city_id
@@ -224,6 +230,7 @@ modules:
cannot_be_modified: 1
currency:
currencies-table:
+ default_save_state: 1
columns:
-
columnname: currency
@@ -249,6 +256,7 @@ modules:
patron_categories:
default_display_length: 20
default_sort_order: 1
+ default_save_state: 1
columns:
-
columnname: code
@@ -291,6 +299,7 @@ modules:
table_item_type:
default_display_length: 10
default_sort_order: 1
+ default_save_state: 1
columns:
-
columnname: image
@@ -332,6 +341,7 @@ modules:
libraries:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: library_name
@@ -357,6 +367,7 @@ modules:
catalogue:
detail:
holdings_table:
+ default_save_state: 1
columns:
-
columnname: holdings_checkbox
@@ -420,6 +431,7 @@ modules:
cannot_be_modified: 1
otherholdings_table:
+ default_save_state: 1
columns:
-
columnname: otherholdings_checkbox
@@ -483,6 +495,7 @@ modules:
cannot_be_modified: 1
acquisitiondetails-table:
+ default_save_state: 1
columns:
-
columnname: vendor
@@ -513,6 +526,7 @@ modules:
checkoutshistory-table:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: patron
@@ -536,6 +550,7 @@ modules:
columnname: checkin_on
bundle_tables:
+ default_save_state: 1
columns:
-
columnname: title
@@ -556,6 +571,7 @@ modules:
cataloguing:
addbooks:
reservoir-table:
+ default_save_state: 1
columns:
-
columnname: title
@@ -575,6 +591,7 @@ modules:
# columns except for the following internal/obsolete fields: stack, more_subfields_xml,
# cn_sort, permanent_location, damaged_on itemlost_on, withdrawn_on, issues, renewals and
# reserves.
+ default_save_state: 1
columns:
-
columnname: barcode
@@ -642,6 +659,7 @@ modules:
concerns:
table_concerns:
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: reported
@@ -659,6 +677,7 @@ modules:
z3950_search:
resultst:
default_sort_order: 1
+ default_save_state: 1
columns:
-
columnname: server
@@ -684,6 +703,7 @@ modules:
course_reserves_table:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: name
@@ -710,6 +730,7 @@ modules:
course_reserves_table:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: title
@@ -745,6 +766,7 @@ modules:
erm:
agreements:
agreements:
+ default_save_state: 1
columns:
-
columnname: name
@@ -766,6 +788,7 @@ modules:
cannot_be_modified: 1
licenses:
licenses:
+ default_save_state: 1
columns:
-
columnname: name
@@ -787,6 +810,7 @@ modules:
cannot_be_modified: 1
eholdings:
packages:
+ default_save_state: 1
columns:
-
columnname: name
@@ -805,6 +829,7 @@ modules:
cannot_be_toggled: 1
cannot_be_modified: 1
titles:
+ default_save_state: 1
columns:
-
columnname: title
@@ -822,6 +847,7 @@ modules:
illrequests:
ill-requests:
ill-requests:
+ default_save_state: 1
columns:
-
columnname: illrequest_id
@@ -897,6 +923,7 @@ modules:
fines:
account-fines:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: date
@@ -942,6 +969,7 @@ modules:
pay-fines-table:
default_display_length: 20
default_sort_order: 3
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -980,6 +1008,7 @@ modules:
member:
memberresultst:
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -1010,6 +1039,7 @@ modules:
moremember:
issues-table:
+ default_save_state: 1
columns:
-
columnname: sort_order
@@ -1073,6 +1103,7 @@ modules:
cannot_be_modified: 1
relatives-issues-table:
+ default_save_state: 1
columns:
-
columnname: due_date_unformatted
@@ -1116,6 +1147,7 @@ modules:
holdshistory:
holdshistory-table:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: title
@@ -1143,6 +1175,7 @@ modules:
checkouthistory:
checkouthistory-table:
default_display_length: 20
+ default_save_state: 1
columns:
- columnname: type
cannot_be_toggled: 1
@@ -1174,6 +1207,7 @@ modules:
patron-list-table:
default_display_length: 20
default_sort_order: 3
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -1199,6 +1233,7 @@ modules:
reports:
lostitems:
lostitems-table:
+ default_save_state: 1
columns:
-
columnname: title
@@ -1239,6 +1274,7 @@ modules:
funds-table:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: fund
@@ -1279,6 +1315,7 @@ modules:
table_reports:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: selection
@@ -1324,6 +1361,7 @@ modules:
circ:
circulation:
issues-table:
+ default_save_state: 1
columns:
-
columnname: sort_order
@@ -1387,6 +1425,7 @@ modules:
cannot_be_modified: 1
relatives-issues-table:
+ default_save_state: 1
columns:
-
columnname: due_date_unformatted
@@ -1428,6 +1467,7 @@ modules:
columnname: patron
table_borrowers:
+ default_save_state: 1
columns:
-
columnname: name
@@ -1449,6 +1489,7 @@ modules:
returns:
checkedintable:
+ default_save_state: 1
columns:
-
columnname: due_date
@@ -1483,6 +1524,7 @@ modules:
view_holdsqueue:
holds-table:
default_sort_order: 3
+ default_save_state: 1
columns:
-
columnname: title
@@ -1516,6 +1558,7 @@ modules:
holds-to-pull:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: pull_items
@@ -1555,6 +1598,7 @@ modules:
holdsratios:
holds-ratios:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: holds
@@ -1579,6 +1623,7 @@ modules:
holds_awaiting_pickup:
holdst:
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -1610,6 +1655,7 @@ modules:
columnname: action
holdso:
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -1641,6 +1687,7 @@ modules:
columnname: action
holdscr:
+ default_save_state: 1
columns:
-
columnname: checkbox
@@ -1675,6 +1722,7 @@ modules:
circ-overdues:
default_display_length: 20
default_sort_order: 0
+ default_save_state: 1
columns:
-
columnname: due_date
@@ -1762,6 +1810,7 @@ modules:
opac:
biblio-detail:
holdingst:
+ default_save_state: 1
columns:
-
columnname: item_cover
@@ -1804,6 +1853,7 @@ modules:
columnname: item_coursereserves
course_reserves_table:
+ default_save_state: 1
columns:
-
columnname: coursename
@@ -1821,6 +1871,7 @@ modules:
columnname: notes
subscriptionst:
+ default_save_state: 1
columns:
-
columnname: serial_serialseq
@@ -1834,6 +1885,7 @@ modules:
columnname: serial_notes
course-items-table:
+ default_save_state: 1
columns:
-
columnname: title
@@ -1861,6 +1913,7 @@ modules:
serials:
subscription-detail:
orders:
+ default_save_state: 1
columns:
-
columnname: invoice
@@ -1888,6 +1941,7 @@ modules:
tools:
batch_patron_modification:
borrowerst:
+ default_save_state: 1
columns:
-
columnname: batch_patron_edit_selections
@@ -1939,6 +1993,7 @@ modules:
logviewer:
logst:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: date
@@ -1956,6 +2011,7 @@ modules:
columnname: interface
marc-modification-templates:
templatest:
+ default_save_state: 1
columns:
-
columnname: id
@@ -1969,6 +2025,7 @@ modules:
notices:
lettert:
default_sort_order: 3
+ default_save_state: 1
columns:
-
columnname: library
@@ -1989,6 +2046,7 @@ modules:
stockrotation:
stock_rotation:
+ default_save_state: 1
columns:
-
columnname: name
@@ -2006,6 +2064,7 @@ modules:
cannot_be_modified: 1
stock_rotation_manage_items:
+ default_save_state: 1
columns:
-
columnname: barcode
@@ -2027,6 +2086,7 @@ modules:
upload:
uploadresults:
default_display_length: 20
+ default_save_state: 1
columns:
-
columnname: filename
@@ -2050,6 +2110,7 @@ modules:
pos:
pay:
invoices:
+ default_save_state: 1
columns:
-
columnname: code
diff --git a/installer/data/mysql/atomicupdate/bug_33484.pl b/installer/data/mysql/atomicupdate/bug_33484.pl
new file mode 100644
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 cba889d5e0..f676e6f235 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -5663,6 +5663,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 2419bfd5ab..3c8f442da5 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 bd8c826f27..39e25d72ea 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
@@ -136,6 +136,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 de93c14d37..1cebe86ee8 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js
@@ -979,6 +979,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.40.0