View | Details | Raw Unified | Return to bug 16881
Collapse All | Expand All

(-)a/C4/Utils/DataTables/ColumnsSettings.pm (-27 / +53 lines)
Lines 6-13 use YAML; Link Here
6
use C4::Context;
6
use C4::Context;
7
use Koha::Database;
7
use Koha::Database;
8
use Koha::Caches;
8
use Koha::Caches;
9
use Koha::UsersColumnsSettings;
10
use Koha::UsersColumnsSetting;
11
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
9
12
10
sub get_yaml {
13
sub get_yaml {
14
    my ( $module, $page, $tablename ) = @_;
15
11
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
16
    my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
12
    my $cache = Koha::Caches->get_instance();
17
    my $cache = Koha::Caches->get_instance();
13
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
18
    my $yaml  = $cache->get_from_cache('ColumnsSettingsYaml');
Lines 19-60 sub get_yaml { Link Here
19
        $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
24
        $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
20
    }
25
    }
21
26
22
    return $yaml;
27
    unless ( $module || $page || $tablename ) {
28
        return $yaml;
29
    }
30
31
    if (my $list = $yaml->{modules}{$module}{$page}{$tablename}) {
32
        return $list;
33
    }
34
35
    return '';
23
}
36
}
24
37
25
sub get_columns {
38
sub get_columns {
26
    my ( $module, $page, $tablename ) = @_;
39
    my ( $module, $page, $tablename, $additional_param ) = @_;
27
40
28
    my $list = get_yaml;
41
    my $columns = get_yaml($module, $page, $tablename);
42
    # Fall back on a dynamic way to retrieve default columns.
43
    unless ($columns) {
44
        my $sub = $module . '_' . $page . '_' . $tablename;
45
        if (my $s = C4::Utils::DataTables::ColumnsSettings::Dynamic->can($sub)) {
46
            $columns = $s->($additional_param);
47
        }
48
    }
29
49
30
    my $schema = Koha::Database->new->schema;
50
    my $schema = Koha::Database->new->schema;
31
51
    my $borrowernumber = C4::Context::userenv->{number};
32
    my $rs = $schema->resultset('ColumnsSetting')->search(
52
33
        {
53
    foreach my $c (@$columns) {
34
            module    => $module,
54
        # User settings.
35
            page      => $page,
55
        my $user_column = Koha::UsersColumnsSettings->search({
36
            tablename => $tablename,
56
            borrowernumber   => $borrowernumber,
57
            module           => $module,
58
            page             => $page,
59
            tablename        => $tablename,
60
            columnname       => $c->{columnname},
61
            additional_param => $additional_param
62
        })->next();
63
64
        if ($user_column) {
65
            $c->{is_hidden} = $user_column->is_hidden || 0;
37
        }
66
        }
38
    );
39
40
    while ( my $c = $rs->next ) {
41
        my $column = first { $c->columnname eq $_->{columnname} }
42
        @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
43
        $column->{is_hidden}         = $c->is_hidden;
44
        $column->{cannot_be_toggled} = $c->cannot_be_toggled;
45
    }
46
67
47
    my $columns = $list->{modules}{$module}{$page}{$tablename} || [];
68
        # Admin settings.
69
        my $column = $schema->resultset('ColumnsSetting')->search({
70
            module     => $module,
71
            page       => $page,
72
            tablename  => $tablename,
73
            columnname => $c->{columnname},
74
        })->next();
48
75
49
    # Assign default value if does not exist
76
        if ($column) {
50
    $columns = [ map {
77
            $c->{cannot_be_toggled} = $column->cannot_be_toggled;
51
        {
52
            cannot_be_toggled => exists $_->{cannot_be_toggled} ? $_->{cannot_be_toggled} : 0,
53
            cannot_be_modified => exists $_->{cannot_be_modified} ? $_->{cannot_be_modified} : 0,
54
            is_hidden => exists $_->{is_hidden} ? $_->{is_hidden} : 0,
55
            columnname => $_->{columnname},
56
        }
78
        }
57
    } @$columns ];
79
80
        $c->{is_hidden} ||= 0;
81
        $c->{cannot_be_toggled} ||= 0;
82
        $c->{cannot_be_modified} ||= 0;
83
    }
58
84
59
    return $columns;
85
    return $columns;
60
}
86
}
(-)a/C4/Utils/DataTables/ColumnsSettings/Dynamic.pm (+74 lines)
Line 0 Link Here
1
package C4::Utils::DataTables::ColumnsSettings::Dynamic;
2
3
# Copyright 2017 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
require Exporter;
22
23
use vars qw(@ISA @EXPORT);
24
25
use C4::Biblio;
26
use Koha::Database;
27
28
BEGIN {
29
30
    @ISA        = qw(Exporter);
31
    @EXPORT     = qw(dt_build_orderby dt_build_having dt_get_params dt_build_query);
32
}
33
34
=head1 NAME
35
36
C4::Utils::DataTables::ColumnsSettings::Dynamic - Subs providing dynamic columns for jquery datatables.
37
38
=head1 SYNOPSIS
39
40
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
41
42
=head1 DESCRIPTION
43
44
This modules is intented to contain subs that return columns for KohaTable with columns setting plugin.
45
46
=head1 FUNCTIONS
47
48
=head2 catalogue_marcdetail_itemst
49
50
    my $columns = catalogue_marcdetail_itemst($frameworkcode);
