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

(-)a/Koha/Virtualshelves.pm (-2 / +33 lines)
Lines 87-92 sub get_private_shelves { Link Here
87
    my $rows           = $params->{rows};
87
    my $rows           = $params->{rows};
88
    my $borrowernumber = $params->{borrowernumber} || 0;
88
    my $borrowernumber = $params->{borrowernumber} || 0;
89
89
90
    my $sort_by  = $params->{sort_by};
91
    my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } );
92
90
    $self->search(
93
    $self->search(
91
        {
94
        {
92
            public => 0,
95
            public => 0,
Lines 98-104 sub get_private_shelves { Link Here
98
        {
101
        {
99
            join     => ['virtualshelfshares'],
102
            join     => ['virtualshelfshares'],
100
            distinct => 'shelfnumber',
103
            distinct => 'shelfnumber',
101
            order_by => 'shelfname',
104
            order_by => $order_by,
102
            ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
105
            ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
103
        }
106
        }
104
    );
107
    );
Lines 113-130 sub get_public_shelves { Link Here
113
    my $page = $params->{page};
116
    my $page = $params->{page};
114
    my $rows = $params->{rows};
117
    my $rows = $params->{rows};
115
118
119
    my $sort_by  = $params->{sort_by};
120
    my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } );
121
116
    $self->search(
122
    $self->search(
117
        {
123
        {
118
            public => 1,
124
            public => 1,
119
        },
125
        },
120
        {
126
        {
121
            distinct => 'shelfnumber',
127
            distinct => 'shelfnumber',
122
            order_by => 'shelfname',
128
            order_by => $order_by,
123
            ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
129
            ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
124
        }
130
        }
125
    );
131
    );
126
}
132
}
127
133
134
=head3 _prepare_order_by_for_shelves
135
136
Create an "order_by" statement when sorting lists of lists
137
138
=cut
139
140
sub _prepare_order_by_for_shelves {
141
    my ($args)       = @_;
142
    my $sort_by      = $args->{sort_by};
143
    my $order_by_dir = '-asc';
144
    my $order_by_col = 'shelfname';
145
    if ($sort_by) {
146
        my $sortfield = $sort_by->{sortfield};
147
        my $direction = $sort_by->{direction};
148
        if ( $direction eq 'asc' || $direction eq 'desc' ) {
149
            $order_by_dir = '-' . $direction;
150
        }
151
        if ( $sortfield eq 'shelfname' || $sortfield eq 'lastmodified' ) {
152
            $order_by_col = $sortfield;
153
        }
154
    }
155
    my $order_by = { $order_by_dir => $order_by_col };
156
    return $order_by;
157
}
158
128
=head3 get_some_shelves
159
=head3 get_some_shelves
129
160
130
=cut
161
=cut
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt (-3 / +21 lines)
Lines 751-761 Link Here
751
                                    <div id="publicshelves" class="tab-pane active" role="tabpanel" aria-labelledby="public_lists"> </div>
751
                                    <div id="publicshelves" class="tab-pane active" role="tabpanel" aria-labelledby="public_lists"> </div>
752
                                [% END %]
752
                                [% END %]
753
753
754
                                [% SET show_new_list = 0 %]
754
                                [% IF !public || Koha.Preference('OpacAllowPublicListCreation') %]
755
                                [% IF !public || Koha.Preference('OpacAllowPublicListCreation') %]
755
                                    [% IF loggedinusername %]
756
                                    [% IF loggedinusername %]
756
                                        <div id="toolbar" class="toolbar"
757
                                        [% show_new_list = 1 %]
757
                                            ><a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-plus" aria-hidden="true"></i> New list</a></div
758
                                        >
759
                                    [% ELSE %]
758
                                    [% ELSE %]
760
                                        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
759
                                        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
761
                                            <div class="alert alert-info"><a href="/cgi-bin/koha/opac-shelves.pl?op=add_form">Log in to create a new list</a></div>
