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

(-)a/C4/Utils/DataTables/ColumnsSettings.pm (+21 lines)
Lines 100-103 sub update_columns { Link Here
100
    }
100
    }
101
}
101
}
102
102
103
sub update_user_columns {
104
    my ($params) = @_;
105
    my $columns = $params->{columns};
106
107
    my $schema = Koha::Database->new->schema;
108
109
    foreach my $colname (keys %$columns) {
110
        $schema->resultset('UsersColumnsSetting')->update_or_create(
111
            {
112
                borrowernumber   => $params->{borrowernumber},
113
                module           => $params->{module},
114
                page             => $params->{page},
115
                tablename        => $params->{tablename},
116
                additional_param => $params->{additional_param},
117
                columnname       => $colname,
118
                is_hidden        => $columns->{$colname},
119
            }
120
        );
121
    }
122
}
123
103
1;
124
1;
(-)a/C4/Utils/DataTables/DynamicColumnsSettings.pm (+49 lines)
Line 0 Link Here
1
package C4::Utils::DataTables::DynamicColumnsSettings;
2
3
use Modern::Perl;
4
5
use C4::Biblio;
6
use Koha::Database;
7
8
sub catalogue_marcdetail_itemst {
9
    my ($frameworkcode) = @_;
10
11
    my $schema = Koha::Database->new->schema;
12
    my $borrowernumber = C4::Context::userenv->{number};
13
14
    my $columns;
15
    my $tagslib = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
16
    my ($itemfield) = C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', $frameworkcode );
17
    foreach my $subfield ( keys %{ $tagslib->{$itemfield} } ) {
18
        next unless $subfield =~ /^\w$/;
19
        next if ( $tagslib->{$itemfield}->{$subfield}->{tab} ne 10 );
20
        next if ( $tagslib->{$itemfield}->{$subfield}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ );
21
22
        my $user_column;
23
        if (my @rs = $schema->resultset('UsersColumnsSetting')->search(
24
            {
25
                borrowernumber   => $borrowernumber,
26
                module           => 'catalogue',
27
                page             => 'marcdetail',
28
                tablename        => 'itemst',
29
                additional_param => $frameworkcode,
30
                columnname       => $subfield
31
            }
32
        )) {
33
            $user_column = $rs[0];
34
        }
35
36
        if ( $tagslib->{$itemfield}{$subfield}{hidden} eq "0" ) {
37
            push @$columns,
38
                {
39
                    columnname         => $subfield,
40
                    is_hidden          => $user_column ? $user_column->is_hidden : 0,
41
                    cannot_be_modified => 0,
42
                    cannot_be_toggled  => 0
43
                };
44
        }
45
    }
46
    return $columns;
47
}
48
49
1;
(-)a/Koha/Template/Plugin/ColumnsSettings.pm (+13 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::DynamicColumnsSettings;
30
31
31
=pod
32
=pod
32
33
Lines 52-55 sub GetColumns { Link Here
52
        : $columns
53
        : $columns
53
}
54
}
54
55
56
sub GetDynamicColumns {
57
    my ($self, $module, $page, $tablename, $param) = @_;
58
59
    my $sub = $module . '_' . $page . '_' . $tablename;
60
    my $columns = [];
61
    if (my $s = C4::Utils::DataTables::DynamicColumnsSettings->can($sub)) {
62
        $columns = $s->($param);
63
    }
64
65
    return to_json($columns);
66
}
67
55
1;
68
1;
(-)a/catalogue/MARCdetail.pl (-1 / +4 lines)
Lines 82-87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
82
        debug           => 1,
82
        debug           => 1,
83
    }
83
    }