51
    This function returns items columns depending on the framework.
52
53
=cut
54
55
sub catalogue_marcdetail_itemst {
56
    my ($frameworkcode) = @_;
57
58
    my $columns;
59
    my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
60
    my ($itemfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', $frameworkcode );
61
    foreach my $subfield ( keys %{ $tagslib->{$itemfield} } ) {
62
        next unless $subfield =~ /^\w$/;
63
        next if ( $tagslib->{$itemfield}->{$subfield}->{tab} ne 10 );
64
        next if ( $tagslib->{$itemfield}->{$subfield}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ );
65
66
        push @$columns, {
67
            columnname         => $subfield,
68
            is_hidden          => 0,
69
        }
70
    }
71
    return $columns;
72
}
73
74
1;
(-)a/Koha/REST/V1/UserColumnsSettings.pm (+64 lines)
Line 0 Link Here
1
package Koha::REST::V1::UserColumnsSettings;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use C4::Auth qw( haspermission );
23
use Koha::UsersColumnsSetting;
24
use Koha::UsersColumnsSettings;
25
26
use Try::Tiny;
27
28
sub add {
29
    my $c = shift->openapi->valid_input or return;
30
31
    return try {
32
        my $added;
33
        my $body = $c->validation->param('body');
34
        foreach my $column (@{ $body->{columns} }) {
35
            my $params = {
36
                borrowernumber => $body->{'patron_id'},
37
                module => $body->{module},
38
                page => $body->{page},
39
                tablename => $body->{tablename},
40
                additional_param => $body->{additional_param},
41
                columnname => $column->{name},
42
            };
43
44
            my $user_column;
45
            unless ( $user_column = Koha::UsersColumnsSettings->search($params)->next ) {
46
                $user_column = Koha::UsersColumnsSetting->new($params);
47
            }
48
            $user_column->is_hidden($column->{is_hidden});
49
50
            $user_column->store;
51
            push @$added, $user_column->unblessed;
52
        }
53
54
        return $c->render( status => 200, openapi => { openapi => $added } );
55
    }
56
    catch {
57
        return $c->render(
58
            status  => 500,
59
            openapi => { error => "Something went wrong, check Koha logs for details." }
60
        );
61
    }
62
}
63
64
1;
(-)a/Koha/Template/Plugin/ColumnsSettings.pm (-2 / +3 lines)
Lines 27-32 use JSON qw( to_json ); Link Here
27
27
28
use C4::Context qw( config );
28
use C4::Context qw( config );
29
use C4::Utils::DataTables::ColumnsSettings;
29
use C4::Utils::DataTables::ColumnsSettings;
30
use C4::Utils::DataTables::ColumnsSettings::Dynamic;
30
31
31
=pod
32
=pod
32
33
Lines 42-51 For example: [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'holdst' ) %] Link Here
42
=cut
43
=cut
43
44
44
sub GetColumns {
45
sub GetColumns {
45
    my ( $self, $module, $page, $table, $format ) = @_;
46
    my ( $self, $module, $page, $table, $format, $additional_params ) = @_;
46
    $format //= q{};
47
    $format //= q{};
47
48
48
    my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table );
49
    my $columns = C4::Utils::DataTables::ColumnsSettings::get_columns( $module, $page, $table, $additional_params );
49
50
50
    return $format eq 'json'
51
    return $format eq 'json'
51
        ? to_json( $columns )
52
        ? to_json( $columns )
(-)a/Koha/UsersColumnsSetting.pm (+50 lines)
Line 0 Link Here
1
package Koha::UsersColumnsSetting;
2
3
# Copyright Biblibre 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::UsersColumnsSetting - Koha UsersColumnsSetting Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'UsersColumnsSetting';
42
}
43
44
=head1 AUTHOR
45
46
Alex Arnaud <alex.arnaud@biblibre.com>
47
48
=cut
49
50
1;
(-)a/Koha/UsersColumnsSettings.pm (+54 lines)
Line 0 Link Here
1
package Koha::UsersColumnsSettings;
2
3
# Copyright Biblibre 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::UsersColumnsSettings - Koha UsersColumnsSettings Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'UsersColumnsSetting';
42
}
43
44
sub object_class {
45
    return 'Koha::UsersColumnsSetting';
46
}
47
48
=head1 AUTHOR
49
50
Alex Arnaud <alex.arnaud@biblibre.com>
51
52
=cut
53
54
1;
(-)a/api/v1/swagger/definitions.json (+6 lines)
Lines 25-29 Link Here
25
  },
