@@ -, +, @@ configurable (basket page) * rename variables and files * Modify the structure of the yml files * Create a new DB table to store the tables settings a. Execute the update DB entry to create the new table b. Restart all (to get a new version of the yml file, that is cached by memcached) c. Create several orders for a given basket --- C4/Utils/DataTables/TablesSettings.pm | 61 +++++++- Koha/Template/Plugin/TablesSettings.pm | 32 ++++ admin/columns_settings.pl | 18 +++ .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 5 +- .../prog/en/modules/admin/columns_settings.tt | 171 +++++++++++++------- t/db_dependent/TablesSettings.t | 173 ++++++++++++--------- 6 files changed, 319 insertions(+), 141 deletions(-) --- a/C4/Utils/DataTables/TablesSettings.pm +++ a/C4/Utils/DataTables/TablesSettings.pm @@ -14,7 +14,7 @@ sub get_yaml { unless ($yaml) { $yaml = eval { YAML::LoadFile($yml_path) }; - warn "ERROR: the yaml file for DT::TablesSettings is not correctly formated: $@" + warn "ERROR: the yaml file for DT::TablesSettings is not correctly formatted: $@" if $@; $cache->set_in_cache( 'TablesSettingsYaml', $yaml, { expiry => 3600 } ); } @@ -39,12 +39,12 @@ sub get_columns { while ( my $c = $rs->next ) { my $column = first { $c->columnname eq $_->{columnname} } - @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename }{ columns } }; $column->{is_hidden} = $c->is_hidden; $column->{cannot_be_toggled} = $c->cannot_be_toggled; } - my $columns = $list->{modules}{$module}{$page}{$tablename} || []; + my $columns = $list->{modules}{$module}{$page}{$tablename}{columns} || []; # Assign default value if does not exist $columns = [ map { @@ -59,6 +59,22 @@ sub get_columns { return $columns; } +sub get_table_settings { + my ( $module, $page, $tablename ) = @_; + my $list = get_yaml; + + my $schema = Koha::Database->new->schema; + + my $rs = $schema->resultset('TablesSetting')->search( + { + module => $module, + page => $page, + tablename => $tablename, + } + )->next; + return $rs ? $rs : $list->{modules}{$module}{$page}{$tablename}; +} + sub get_modules { my $list = get_yaml; @@ -67,7 +83,7 @@ sub get_modules { while ( my $c = $rs->next ) { my $column = first { $c->columnname eq $_->{columnname} } - @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename }{columns} }; $column->{is_hidden} = $c->is_hidden; $column->{cannot_be_toggled} = $c->cannot_be_toggled; $column->{cannot_be_modified} = 0 @@ -100,4 +116,41 @@ sub update_columns { } } +=head3 update_table_settings + +C4::Utils::DataTables::TablesSettings::update_table_settings( + { + module => $module, + pag => $page, + tablename => $tablename, + default_display_length => $default_display_length, + default_sort_order => $default_sort_order + } +); + +Will update the default_display_length and default_sort_order for the given table. + +=cut + +sub update_table_settings { + my ($params) = @_; + my $module = $params->{module}; + my $page = $params->{page}; + my $tablename = $params->{tablename}; + my $default_display_length = $params->{default_display_length}; + my $default_sort_order = $params->{default_sort_order}; + + my $schema = Koha::Database->new->schema; + + $schema->resultset('TablesSetting')->update_or_create( + { + module => $module, + page => $page, + tablename => $tablename, + default_display_length => $default_display_length, + default_sort_order => $default_sort_order, + } + ); +} + 1; --- a/Koha/Template/Plugin/TablesSettings.pm +++ a/Koha/Template/Plugin/TablesSettings.pm @@ -41,6 +41,17 @@ For example: [% TablesSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %] =cut +=head3 GetColumns + +var columns_settings = [% TablesSettings.GetColumns( module, page, table 'json' ) | $raw%] + +This method is usually be used to retrieve the columns settings for a DataTable init. + +So the 'json' format will be provided and the columns_settings JS var will be +passed as argument of the constructor. + +=cut + sub GetColumns { my ( $self, $module, $page, $table, $format ) = @_; $format //= q{}; @@ -52,4 +63,25 @@ sub GetColumns { : $columns } +=head3 GetTableSettings + +[% SET table_settings = GetTableSettings( module, page, table ) %] + +This method is used to retrieve the tables settings (like table_settings.default_display_length and +table_settings.default_sort_order). +They can be passed to the DataTable constructor (for iDisplayLength and order parameters) + +=cut + +sub GetTableSettings { + my ( $self, $module, $page, $table, $format ) = @_; + $format //= q{}; + + my $settings = C4::Utils::DataTables::TablesSettings::get_table_settings( $module, $page, $table ); + + return $format eq 'json' + ? to_json( $settings || {} ) + : $settings +} + 1; --- a/admin/columns_settings.pl +++ a/admin/columns_settings.pl @@ -48,6 +48,24 @@ if ( $action eq 'save' ) { } ); + my @table_ids = $input->multi_param('table_id'); + for my $table_id (@table_ids) { + 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' ); + if ( $default_display_length && $default_sort_order ) { + C4::Utils::DataTables::TablesSettings::update_table_settings( + { + module => $module, + page => $1, + tablename => $2, + default_display_length => $default_display_length, + default_sort_order => $default_sort_order, + } + ); + } + } + $action = 'list'; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -918,6 +918,7 @@ [% END %]