760
                                            <div class="alert alert-info"><a href="/cgi-bin/koha/opac-shelves.pl?op=add_form">Log in to create a new list</a></div>
Lines 764-769 Link Here
764
                                [% END %]
763
                                [% END %]
765
764
766
                                [% IF shelves.count %]
765
                                [% IF shelves.count %]
766
                                    <div id="toolbar" class="toolbar">
767
                                        [% IF ( show_new_list ) %]
768
                                            <a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-plus" aria-hidden="true"></i> New list</a> <span class="sep">|</span>
769
                                        [% END %]
770
                                        <div class="btn-group dropdown">
771
                                            <button type="button" class="btn btn-link dropdown-toggle" data-bs-toggle="dropdown" id="sortmenu" aria-haspopup="true" aria-expanded="false"
772
                                                ><i class="fa fa-sort" aria-hidden="true"></i> Sort</button
773
                                            >
774
                                            <div class="dropdown-menu dropdown-menu-end" aria-labelledby="sortmenu">
775
                                                <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=">Default sorting</a>
776
                                                <span class="dropdown-header">List name</span>
777
                                                <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=shelfname&direction=asc">List name (A-Z)</a>
778
                                                <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=shelfname&direction=desc">List name (Z-A)</a>
779
                                                <span class="dropdown-header">Modification date</span>
780
                                                <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=lastmodified&direction=desc">Modification date (newest to oldest)</a>
781
                                                <a class="dropdown-item" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=[% public | html %]&sortfield=lastmodified&direction=asc">Modification date (oldest to newest)</a>
782
                                            </div>
783
                                        </div>
784
                                    </div>
767
                                    <table class="table">
785
                                    <table class="table">
768
                                        [% IF !public %]
786
                                        [% IF !public %]
769
                                            <caption class="sr-only">Your lists</caption>
787
                                            <caption class="sr-only">Your lists</caption>
(-)a/opac/opac-shelves.pl (-4 / +11 lines)
Lines 518-530 if ( $op eq 'view' ) { Link Here
518
        push @messages, { type => 'error', code => 'does_not_exist' };
518
        push @messages, { type => 'error', code => 'does_not_exist' };
519
    }
519
    }
520
} elsif ( $op eq 'list' ) {
520
} elsif ( $op eq 'list' ) {
521
    my $direction = $query->param('direction') || 'asc';
522
    my $sortfield = $query->param('sortfield') || 'shelfname';
523
    my $sort_by   = { sortfield => $sortfield, direction => $direction };
524
521
    my $shelves;
525
    my $shelves;
522
    my ($rows) = (20);
526
    my ($rows) = (20);
523
    if ( !$public ) {
527
    if ( !$public ) {
524
        $shelves = Koha::Virtualshelves->get_private_shelves(
528
        $shelves = Koha::Virtualshelves->get_private_shelves(
525
            { page => $page, rows => $rows, borrowernumber => $loggedinuser, } );
529
            { page => $page, rows => $rows, borrowernumber => $loggedinuser, sort_by => $sort_by, } );
526
    } else {
530
    } else {
527
        $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, } );
531
        $shelves = Koha::Virtualshelves->get_public_shelves( { page => $page, rows => $rows, sort_by => $sort_by, } );
528
    }
532
    }
529
533
530
    my $pager = $shelves->pager;
534
    my $pager = $shelves->pager;
Lines 532-538 if ( $op eq 'view' ) { Link Here
532
        shelves        => $shelves,
536
        shelves        => $shelves,
533
        pagination_bar => pagination_bar(
537
        pagination_bar => pagination_bar(
534
            q||,   $pager->last_page - $pager->first_page + 1,
538
            q||,   $pager->last_page - $pager->first_page + 1,
535
            $page, "page", { op => 'list', public => $public, }
539
            $page, "page",
540
            {
541
                op        => 'list', public => $public, sortfield => $sortfield,
542
                direction => $direction,
543
            }
536
        ),
544
        ),
537
    );
545
    );
538
}
546
}
539
- 

Return to bug 18148