84
);
84
);
85
$template->param(
86
    frameworkcode   => $frameworkcode
87
);
85
88
86
my $record = GetMarcBiblio($biblionumber, 1);
89
my $record = GetMarcBiblio($biblionumber, 1);
87
$template->param( ocoins => GetCOinSBiblio($record) );
90
$template->param( ocoins => GetCOinSBiblio($record) );
Lines 288-294 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbran Link Here
288
# fill item info
291
# fill item info
289
my @item_header_loop;
292
my @item_header_loop;
290
for my $subfield_code ( @item_subfield_codes ) {
293
for my $subfield_code ( @item_subfield_codes ) {
291
    push @item_header_loop, $witness{$subfield_code};
294
    push @item_header_loop, { colname => $subfield_code, label => $witness{$subfield_code} };
292
    for my $item_data ( @item_loop ) {
295
    for my $item_data ( @item_loop ) {
293
        $item_data->{$subfield_code} ||= " "
296
        $item_data->{$subfield_code} ||= " "
294
    }
297
    }
(-)a/installer/data/mysql/atomicupdate/add-table-users_columns_settings.sql (+11 lines)
Line 0 Link Here
1
CREATE TABLE IF NOT EXISTS users_columns_settings (
2
    borrowernumber int(11) NOT NULL,
3
    module varchar(50) NOT NULL,
4
    page varchar(50) NOT NULL,
5
    tablename varchar(50) NOT NULL,
6
    additional_param varchar(255) NOT NULL,
7
    columnname varchar(50) NOT NULL,
8
    is_hidden int(1) NOT NULL DEFAULT 0,
9
    PRIMARY KEY(borrowernumber, module, page, tablename, columnname, additional_param),
10
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
11
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (+16 lines)
Lines 3557-3562 CREATE TABLE IF NOT EXISTS columns_settings ( Link Here
3557
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3557
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3558
3558
3559
--
3559
--
3560
-- Table structure for table `users_columns_settings`
3561
--
3562
3563
CREATE TABLE IF NOT EXISTS users_columns_settings (
3564
    borrowernumber int(11) NOT NULL,
3565
    module varchar(50) NOT NULL,
3566
    page varchar(50) NOT NULL,
3567
    tablename varchar(50) NOT NULL,
3568
    additional_param varchar(255) NOT NULL,
3569
    columnname varchar(50) NOT NULL,
3570
    is_hidden int(1) NOT NULL DEFAULT 0,
3571
    PRIMARY KEY(borrowernumber, module, page, tablename, columnname, additional_param),
3572
    CONSTRAINT borrower_columns_settings_ibfk1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3573
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3574
3575
--
3560
-- Table structure for table 'items_search_fields'
3576
-- Table structure for table 'items_search_fields'
3561
--
3577
--
3562
3578
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-1 / +1 lines)
Lines 6-12 function KohaTable(selector, dt_parameters, columns_settings) { Link Here
6
    var hidden_ids = [];
6
    var hidden_ids = [];
7
    var included_ids = [];
7
    var included_ids = [];
8
    $(columns_settings).each( function() {
8
    $(columns_settings).each( function() {
9
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
9
        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index();
10
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
10
        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
11
        if ( used_id == -1 ) return;
11
        if ( used_id == -1 ) return;
12
12
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt (-4 / +45 lines)
Lines 1-3 Link Here
1
[% USE ColumnsSettings %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Catalog &rsaquo;
3
<title>Koha &rsaquo; Catalog &rsaquo;
3
  [% IF ( unknownbiblionumber ) %]
4
  [% IF ( unknownbiblionumber ) %]
Lines 6-13 Link Here
6
    MARC details for [% bibliotitle %]
7
    MARC details for [% bibliotitle %]
7
  [% END %]
8
  [% END %]
8
</title>
9
</title>
10
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
9
[% INCLUDE 'doc-head-close.inc' %]
11
[% INCLUDE 'doc-head-close.inc' %]
10
[% INCLUDE 'browser-strings.inc' %]
12
[% INCLUDE 'browser-strings.inc' %]
13
[% INCLUDE 'datatables.inc' %]
14
[% INCLUDE 'columns_settings.inc' %]
11
<!--[if lt IE 9]>
15
<!--[if lt IE 9]>
12
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
16
<script type="text/javascript" src="[% interface %]/lib/shims/json2.min.js"></script>
13
<![endif]-->
17
<![endif]-->
Lines 17-25 Link Here
17
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
21
    var browser = KOHA.browser('[% searchid %]', parseInt('[% biblionumber %]', 10));
18
    browser.show();
22
    browser.show();
19
23
20
	 $(document).ready(function() {
24
$(document).ready(function() {
21
        $('#bibliotabs').tabs();
25
    $('#bibliotabs').tabs();
22
	 });
26
27
    var loaded = false;
28
    var columns_settings = [% ColumnsSettings.GetDynamicColumns( 'catalogue', 'marcdetail', 'itemst', frameworkcode ) %];
29
    var itemst = KohaTable("#tab10XX table", {
30
        'bPaginate': false,
31
        'bInfo': false,
32
        "bAutoWidth": false,
33
        "bKohaColumnsUseNames": true,
34
        'stateSave': true,
35
        'stateSaveCallback': function (settings, data) {
36
            if (loaded && typeof settings['aoColumns'] !== 'undefined') {
37
                var columns = {};
38
                $.each( settings['aoColumns'], function( index, value ){
39
                    columns[value.colname] = value.bVisible ? '0' : '1';
40
                });
41
                $.ajax({
42
                    url: "/cgi-bin/koha/svc/users_columns_settings",
43
                    data: {
44
                        columns: JSON.stringify(columns),
45
                        module: 'catalogue',
46
                        page: 'marcdetail',
47
                        tablename: 'itemst',
48
                        additional_param: '[% frameworkcode %]',
49
                    },
50
                    type: "POST",
51
                });
52
            }
53
        },
54
        "aoColumnDefs": [
55
            { "bSortable": false, "bSearchable": false, "aTargets": [ "NoSort" ] }
56
        ]
57
    }, columns_settings);
58
    loaded = true;
59
});
23
60
24
function Changefwk(FwkList) {
61
function Changefwk(FwkList) {
25
	var fwk = FwkList.options[FwkList.selectedIndex].value;
62
	var fwk = FwkList.options[FwkList.selectedIndex].value;
Lines 166-176 function Changefwk(FwkList) { Link Here
166
     [% IF ( tab10XX ) %]
203
     [% IF ( tab10XX ) %]
167
    <div id="tab10XX">
204
    <div id="tab10XX">
168
        <table>
205
        <table>
206
            <thead>
169
                <tr>
207
                <tr>
170
                    [% FOREACH header IN item_header_loop %]
208
                    [% FOREACH header IN item_header_loop %]
171
                        <th>[% header %]</th>
209
                        <th data-colname="[% header.colname %]">[% header.label %]</th>
172
                    [% END %]
210
                    [% END %]
173
                </tr>
211
                </tr>
212
            </thead>
213
            <tbody>
174
                [% FOREACH item IN item_loop %]
214
                [% FOREACH item IN item_loop %]
175
                    <tr>
215
                    <tr>
176
                        [% FOREACH sf_code IN item_subfield_codes %]
216
                        [% FOREACH sf_code IN item_subfield_codes %]
Lines 178-183 function Changefwk(FwkList) { Link Here
178
                        [% END %]
218
                        [% END %]
179
                    </tr>
219
                    </tr>
180
                [% END %]
220
                [% END %]
221
            </tbody>
181
        </table>
222
        </table>
182
    </div>
223
    </div>
183
    [% END %]
224
    [% END %]
(-)a/svc/users_columns_settings (+51 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 Biblibre
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 CGI;
23
use C4::Auth qw(check_cookie_auth get_session);
24
use JSON qw(from_json);
25
use C4::Utils::DataTables::ColumnsSettings;
26
27
my $input = new CGI;
28
29
binmode STDOUT, ":encoding(UTF-8)";
30
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
31
32
my ( $auth_status, $sessionID ) =
33
  check_cookie_auth( $input->cookie('CGISESSID'),
34
    { catalogue => '*' } );
35
36
if ( $auth_status ne "ok" ) {
37
    exit 0;
38
}
39
40
my $session   = get_session($sessionID);
41
42
my $params = {
43
    columns => from_json($input->param('columns')),
44
    module => $input->param('module'),
45
    page => $input->param('page'),
46
    tablename => $input->param('tablename'),
47
    borrowernumber => $session->param('number'),
48
    additional_param => $input->param('additional_param')
49
};
50
51
C4::Utils::DataTables::ColumnsSettings::update_user_columns($params);
(-)a/t/db_dependent/ColumnsSettings.t (-2 / +128 lines)
Lines 1-11 Link Here
1
#!/usr/bin/perl;
1
#!/usr/bin/perl;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 2;
4
use Test::More tests => 5;
5
use Test::MockModule;
5
use Test::MockModule;
6
use t::lib::TestBuilder;
6
7
7
use C4::Context;
8
use C4::Context;
9
use C4::Biblio;
8
use C4::Utils::DataTables::ColumnsSettings;
10
use C4::Utils::DataTables::ColumnsSettings;
11
use C4::Utils::DataTables::DynamicColumnsSettings;
12
13
my $schema = Koha::Database->new()->schema();
14
$schema->storage->txn_begin();
15
16
my $builder = t::lib::TestBuilder->new;
17
9
my $dbh = C4::Context->dbh;
18
my $dbh = C4::Context->dbh;
10
$dbh->{AutoCommit} = 0;
19
$dbh->{AutoCommit} = 0;
11
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
Lines 56-61 $module->mock( Link Here
56
    }
65
    }
57
);
66
);
58
67
68
my $borrower = $builder->build({ source => 'Borrower' });
69
my $context = new Test::MockModule('C4::Context');
70
$context->mock(
71
    'userenv',
72
    sub {
73
        return {
74
            number => $borrower->{borrowernumber}
75
        };
76
    }
77
);
78
79
my $bibliomodule = new Test::MockModule('C4::Biblio');
80
$bibliomodule->mock(
81
    'GetMarcStructure',
82
    sub {
83
        return {
84
            995 => {
85
                'q' => {
86
                       'hidden' => '0',
87
                       'authorised_value' => '',
88
                       'defaultvalue' => '',
89
                       'repeatable' => '0',
90
                       'link' => '',
91
                       'seealso' => undef,
92
                       'tab' => '10',
93
                       'mandatory' => '1',
94
                       'lib' => 'Section',
95
                       'maxlength' => '9999',
96
                       'authtypecode' => '',
97
                       'isurl' => '0',
98
                       'kohafield' => '',
99
                        'value_builder' => ''
100
                },
101
                'j' => {
102
                       'hidden' => '0',
103
                       'authorised_value' => '',
104
                       'defaultvalue' => '',
105
                       'repeatable' => '0',
106
                       'link' => '',
107
                       'seealso' => undef,
108
                       'tab' => '10',
109
                       'mandatory' => '1',
110
                       'lib' => 'Provider',
111
                       'maxlength' => '9999',
112
                       'authtypecode' => '',
113
                       'isurl' => '0',
114
                       'kohafield' => '',
115
                        'value_builder' => ''
116
                },
117
            }
118
        }
119
    }
120
);
121
122
$bibliomodule->mock(
123
    'GetMarcFromKohaField',
124
    sub {
125
        return '995';
126
    }
127
);
128
129
59
C4::Utils::DataTables::ColumnsSettings::update_columns(
130
C4::Utils::DataTables::ColumnsSettings::update_columns(
60
    {
131
    {
61
        columns => [
132
        columns => [
Lines 181-184 for my $m ( keys %$modules ) { Link Here
181
    }
252
    }
182
}
253
}
183
254
255
C4::Utils::DataTables::ColumnsSettings::update_user_columns(
256
    {
257
        columns => {
258
            q => 1,
259
            j => 0
260
        },
261
        borrowernumber   => $borrower->{borrowernumber},
262
        module           => 'catalogue',
263
        page             => 'marcdetail',
264
        tablename        => 'itemst',
265
        additional_param => 'BOOK'
266
    }
267
);
268
269
my @c = $schema->resultset('UsersColumnsSetting')->search(
270
    {
271
        borrowernumber => $borrower->{borrowernumber},
272
        module     => 'catalogue',
273
        page       => 'marcdetail',
274
        tablename  => 'itemst',
275
        columnname => 'q',
276
        additional_param => 'BOOK'
277
    }
278
);
279
is(1, $c[0]->is_hidden, 'Column q is hidden');
280
281
@c = $schema->resultset('UsersColumnsSetting')->search(
282
    {
283
        borrowernumber => $borrower->{borrowernumber},
284
        module     => 'catalogue',
285
        page       => 'marcdetail',
286
        tablename  => 'itemst',
287
        columnname => 'j',
288
        additional_param => 'BOOK'
289
    }
290
);
291
is(0, $c[0]->is_hidden, 'Column j is not hidden');
292
293
my $expected_columns = [
294
    {
295
        columnname         => 'q',
296
        is_hidden          => 1,
297
        cannot_be_modified => 0,
298
        cannot_be_toggled  => 0
299
    },
300
    {
301
        columnname         => 'j',
302
        is_hidden          => 0,
303
        cannot_be_modified => 0,
304
        cannot_be_toggled  => 0
305
    },
306
307
];
308
my $columns = C4::Utils::DataTables::DynamicColumnsSettings::catalogue_marcdetail_itemst('BOOK');
309
is_deeply( $columns, $expected_columns, 'catalogue_marcdetail_itemst should returns all columns' );
310
184
$dbh->rollback;
311
$dbh->rollback;
185
- 

Return to bug 16881