@@ -, +, @@ - the js and css file for ColVis - a new DB table 'columns_settings' - a new template plugin 'ColumnsSettings' - a new package C4::Utils::DataTables::ColumnsSettings - a new admin page admin/columns_settings.pl - is_hidden: default is 0 - cannot_be_toggled: default is 0. - cannot_be_modified: default is 0 --- C4/Utils/DataTables/ColumnsSettings.pm | 106 ++++++++++++++++ Koha/Template/Plugin/ColumnsSettings.pm | 56 +++++++++ admin/columns_settings.pl | 59 +++++++++ admin/columns_settings.yml | 10 ++ .../prog/en/includes/columns_settings.inc | 27 ++++ koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 2 +- .../prog/en/modules/admin/admin-home.tt | 2 + .../prog/en/modules/admin/columns_settings.tt | 139 +++++++++++++++++++++ 8 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 C4/Utils/DataTables/ColumnsSettings.pm create mode 100644 Koha/Template/Plugin/ColumnsSettings.pm create mode 100755 admin/columns_settings.pl create mode 100644 admin/columns_settings.yml create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt --- a/C4/Utils/DataTables/ColumnsSettings.pm +++ a/C4/Utils/DataTables/ColumnsSettings.pm @@ -0,0 +1,106 @@ +package C4::Utils::DataTables::ColumnsSettings; + +use Modern::Perl; +use List::Util qw( first ); +use YAML; +use C4::Context; +use Koha::Database; + +sub get_yaml { + my $yml_path = + C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; + my $yaml = eval { YAML::LoadFile($yml_path) }; + warn +"ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@" + if $@; + return $yaml; +} + +sub get_columns { + my ( $module, $page, $tablename ) = @_; + + my $list = get_yaml; + + my $schema = Koha::Database->new->schema; + + my $rs = $schema->resultset('ColumnsSetting')->search( + { + module => $module, + page => $page, + tablename => $tablename, + } + ); + + while ( my $c = $rs->next ) { + my $column = first { $c->columnname eq $_->{columnname} } + @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + $column->{is_hidden} = $c->is_hidden; + $column->{cannot_be_toggled} = $c->cannot_be_toggled; + } + + return $list->{modules}{$module}{$page}{$tablename} || []; +} + +sub get_modules { + my $list = get_yaml; + + my $schema = Koha::Database->new->schema; + my $rs = $schema->resultset('ColumnsSetting')->search; + + while ( my $c = $rs->next ) { + my $column = first { $c->columnname eq $_->{columnname} } + @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + $column->{is_hidden} = $c->is_hidden; + $column->{cannot_be_toggled} = $c->cannot_be_toggled; + } + + return $list->{modules}; +} + +sub update_columns { + my ($params) = @_; + my $columns = $params->{columns}; + + my $schema = Koha::Database->new->schema; + + for my $c (@$columns) { + $c->{is_hidden} //= 0; + $c->{cannot_be_toggled} //= 0; + + my $column = $schema->resultset('ColumnsSetting')->search( + { + module => $c->{module}, + page => $c->{page}, + tablename => $c->{tablename}, + columnname => $c->{columnname}, + } + ); + if ( $column->count ) { + $column = $column->first; + $column->update( + { + module => $c->{module}, + page => $c->{page}, + tablename => $c->{tablename}, + columnname => $c->{columnname}, + is_hidden => $c->{is_hidden}, + cannot_be_toggled => $c->{cannot_be_toggled}, + } + ); + } + else { + $schema->resultset('ColumnsSetting')->create( + { + module => $c->{module}, + page => $c->{page}, + tablename => $c->{tablename}, + columnname => $c->{columnname}, + is_hidden => $c->{is_hidden}, + cannot_be_toggled => $c->{cannot_be_toggled}, + } + ); + } + } +} + +1; --- a/Koha/Template/Plugin/ColumnsSettings.pm +++ a/Koha/Template/Plugin/ColumnsSettings.pm @@ -0,0 +1,56 @@ +package Koha::Template::Plugin::ColumnsSettings; + +# This file is part of Koha. +# +# Copyright BibLibre 2013 +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use YAML qw( LoadFile ); +use JSON qw( to_json ); + +use C4::Context qw( config ); +use C4::Utils::DataTables::ColumnsSettings; + +=pod + +This plugin allows to get the column configuration for a table. + +First, include the line '[% USE Tables %]' at the top +of the template to enable the plugin. + +To use, call ColumnsSettings.GetColumns with the module, the page and the table where the template is called. + +For example: [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %] + +=cut + +sub GetColumns { + my ( $self, $module, $page, $table, $format ) = @_; + $format //= q{}; + + my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table ); + + return $format eq 'json' + ? to_json( $columns ) + : $columns +} + +1; + --- a/admin/columns_settings.pl +++ a/admin/columns_settings.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +use Modern::Perl; +use CGI; +use YAML qw( LoadFile ); +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::Utils::DataTables::ColumnsSettings qw( get_modules ); +my $input = new CGI; + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "admin/columns_settings.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 'parameters_remaining_permissions'}, + debug => 1, + }); + + +my $action = $input->param('action') // 'list'; + +if ( $action eq 'save' ) { + my $module = $input->param("module"); + + my @columnids = $input->param("columnid"); + my @columns; + for my $columnid ( @columnids ) { + next unless $columnid =~ m|^([^_]*)_([^_]*)_(.*)$|; + my $is_hidden = $input->param($columnid.'_hidden') // 0; + my $cannot_be_toggled = $input->param($columnid.'_cannot_be_toggled') // 0; + push @columns, + { + module => $module, + page => $1, + tablename => $2, + columnname => $3, + is_hidden => $is_hidden, + cannot_be_toggled => $cannot_be_toggled, + }; + } + + + C4::Utils::DataTables::ColumnsSettings::update_columns( + { + columns => \@columns, + } + ); + + $action = 'list'; +} + +if ( $action eq 'list' ) { + my $modules = C4::Utils::DataTables::ColumnsSettings::get_modules; + $template->param( modules => $modules ); +} + +output_html_with_http_headers $input, $cookie, $template->output; --- a/admin/columns_settings.yml +++ a/admin/columns_settings.yml @@ -0,0 +1,10 @@ +modules: + module_name: + page_name: + table_id: + - + columnname: my_column_name + - + columnname: my_other_column_name + cannot_be_toggled: 1 + cannot_be_modified: 1 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -0,0 +1,27 @@ +[% USE ColumnsSettings %] + + --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -23,7 +23,7 @@ var dataTablesDefaults = { "sSearch" : window.MSG_DT_SEARCH || "Search:", "sZeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found" }, - "sDom": '<"top pager"ilpf>tr<"bottom pager"ip>', + "sDom": 'C<"top pager"ilpf>tr<"bottom pager"ip>', "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]], "iDisplayLength": 20 }; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -104,6 +104,8 @@
Define which servers to query for MARC data in the integrated Z39.50 client.
Did you mean?
Choose which plugins to use to suggest searches to patrons and staff.
+
Configure columns
+
Hide or show columns for tables.
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt @@ -0,0 +1,139 @@ +[% BLOCK pagelist %] +
+
+ + + [% IF module.keys and module.keys.size > 0 %] + [% FOR pagename IN module.keys %] +
[% pagename %]
+ [% SET tables = module %] + [% IF tables.$pagename.keys and tables.$pagename.keys.size > 0 %] + [% FOR tablename IN tables.$pagename.keys.sort %] + + + + + [% FOR column IN tables.$pagename.$tablename %] + + + + + + [% END %] + +
[% tablename %]
Column nameIs Hidden by defaultCannot be toggled
+ [% column.columnname %] + + + [% IF column.is_hidden %] + [% IF column.cannot_be_modified %] + + + [% ELSE %] + + [% END %] + [% ELSE %] + [% IF column.cannot_be_modified %] + + + [% ELSE %] + + [% END %] + [% END %] + + [% IF column.cannot_be_toggled %] + [% IF column.cannot_be_modified %] + + + [% ELSE %] + + [% END %] + [% ELSE %] + [% IF column.cannot_be_modified %] + + + [% ELSE %] + + [% END %] + [% END %] +
+ [% END %] + + [% ELSE %] + There is no table to configure for this module. + [% END %] + [% END %] + [% ELSE %] + There is no page using the table configuration in this module. + [% END %] +
+
+[% END %] + +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › Tables +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + +
+
+
+
+

Columns settings

+
+

Acquisition

+
+

Acquisition tables

+ [% PROCESS pagelist module=modules.acqui modulename="acqui" %] +
+ +

Administration

+
+

Administration tables

+ [% PROCESS pagelist module=modules.admin modulename="admin" %] +
+ +

Authorities

+
+

Authorities tables

+ [% PROCESS pagelist module=modules.authorities modulename="authorities" %] +
+ +

Catalogue

+
+

Catalogue tables

+ [% PROCESS pagelist module=modules.catalogue modulename="catalogue" %] +
+ +

Cataloguing

+
+

Cataloguing tables

+ [% PROCESS pagelist module=modules.cataloguing modulename="cataloguing" %] +
+ +

Circulation

+
+

Circulation tables

+ [% PROCESS pagelist module=modules.circ modulename="circ" %] +
+
+
+
+ +
+ [% INCLUDE 'admin-menu.inc' %] +
+
+[% INCLUDE 'intranet-bottom.inc' %] --