Bugzilla – Attachment 79107 Details for
Bug 16881
Apply KohaTable and ColVis plugin on MARCdetail's items table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16881 - Apply KohaTable and ColVis plugin on MARCdetail's items table
Bug-16881---Apply-KohaTable-and-ColVis-plugin-on-M.patch (text/plain), 31.46 KB, created by
Alex Arnaud
on 2018-09-19 12:58:38 UTC
(
hide
)
Description:
Bug 16881 - Apply KohaTable and ColVis plugin on MARCdetail's items table
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-09-19 12:58:38 UTC
Size:
31.46 KB
patch
obsolete
>From cb77c4741c66da3c485f4cbff28baa66a51ea353 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Fri, 8 Jul 2016 15:53:50 +0200 >Subject: [PATCH] Bug 16881 - Apply KohaTable and ColVis plugin on MARCdetail's > items table > >Also, the columns displayed are saved for each users in database. > >Test plan: > >- apply this BZ, >- launch perl installer/data/mysql/updatedatabase.pl >- launch perl misc/devel/update_dbix_class_files.pl >- go to the items tab on cgi-bin/koha/catalogue/MARCdetail.pl page > you should be able to hide/show each columns. >- leave this page and come back with the same koha account: > You should have the same columns shown/hidden as when you left. > >Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> (2018-09-19) >--- > C4/Utils/DataTables/ColumnsSettings.pm | 80 +++++++---- > C4/Utils/DataTables/ColumnsSettings/Dynamic.pm | 74 +++++++++++ > Koha/REST/V1/UserColumnsSettings.pm | 64 +++++++++ > Koha/Template/Plugin/ColumnsSettings.pm | 5 +- > Koha/UsersColumnsSetting.pm | 50 +++++++ > Koha/UsersColumnsSettings.pm | 54 ++++++++ > api/v1/swagger/definitions.json | 6 + > api/v1/swagger/definitions/column.json | 13 ++ > .../swagger/definitions/user_columns_settings.json | 31 +++++ > api/v1/swagger/paths.json | 3 + > api/v1/swagger/paths/user_columns_settings.json | 44 ++++++ > catalogue/MARCdetail.pl | 5 +- > .../add-table-users_columns_settings.sql | 13 ++ > installer/data/mysql/kohastructure.sql | 18 +++ > .../prog/en/includes/columns_settings.inc | 34 ++++- > .../prog/en/modules/catalogue/MARCdetail.tt | 28 +++- > t/db_dependent/ColumnsSettings.t | 1 + > t/db_dependent/api/v1/user_columns_settings.t | 148 +++++++++++++++++++++ > 18 files changed, 638 insertions(+), 33 deletions(-) > create mode 100644 C4/Utils/DataTables/ColumnsSettings/Dynamic.pm > create mode 100644 Koha/REST/V1/UserColumnsSettings.pm > create mode 100644 Koha/UsersColumnsSetting.pm > create mode 100644 Koha/UsersColumnsSettings.pm > create mode 100644 api/v1/swagger/definitions/column.json > create mode 100644 api/v1/swagger/definitions/user_columns_settings.json > create mode 100644 api/v1/swagger/paths/user_columns_settings.json > create mode 100644 installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql > create mode 100644 t/db_dependent/api/v1/user_columns_settings.t > >diff --git a/C4/Utils/DataTables/ColumnsSettings.pm b/C4/Utils/DataTables/ColumnsSettings.pm >index 8713489..b8e1a0e 100644 >--- a/C4/Utils/DataTables/ColumnsSettings.pm >+++ b/C4/Utils/DataTables/ColumnsSettings.pm >@@ -6,8 +6,13 @@ use YAML; > use C4::Context; > use Koha::Database; > use Koha::Caches; >+use Koha::UsersColumnsSettings; >+use Koha::UsersColumnsSetting; >+use C4::Utils::DataTables::ColumnsSettings::Dynamic; > > sub get_yaml { >+ my ( $module, $page, $tablename ) = @_; >+ > my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; > my $cache = Koha::Caches->get_instance(); > my $yaml = $cache->get_from_cache('ColumnsSettingsYaml'); >@@ -19,42 +24,63 @@ sub get_yaml { > $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } ); > } > >- return $yaml; >+ unless ( $module || $page || $tablename ) { >+ return $yaml; >+ } >+ >+ if (my $list = $yaml->{modules}{$module}{$page}{$tablename}) { >+ return $list; >+ } >+ >+ return ''; > } > > sub get_columns { >- my ( $module, $page, $tablename ) = @_; >- >- my $list = get_yaml; >+ my ( $module, $page, $tablename, $additional_param ) = @_; >+ >+ my $columns = get_yaml($module, $page, $tablename); >+ # Fall back on a dynamic way to retrieve default columns. >+ unless ($columns) { >+ my $sub = $module . '_' . $page . '_' . $tablename; >+ if (my $s = C4::Utils::DataTables::ColumnsSettings::Dynamic->can($sub)) { >+ $columns = $s->($additional_param); >+ } >+ } > > my $schema = Koha::Database->new->schema; >- >- my $rs = $schema->resultset('ColumnsSetting')->search( >- { >- module => $module, >- page => $page, >- tablename => $tablename, >+ my $borrowernumber = C4::Context::userenv->{number}; >+ >+ foreach my $c (@$columns) { >+ # User settings. >+ my $user_column = Koha::UsersColumnsSettings->search({ >+ borrowernumber => $borrowernumber, >+ module => $module, >+ page => $page, >+ tablename => $tablename, >+ columnname => $c->{columnname}, >+ additional_param => $additional_param >+ })->next(); >+ >+ if ($user_column) { >+ $c->{is_hidden} = $user_column->is_hidden || 0; > } >- ); >- >- 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; >- } > >- my $columns = $list->{modules}{$module}{$page}{$tablename} || []; >+ # Admin settings. >+ my $column = $schema->resultset('ColumnsSetting')->search({ >+ module => $module, >+ page => $page, >+ tablename => $tablename, >+ columnname => $c->{columnname}, >+ })->next(); > >- # Assign default value if does not exist >- $columns = [ map { >- { >- cannot_be_toggled => exists $_->{cannot_be_toggled} ? $_->{cannot_be_toggled} : 0, >- cannot_be_modified => exists $_->{cannot_be_modified} ? $_->{cannot_be_modified} : 0, >- is_hidden => exists $_->{is_hidden} ? $_->{is_hidden} : 0, >- columnname => $_->{columnname}, >+ if ($column) { >+ $c->{cannot_be_toggled} = $column->cannot_be_toggled; > } >- } @$columns ]; >+ >+ $c->{is_hidden} ||= 0; >+ $c->{cannot_be_toggled} ||= 0; >+ $c->{cannot_be_modified} ||= 0; >+ } > > return $columns; > } >diff --git a/C4/Utils/DataTables/ColumnsSettings/Dynamic.pm b/C4/Utils/DataTables/ColumnsSettings/Dynamic.pm >new file mode 100644 >index 0000000..cfda84f >--- /dev/null >+++ b/C4/Utils/DataTables/ColumnsSettings/Dynamic.pm >@@ -0,0 +1,74 @@ >+package C4::Utils::DataTables::ColumnsSettings::Dynamic; >+ >+# Copyright 2017 BibLibre >+# >+# This file is part of Koha. >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+require Exporter; >+ >+use vars qw(@ISA @EXPORT); >+ >+use C4::Biblio; >+use Koha::Database; >+ >+BEGIN { >+ >+ @ISA = qw(Exporter); >+ @EXPORT = qw(dt_build_orderby dt_build_having dt_get_params dt_build_query); >+} >+ >+=head1 NAME >+ >+C4::Utils::DataTables::ColumnsSettings::Dynamic - Subs providing dynamic columns for jquery datatables. >+ >+=head1 SYNOPSIS >+ >+use C4::Utils::DataTables::ColumnsSettings::Dynamic; >+ >+=head1 DESCRIPTION >+ >+This modules is intented to contain subs that return columns for KohaTable with columns setting plugin. >+ >+=head1 FUNCTIONS >+ >+=head2 catalogue_marcdetail_itemst >+ >+ my $columns = catalogue_marcdetail_itemst($frameworkcode); >+ This function returns items columns depending on the framework. >+ >+=cut >+ >+sub catalogue_marcdetail_itemst { >+ my ($frameworkcode) = @_; >+ >+ my $columns; >+ my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode ); >+ my ($itemfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', $frameworkcode ); >+ foreach my $subfield ( keys %{ $tagslib->{$itemfield} } ) { >+ next unless $subfield =~ /^\w$/; >+ next if ( $tagslib->{$itemfield}->{$subfield}->{tab} ne 10 ); >+ next if ( $tagslib->{$itemfield}->{$subfield}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ ); >+ >+ push @$columns, { >+ columnname => $subfield, >+ is_hidden => 0, >+ } >+ } >+ return $columns; >+} >+ >+1; >diff --git a/Koha/REST/V1/UserColumnsSettings.pm b/Koha/REST/V1/UserColumnsSettings.pm >new file mode 100644 >index 0000000..1e671f6 >--- /dev/null >+++ b/Koha/REST/V1/UserColumnsSettings.pm >@@ -0,0 +1,64 @@ >+package Koha::REST::V1::UserColumnsSettings; >+ >+# This file is part of Koha. >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use C4::Auth qw( haspermission ); >+use Koha::UsersColumnsSetting; >+use Koha::UsersColumnsSettings; >+ >+use Try::Tiny; >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $added; >+ my $body = $c->validation->param('body'); >+ foreach my $column (@{ $body->{columns} }) { >+ my $params = { >+ borrowernumber => $body->{'patron_id'}, >+ module => $body->{module}, >+ page => $body->{page}, >+ tablename => $body->{tablename}, >+ additional_param => $body->{additional_param}, >+ columnname => $column->{name}, >+ }; >+ >+ my $user_column; >+ unless ( $user_column = Koha::UsersColumnsSettings->search($params)->next ) { >+ $user_column = Koha::UsersColumnsSetting->new($params); >+ } >+ $user_column->is_hidden($column->{is_hidden}); >+ >+ $user_column->store; >+ push @$added, $user_column->unblessed; >+ } >+ >+ return $c->render( status => 200, openapi => { openapi => $added } ); >+ } >+ catch { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check Koha logs for details." } >+ ); >+ } >+} >+ >+1; >diff --git a/Koha/Template/Plugin/ColumnsSettings.pm b/Koha/Template/Plugin/ColumnsSettings.pm >index 4617969..7ef74fc 100644 >--- a/Koha/Template/Plugin/ColumnsSettings.pm >+++ b/Koha/Template/Plugin/ColumnsSettings.pm >@@ -27,6 +27,7 @@ use JSON qw( to_json ); > > use C4::Context qw( config ); > use C4::Utils::DataTables::ColumnsSettings; >+use C4::Utils::DataTables::ColumnsSettings::Dynamic; > > =pod > >@@ -42,10 +43,10 @@ For example: [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %] > =cut > > sub GetColumns { >- my ( $self, $module, $page, $table, $format ) = @_; >+ my ( $self, $module, $page, $table, $format, $additional_params ) = @_; > $format //= q{}; > >- my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table ); >+ my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table, $additional_params ); > > return $format eq 'json' > ? to_json( $columns ) >diff --git a/Koha/UsersColumnsSetting.pm b/Koha/UsersColumnsSetting.pm >new file mode 100644 >index 0000000..55111a5 >--- /dev/null >+++ b/Koha/UsersColumnsSetting.pm >@@ -0,0 +1,50 @@ >+package Koha::UsersColumnsSetting; >+ >+# Copyright Biblibre 2017 >+# >+# This file is part of Koha. >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::UsersColumnsSetting - Koha UsersColumnsSetting Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'UsersColumnsSetting'; >+} >+ >+=head1 AUTHOR >+ >+Alex Arnaud <alex.arnaud@biblibre.com> >+ >+=cut >+ >+1; >diff --git a/Koha/UsersColumnsSettings.pm b/Koha/UsersColumnsSettings.pm >new file mode 100644 >index 0000000..cab57d4 >--- /dev/null >+++ b/Koha/UsersColumnsSettings.pm >@@ -0,0 +1,54 @@ >+package Koha::UsersColumnsSettings; >+ >+# Copyright Biblibre 2017 >+# >+# This file is part of Koha. >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::UsersColumnsSettings - Koha UsersColumnsSettings Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'UsersColumnsSetting'; >+} >+ >+sub object_class { >+ return 'Koha::UsersColumnsSetting'; >+} >+ >+=head1 AUTHOR >+ >+Alex Arnaud <alex.arnaud@biblibre.com> >+ >+=cut >+ >+1; >\ No newline at end of file >diff --git a/api/v1/swagger/definitions.json b/api/v1/swagger/definitions.json >index 6509432..104899b 100644 >--- a/api/v1/swagger/definitions.json >+++ b/api/v1/swagger/definitions.json >@@ -25,5 +25,11 @@ > }, > "vendor": { > "$ref": "definitions/vendor.json" >+ }, >+ "user_columns_settings": { >+ "$ref": "definitions/user_columns_settings.json" >+ }, >+ "column": { >+ "$ref": "definitions/column.json" > } > } >diff --git a/api/v1/swagger/definitions/column.json b/api/v1/swagger/definitions/column.json >new file mode 100644 >index 0000000..1d66489 >--- /dev/null >+++ b/api/v1/swagger/definitions/column.json >@@ -0,0 +1,13 @@ >+{ >+ "type": "object", >+ "properties": { >+ "name": { >+ "description": "Column name", >+ "type": "string" >+ }, >+ "is_hidden": { >+ "description": "Column is hidden or not", >+ "type": "boolean" >+ } >+ } >+} >diff --git a/api/v1/swagger/definitions/user_columns_settings.json b/api/v1/swagger/definitions/user_columns_settings.json >new file mode 100644 >index 0000000..d8886c9 >--- /dev/null >+++ b/api/v1/swagger/definitions/user_columns_settings.json >@@ -0,0 +1,31 @@ >+{ >+ "type": "object", >+ "properties": { >+ "patron_id": { >+ "$ref": "../x-primitives.json#/patron_id" >+ }, >+ "module": { >+ "description": "Module name", >+ "type": "string" >+ }, >+ "page": { >+ "description": "Page name", >+ "type": "string" >+ }, >+ "tablename": { >+ "description": "Table name", >+ "type": "string" >+ }, >+ "additional_param": { >+ "description": "Additional parameter", >+ "type": "string" >+ }, >+ "columns": { >+ "description": "Columns list", >+ "type": "array", >+ "items": { >+ "$ref": "column.json" >+ } >+ } >+ } >+} >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index c9d8e88..ad0d642 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -34,5 +34,8 @@ > }, > "/illrequests": { > "$ref": "paths/illrequests.json#/~1illrequests" >+ }, >+ "/user_columns_settings": { >+ "$ref": "paths/user_columns_settings.json#/~1user_columns_settings" > } > } >diff --git a/api/v1/swagger/paths/user_columns_settings.json b/api/v1/swagger/paths/user_columns_settings.json >new file mode 100644 >index 0000000..4125b2d >--- /dev/null >+++ b/api/v1/swagger/paths/user_columns_settings.json >@@ -0,0 +1,44 @@ >+{ >+ "/user_columns_settings": { >+ "post": { >+ "x-mojo-to": "UserColumnsSettings#add", >+ "operationId": "add", >+ "tags": ["user_columns_settings"], >+ "parameters": [{ >+ "name": "body", >+ "in": "body", >+ "description": "A JSON object containing informations about the columns settings", >+ "required": true, >+ "schema": { >+ "$ref": "../definitions.json#/user_columns_settings" >+ } >+ }], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Columns settings added", >+ "schema": { >+ "$ref": "../definitions.json#/user_columns_settings" >+ } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "500": { >+ "description": "Internal error", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "catalogue": "1" >+ } >+ } >+ } >+ } >+} >diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl >index b4adcfd..affb927 100755 >--- a/catalogue/MARCdetail.pl >+++ b/catalogue/MARCdetail.pl >@@ -86,6 +86,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > debug => 1, > } > ); >+$template->param( >+ frameworkcode => $frameworkcode >+); > > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, >@@ -286,7 +289,7 @@ my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbran > # fill item info > my @item_header_loop; > for my $subfield_code ( @item_subfield_codes ) { >- push @item_header_loop, $witness{$subfield_code}; >+ push @item_header_loop, { colname => $subfield_code, label => $witness{$subfield_code} }; > for my $item_data ( @item_loop ) { > $item_data->{$subfield_code} ||= " " > } >diff --git a/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql b/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql >new file mode 100644 >index 0000000..8388632 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql >@@ -0,0 +1,13 @@ >+CREATE TABLE IF NOT EXISTS users_columns_settings ( >+ id int(11) NOT NULL auto_increment, >+ borrowernumber int(11) NOT NULL, >+ module varchar(50) NOT NULL, >+ page varchar(50) NOT NULL, >+ tablename varchar(50) NOT NULL, >+ additional_param varchar(255) NOT NULL, >+ columnname varchar(50) NOT NULL, >+ is_hidden int(1) NOT NULL DEFAULT 0, >+ PRIMARY KEY(id), >+ UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param), >+ CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; >\ No newline at end of file >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index d5368d4..e2110ff 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -3618,6 +3618,24 @@ CREATE TABLE IF NOT EXISTS columns_settings ( > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > > -- >+-- Table structure for table `users_columns_settings` >+-- >+ >+CREATE TABLE IF NOT EXISTS users_columns_settings ( >+ id int(11) NOT NULL auto_increment, >+ borrowernumber int(11) NOT NULL, >+ module varchar(50) NOT NULL, >+ page varchar(50) NOT NULL, >+ tablename varchar(50) NOT NULL, >+ additional_param varchar(255) NOT NULL, >+ columnname varchar(50) NOT NULL, >+ is_hidden int(1) NOT NULL DEFAULT 0, >+ PRIMARY KEY(id), >+ UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param), >+ CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; >+ >+-- > -- Table structure for table 'items_search_fields' > -- > >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 636cc5a..6cd8663 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >@@ -1,14 +1,15 @@ > [% USE ColumnsSettings %] > > <script type="text/javascript"> >-function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { >+var loaded = false; >+function KohaTable(id_selector, dt_parameters, columns_settings, add_filters, script_params) { > var counter = 0; > var hidden_ids = []; > var included_ids = []; > var selector = '#' + id_selector; > > $(columns_settings).each( function() { >- var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' ); >+ var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index(); > var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter; > if ( used_id == -1 ) return; > >@@ -68,6 +69,13 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { > thead_row.before(clone); > } > >+ if ($(columns_settings).length) { >+ dt_parameters[ "stateSave" ] = true; >+ dt_parameters[ "stateSaveCallback" ] = function(settings, data) { >+ KohaStateSaveCallback(settings, data, script_params); >+ }; >+ } >+ > table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters)); > > $(hidden_ids).each(function(index, value) { >@@ -83,7 +91,29 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { > deactivate_filters(id_selector); > } > >+ loaded = true; > return table; > } > >+function KohaStateSaveCallback(settings, data, script_params) { >+ if (loaded && typeof settings['aoColumns'] !== 'undefined') { >+ var columns = []; >+ $.each( settings['aoColumns'], function( index, value ){ >+ columns.push({name: value.colname, is_hidden: value.bVisible ? false : true}); >+ }); >+ $.ajax({ >+ url: "/api/v1/user_columns_settings", >+ data: JSON.stringify({ >+ patron_id: "[% loggedinusernumber %]", >+ module: script_params['module'], >+ page: script_params['page'], >+ tablename: script_params['tablename'], >+ additional_param: script_params['additional_param'], >+ columns: columns >+ }), >+ type: "POST", >+ }); >+ } >+} >+ > </script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt >index 4b0ef79..9e57c34 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt >@@ -1,6 +1,7 @@ > [% USE raw %] > [% USE Asset %] > [% SET footerjs = 1 %] >+[% USE ColumnsSettings %] > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Catalog › > [% IF ( unknownbiblionumber ) %] >@@ -9,6 +10,7 @@ > MARC details for [% bibliotitle | html %] > [% END %] > </title> >+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" /> > [% INCLUDE 'doc-head-close.inc' %] > </head> > >@@ -153,11 +155,14 @@ > [% IF ( tab10XX ) %] > <div id="tab10XX"> > <table> >+ <thead> > <tr> > [% FOREACH header IN item_header_loop %] >- <th>[% header | html %]</th> >+ <th data-colname="[% header.colname | html %]">[% header.label | html %]</th> > [% END %] > </tr> >+ </thead> >+ <tbody> > [% FOREACH item IN item_loop %] > <tr> > [% FOREACH sf_code IN item_subfield_codes %] >@@ -165,6 +170,7 @@ > [% END %] > </tr> > [% END %] >+ </tbody> > </table> > </div> > [% END %] >@@ -182,6 +188,8 @@ > [% Asset.js("js/catalog.js") | $raw %] > [% INCLUDE 'browser-strings.inc' %] > [% Asset.js("js/browser.js") | $raw %] >+ [% INCLUDE 'datatables.inc' %] >+ [% INCLUDE 'columns_settings.inc' %] > <script type="text/javascript"> > var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10)); > browser.show(); >@@ -191,6 +199,24 @@ > $("#Frameworks").on("change",function(){ > Changefwk(this); > }); >+ >+ var columns_settings = [% ColumnsSettings.GetColumns( 'catalogue', 'marcdetail', 'itemst', 'json', frameworkcode ) %]; >+ var script_params = { >+ module: 'catalogue', >+ page: 'marcdetail', >+ tablename: 'itemst', >+ additional_param: '[% frameworkcode %]', >+ } >+ var itemst = KohaTable("tab10XX table", { >+ 'module': 'catalogue', >+ 'bPaginate': false, >+ 'bInfo': false, >+ "bAutoWidth": false, >+ "bKohaColumnsUseNames": true, >+ "aoColumnDefs": [ >+ { "bSortable": false, "bSearchable": false, "aTargets": [ "NoSort" ] } >+ ] >+ }, columns_settings, '', script_params); > }); > > function Changefwk(FwkList) { >diff --git a/t/db_dependent/ColumnsSettings.t b/t/db_dependent/ColumnsSettings.t >index da75931..1a7049c 100644 >--- a/t/db_dependent/ColumnsSettings.t >+++ b/t/db_dependent/ColumnsSettings.t >@@ -6,6 +6,7 @@ use Test::MockModule; > > use C4::Context; > use C4::Utils::DataTables::ColumnsSettings; >+ > my $dbh = C4::Context->dbh; > $dbh->{AutoCommit} = 0; > $dbh->{RaiseError} = 1; >diff --git a/t/db_dependent/api/v1/user_columns_settings.t b/t/db_dependent/api/v1/user_columns_settings.t >new file mode 100644 >index 0000000..98e0753 >--- /dev/null >+++ b/t/db_dependent/api/v1/user_columns_settings.t >@@ -0,0 +1,148 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 9; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use C4::Auth; >+use Koha::UsersColumnsSetting; >+use Koha::UsersColumnsSettings; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; >+ >+t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); >+ >+my $remote_address = '127.0.0.1'; >+my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+my ( $unauthorized_borrowernumber, $unauthorized_session_id ) = >+ create_user_and_session( { authorized => 0 } ); >+my ( $authorized_borrowernumber, $authorized_session_id ) = >+ create_user_and_session( { authorized => 1 } ); >+ >+my $user_columns_settings = { >+ borrowernumber => $authorized_borrowernumber, >+ module => 'catalgue', >+ page => 'marcdetail', >+ tablename => 'itemst', >+ additional_param => 'ACQ', >+ columns => [ >+ {name => 'foo', is_hidden => \0}, >+ {name => 'bar', is_hidden => \1} >+ ] >+}; >+ >+my $tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings ); >+$tx->req->cookies( >+ { name => 'CGISESSID', value => $unauthorized_session_id } ); >+$tx->req->env( { REMOTE_ADDR => $remote_address } ); >+$t->request_ok($tx)->status_is(403); >+ >+$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings ); >+$tx->req->cookies( >+ { name => 'CGISESSID', value => $authorized_session_id } ); >+$tx->req->env( { REMOTE_ADDR => $remote_address } ); >+$t->request_ok($tx)->status_is(200); >+ >+my $col_foo = Koha::UsersColumnsSettings->search({ >+ borrowernumber => $authorized_borrowernumber, >+ module => 'catalgue', >+ page => 'marcdetail', >+ tablename => 'itemst', >+ additional_param => 'ACQ', >+ columnname => 'foo' >+ >+})->next; >+ >+is($col_foo->is_hidden, 0, 'Column foo added'); >+ >+my $col_bar = Koha::UsersColumnsSettings->search({ >+ borrowernumber => $authorized_borrowernumber, >+ module => 'catalgue', >+ page => 'marcdetail', >+ tablename => 'itemst', >+ additional_param => 'ACQ', >+ columnname => 'bar' >+})->next; >+ >+is($col_bar->is_hidden, 1, 'Column bar added'); >+ >+# Update user columns >+$user_columns_settings->{columns}->[0]->{is_hidden} = \1; >+ >+$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings ); >+$tx->req->cookies( >+ { name => 'CGISESSID', value => $authorized_session_id } ); >+$tx->req->env( { REMOTE_ADDR => $remote_address } ); >+$t->request_ok($tx)->status_is(200); >+ >+$col_foo = Koha::UsersColumnsSettings->search({ >+ borrowernumber => $authorized_borrowernumber, >+ module => 'catalgue', >+ page => 'marcdetail', >+ tablename => 'itemst', >+ additional_param => 'ACQ', >+ columnname => 'foo' >+ >+})->next; >+ >+is($col_foo->is_hidden, 1, 'Column foo updated'); >+ >+sub create_user_and_session { >+ >+ my $args = shift; >+ my $flags = ( $args->{authorized} ) ? $args->{authorized} : 0; >+ my $dbh = C4::Context->dbh; >+ >+ my $user = $builder->build( >+ { >+ source => 'Borrower', >+ value => { >+ flags => $flags >+ } >+ } >+ ); >+ >+ # Create a session for the authorized user >+ my $session = C4::Auth::get_session(''); >+ $session->param( 'number', $user->{borrowernumber} ); >+ $session->param( 'id', $user->{userid} ); >+ $session->param( 'ip', '127.0.0.1' ); >+ $session->param( 'lasttime', time() ); >+ $session->flush; >+ >+ if ( $args->{authorized} ) { >+ $dbh->do( " >+ INSERT INTO user_permissions (borrowernumber,module_bit,code) >+ VALUES (?,3,'parameters_remaining_permissions')", undef, >+ $user->{borrowernumber} ); >+ } >+ >+ return ( $user->{borrowernumber}, $session->id ); >+} >+ >+$schema->storage->txn_rollback; >+ >+1; >\ No newline at end of file >-- >2.7.4
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 16881
:
53226
|
53303
|
53510
|
59566
|
59567
| 79107 |
79108