25
  },
26
  "vendor": {
26
  "vendor": {
27
    "$ref": "definitions/vendor.json"
27
    "$ref": "definitions/vendor.json"
28
  },
29
  "user_columns_settings": {
30
    "$ref": "definitions/user_columns_settings.json"
31
  },
32
  "column": {
33
    "$ref": "definitions/column.json"
28
  }
34
  }
29
}
35
}
(-)a/api/v1/swagger/definitions/column.json (+13 lines)
Line 0 Link Here
1
{
2
    "type": "object",
3
    "properties": {
4
        "name": {
5
            "description": "Column name",
6
            "type": "string"
7
        },
8
        "is_hidden": {
9
            "description": "Column is hidden or not",
10
            "type": "boolean"
11
        }
12
    }
13
}
(-)a/api/v1/swagger/definitions/user_columns_settings.json (+31 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "patron_id": {
5
      "$ref": "../x-primitives.json#/patron_id"
6
    },
7
    "module": {
8
      "description": "Module name",
9
      "type": "string"
10
    },
11
    "page": {
12
      "description": "Page name",
13
      "type": "string"
14
    },
15
    "tablename": {
16
      "description": "Table name",
17
      "type": "string"
18
    },
19
    "additional_param": {
20
      "description": "Additional parameter",
21
      "type": "string"
22
    },
23
    "columns": {
24
      "description": "Columns list",
25
      "type": "array",
26
      "items": {
27
        "$ref": "column.json"
28
      }
29
    }
30
  }
31
}
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 34-38 Link Here
34
  },
34
  },
35
  "/illrequests": {
35
  "/illrequests": {
36
    "$ref": "paths/illrequests.json#/~1illrequests"
36
    "$ref": "paths/illrequests.json#/~1illrequests"
37
  },
38
  "/user_columns_settings": {
39
    "$ref": "paths/user_columns_settings.json#/~1user_columns_settings"
37
  }
40
  }
38
}
41
}
(-)a/api/v1/swagger/paths/user_columns_settings.json (+44 lines)
Line 0 Link Here
1
{
2
  "/user_columns_settings": {
3
    "post": {
4
      "x-mojo-to": "UserColumnsSettings#add",
5
      "operationId": "add",
6
      "tags": ["user_columns_settings"],
7
      "parameters": [{
8
        "name": "body",
9
        "in": "body",
10
        "description": "A JSON object containing informations about the columns settings",
11
        "required": true,
12
        "schema": {
13
          "$ref": "../definitions.json#/user_columns_settings"
14
        }
15
      }],
16
      "produces": ["application/json"],
17
      "responses": {
18
        "200": {
19
          "description": "Columns settings added",
20
          "schema": {
21
            "$ref": "../definitions.json#/user_columns_settings"
22
          }
23
        },
24
        "403": {
25
          "description": "Access forbidden",
26
          "schema": {
27
            "$ref": "../definitions.json#/error"
28
          }
29
        },
30
        "500": {
31
          "description": "Internal error",
32
          "schema": {
33
            "$ref": "../definitions.json#/error"
34
          }
35
        }
36
      },
37
      "x-koha-authorization": {
38
        "permissions": {
39
          "catalogue": "1"
40
        }
41
      }
42
    }
43
  }
44
}
(-)a/catalogue/MARCdetail.pl (-1 / +4 lines)
Lines 86-91 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
86
        debug           => 1,
86
        debug           => 1,
87
    }
87
    }
88
);
88
);
89
$template->param(
90
    frameworkcode   => $frameworkcode
91
);
89
92
90
my $record = GetMarcBiblio({
93
my $record = GetMarcBiblio({
91
    biblionumber => $biblionumber,
94
    biblionumber => $biblionumber,
Lines 286-292 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbran Link Here
286
# fill item info
289
# fill item info
287
my @item_header_loop;
290
my @item_header_loop;
288
for my $subfield_code ( @item_subfield_codes ) {
291
for my $subfield_code ( @item_subfield_codes ) {
289
    push @item_header_loop, $witness{$subfield_code};
292
    push @item_header_loop, { colname => $subfield_code, label => $witness{$subfield_code} };
290
    for my $item_data ( @item_loop ) {
293
    for my $item_data ( @item_loop ) {
291
        $item_data->{$subfield_code} ||= "&nbsp;"
294
        $item_data->{$subfield_code} ||= "&nbsp;"
292
    }
295
    }
(-)a/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql (+13 lines)
Line 0 Link Here
1
CREATE TABLE IF NOT EXISTS users_columns_settings (
2
    id int(11) NOT NULL auto_increment,
3
    borrowernumber int(11) NOT NULL,
4
    module varchar(50) NOT NULL,
5
    page varchar(50) NOT NULL,
6
    tablename varchar(50) NOT NULL,
7
    additional_param varchar(255) NOT NULL,
8
    columnname varchar(50) NOT NULL,
9
    is_hidden int(1) NOT NULL DEFAULT 0,
10
    PRIMARY KEY(id),
11
    UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param),
12
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
13
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (+18 lines)
Lines 3618-3623 CREATE TABLE IF NOT EXISTS columns_settings ( Link Here
3618
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3618
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3619
3619
3620
--
3620
--
3621
-- Table structure for table `users_columns_settings`
3622
--
3623
3624
CREATE TABLE IF NOT EXISTS users_columns_settings (
3625
    id int(11) NOT NULL auto_increment,
3626
    borrowernumber int(11) NOT NULL,
3627
    module varchar(50) NOT NULL,
3628
    page varchar(50) NOT NULL,
3629
    tablename varchar(50) NOT NULL,
3630
    additional_param varchar(255) NOT NULL,
3631
    columnname varchar(50) NOT NULL,
3632
    is_hidden int(1) NOT NULL DEFAULT 0,
3633
    PRIMARY KEY(id),
3634
    UNIQUE KEY user_column_elements (borrowernumber, module, page, tablename, columnname, additional_param),
3635
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3636
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3637
3638
--
3621
-- Table structure for table 'items_search_fields'
3639
-- Table structure for table 'items_search_fields'
3622
--
3640
--
3623
3641
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-2 / +32 lines)
Lines 1-14 Link Here
1
[% USE ColumnsSettings %]
1
[% USE ColumnsSettings %]
2
2
3
<script type="text/javascript">
3
<script type="text/javascript">
4
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
4
var loaded = false;
5
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters, script_params) {
5
    var counter = 0;
6
    var counter = 0;
6
    var hidden_ids = [];
7
    var hidden_ids = [];
7
    var included_ids = [];
8
    var included_ids = [];
8
    var selector = '#' + id_selector;
9
    var selector = '#' + id_selector;
9
10
10
    $(columns_settings).each( function() {
11
    $(columns_settings).each( function() {
11
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
12
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index();
12
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
13
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter;
13
        if ( used_id == -1 ) return;
14
        if ( used_id == -1 ) return;
14
15
Lines 68-73 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { Link Here
68
        thead_row.before(clone);
69
        thead_row.before(clone);
69
    }
70
    }
70
71
72
    if ($(columns_settings).length) {
73
        dt_parameters[ "stateSave" ] =  true;
74
        dt_parameters[ "stateSaveCallback" ] = function(settings, data) {
75
            KohaStateSaveCallback(settings, data, script_params);
76
        };
77
    }
78
71
    table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
79
    table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
72
80
73
    $(hidden_ids).each(function(index, value) {
81
    $(hidden_ids).each(function(index, value) {
Lines 83-89 function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { Link Here
83
        deactivate_filters(id_selector);
91
        deactivate_filters(id_selector);
84
    }
92
    }
85
93
94
    loaded = true;
86
    return table;
95
    return table;
87
}
96
}
88
97
98
function KohaStateSaveCallback(settings, data, script_params) {
99
    if (loaded && typeof settings['aoColumns'] !== 'undefined') {
100
        var columns = [];
101
        $.each( settings['aoColumns'], function( index, value ){
102
            columns.push({name: value.colname, is_hidden: value.bVisible ? false : true});
103
        });
104
        $.ajax({
105
            url: "/api/v1/user_columns_settings",
106
            data: JSON.stringify({
107
                patron_id: "[% loggedinusernumber %]",
108
                module: script_params['module'],
109
                page: script_params['page'],
110
                tablename: script_params['tablename'],
111
                additional_param: script_params['additional_param'],
112
                columns: columns
113
            }),
114
            type: "POST",
115
        });
116
    }
117
}
118
89
</script>
119
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt (-1 / +27 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
3
[% SET footerjs = 1 %]
4
[% USE ColumnsSettings %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Catalog &rsaquo;
6
<title>Koha &rsaquo; Catalog &rsaquo;
6
  [% IF ( unknownbiblionumber ) %]
7
  [% IF ( unknownbiblionumber ) %]
Lines 9-14 Link Here
9
    MARC details for [% bibliotitle | html %]
10
    MARC details for [% bibliotitle | html %]
10
  [% END %]
11
  [% END %]
11
</title>
12
</title>
13
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
12
[% INCLUDE 'doc-head-close.inc' %]
14
[% INCLUDE 'doc-head-close.inc' %]
13
</head>
15
</head>
14
16
Lines 153-163 Link Here
153
     [% IF ( tab10XX ) %]
155
     [% IF ( tab10XX ) %]
154
    <div id="tab10XX">
156
    <div id="tab10XX">
155
        <table>
157
        <table>
158
            <thead>
156
                <tr>
159
                <tr>
157
                    [% FOREACH header IN item_header_loop %]
160
                    [% FOREACH header IN item_header_loop %]
158
                        <th>[% header | html %]</th>
161
                        <th data-colname="[% header.colname | html %]">[% header.label | html %]</th>
159
                    [% END %]
162
                    [% END %]
160
                </tr>
163
                </tr>
164
            </thead>
165
            <tbody>
161
                [% FOREACH item IN item_loop %]
166
                [% FOREACH item IN item_loop %]
162
                    <tr>
167
                    <tr>
163
                        [% FOREACH sf_code IN item_subfield_codes %]
168
                        [% FOREACH sf_code IN item_subfield_codes %]
Lines 165-170 Link Here
165
                        [% END %]
170
                        [% END %]
166
                    </tr>
171
                    </tr>
167
                [% END %]
172
                [% END %]
173
            </tbody>
168
        </table>
174
        </table>
169
    </div>
175
    </div>
170
    [% END %]
176
    [% END %]
Lines 182-187 Link Here
182
    [% Asset.js("js/catalog.js") | $raw %]
188
    [% Asset.js("js/catalog.js") | $raw %]
183
    [% INCLUDE 'browser-strings.inc' %]
189
    [% INCLUDE 'browser-strings.inc' %]
184
    [% Asset.js("js/browser.js") | $raw %]
190
    [% Asset.js("js/browser.js") | $raw %]
191
    [% INCLUDE 'datatables.inc' %]
192
    [% INCLUDE 'columns_settings.inc' %]
185
    <script type="text/javascript">
193
    <script type="text/javascript">
186
        var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10));
194
        var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10));
187
        browser.show();
195
        browser.show();
Lines 191-196 Link Here
191
            $("#Frameworks").on("change",function(){
199
            $("#Frameworks").on("change",function(){
192
                Changefwk(this);
200
                Changefwk(this);
193
            });
201
            });
202
203
            var columns_settings = [% ColumnsSettings.GetColumns( 'catalogue', 'marcdetail', 'itemst', 'json', frameworkcode ) %];
204
            var script_params = {
205
                module: 'catalogue',
206
                page: 'marcdetail',
207
                tablename: 'itemst',
208
                additional_param: '[% frameworkcode %]',
209
            }
210
            var itemst = KohaTable("tab10XX table", {
211
                'module': 'catalogue',
212
                'bPaginate': false,
213
                'bInfo': false,
214
                "bAutoWidth": false,
215
                "bKohaColumnsUseNames": true,
216
                "aoColumnDefs": [
217
                    { "bSortable": false, "bSearchable": false, "aTargets": [ "NoSort" ] }
218
                ]
219
            }, columns_settings, '', script_params);
194
         });
220
         });
195
221
196
        function Changefwk(FwkList) {
222
        function Changefwk(FwkList) {
(-)a/t/db_dependent/ColumnsSettings.t (+1 lines)
Lines 6-11 use Test::MockModule; Link Here
6
6
7
use C4::Context;
7
use C4::Context;
8
use C4::Utils::DataTables::ColumnsSettings;
8
use C4::Utils::DataTables::ColumnsSettings;
9
9
my $dbh = C4::Context->dbh;
10
my $dbh = C4::Context->dbh;
10
$dbh->{AutoCommit} = 0;
11
$dbh->{AutoCommit} = 0;
11
$dbh->{RaiseError} = 1;
12
$dbh->{RaiseError} = 1;
(-)a/t/db_dependent/api/v1/user_columns_settings.t (-1 / +148 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 9;
21
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use C4::Auth;
27
use Koha::UsersColumnsSetting;
28
use Koha::UsersColumnsSettings;
29
use Koha::Database;
30
31
my $schema  = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
my $builder = t::lib::TestBuilder->new;
34
35
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
36
37
my $remote_address = '127.0.0.1';
38
my $t              = Test::Mojo->new('Koha::REST::V1');
39
40
my ( $unauthorized_borrowernumber, $unauthorized_session_id ) =
41
  create_user_and_session( { authorized => 0 } );
42
my ( $authorized_borrowernumber, $authorized_session_id ) =
43
  create_user_and_session( { authorized => 1 } );
44
45
my $user_columns_settings = {
46
    borrowernumber => $authorized_borrowernumber,
47
    module => 'catalgue',
48
    page => 'marcdetail',
49
    tablename => 'itemst',
50
    additional_param => 'ACQ',
51
    columns => [
52
        {name => 'foo', is_hidden => \0},
53
        {name => 'bar', is_hidden => \1}
54
    ]
55
};
56
57
my $tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
58
$tx->req->cookies(
59
    { name => 'CGISESSID', value => $unauthorized_session_id } );
60
$tx->req->env( { REMOTE_ADDR => $remote_address } );
61
$t->request_ok($tx)->status_is(403);
62
63
$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
64
$tx->req->cookies(
65
    { name => 'CGISESSID', value => $authorized_session_id } );
66
$tx->req->env( { REMOTE_ADDR => $remote_address } );
67
$t->request_ok($tx)->status_is(200);
68
69
my $col_foo = Koha::UsersColumnsSettings->search({
70
    borrowernumber => $authorized_borrowernumber,
71
    module => 'catalgue',
72
    page => 'marcdetail',
73
    tablename => 'itemst',
74
    additional_param => 'ACQ',
75
    columnname => 'foo'
76
77
})->next;
78
79
is($col_foo->is_hidden, 0, 'Column foo added');
80
81
my $col_bar = Koha::UsersColumnsSettings->search({
82
    borrowernumber => $authorized_borrowernumber,
83
    module => 'catalgue',
84
    page => 'marcdetail',
85
    tablename => 'itemst',
86
    additional_param => 'ACQ',
87
    columnname => 'bar'
88
})->next;
89
90
is($col_bar->is_hidden, 1, 'Column bar added');
91
92
# Update user columns
93
$user_columns_settings->{columns}->[0]->{is_hidden} = \1;
94
95
$tx = $t->ua->build_tx( POST => "/api/v1/user_columns_settings/" => json => $user_columns_settings );
96
$tx->req->cookies(
97
    { name => 'CGISESSID', value => $authorized_session_id } );
98
$tx->req->env( { REMOTE_ADDR => $remote_address } );
99
$t->request_ok($tx)->status_is(200);
100
101
$col_foo = Koha::UsersColumnsSettings->search({
102
    borrowernumber => $authorized_borrowernumber,
103
    module => 'catalgue',
104
    page => 'marcdetail',
105
    tablename => 'itemst',
106
    additional_param => 'ACQ',
107
    columnname => 'foo'
108
109
})->next;
110
111
is($col_foo->is_hidden, 1, 'Column foo updated');
112
113
sub create_user_and_session {
114
115
    my $args  = shift;
116
    my $flags = ( $args->{authorized} ) ? $args->{authorized} : 0;
117
    my $dbh   = C4::Context->dbh;
118
119
    my $user = $builder->build(
120
        {
121
            source => 'Borrower',
122
            value  => {
123
                flags => $flags
124
            }
125
        }
126
    );
127
128
    # Create a session for the authorized user
129
    my $session = C4::Auth::get_session('');
130
    $session->param( 'number',   $user->{borrowernumber} );
131
    $session->param( 'id',       $user->{userid} );
132
    $session->param( 'ip',       '127.0.0.1' );
133
    $session->param( 'lasttime', time() );
134
    $session->flush;
135
136
    if ( $args->{authorized} ) {
137
        $dbh->do( "
138
            INSERT INTO user_permissions (borrowernumber,module_bit,code)
139
            VALUES (?,3,'parameters_remaining_permissions')", undef,
140
            $user->{borrowernumber} );
141
    }
142
143
    return ( $user->{borrowernumber}, $session->id );
144
}
145
146
$schema->storage->txn_rollback;
147
148
1;

Return to bug 16881