LP1160596 - Add pagination for items in My Lists
authorKyle Tomita <ktomita@catalystitservices.com>
Wed, 3 Apr 2013 21:37:41 +0000 (14:37 -0700)
committerDan Wells <dbw2@calvin.edu>
Fri, 13 Sep 2013 18:30:42 +0000 (14:30 -0400)
Added pagination with page numbers when viewing the items in
a list.  Also made the number of list items per page a user
setting, per the suggestions of Pasi Kallinen and Jason
Stephenson.

The setting is located in, Account Preferences -> My Lists Preferences

Update: Added i18n part to allow for translation.  Removed hard-coded
bre.source.

Signed-off-by: Kyle Tomita <ktomita@catalystitservices.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.add_setting_for_selecting_items_per_page_of_a_my_list.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/myopac/prefs_my_lists.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/myopac/prefs_base.tt2

index 48931e8..0af9399 100644 (file)
@@ -195,6 +195,7 @@ sub load {
     return $self->load_myopac_hold_history if $path =~ m|opac/myopac/hold_history|;
     return $self->load_myopac_prefs_notify if $path =~ m|opac/myopac/prefs_notify|;
     return $self->load_myopac_prefs_settings if $path =~ m|opac/myopac/prefs_settings|;
+    return $self->load_myopac_prefs_my_lists if $path =~ m|opac/myopac/prefs_my_lists|;
     return $self->load_myopac_prefs if $path =~ m|opac/myopac/prefs|;
     return $self->load_sms_cn if $path =~ m|opac/sms_cn|;
 
index a7f60a4..22182ee 100644 (file)
@@ -466,6 +466,42 @@ sub load_myopac_prefs_settings {
     return $self->_load_user_with_prefs || Apache2::Const::OK;
 }
 
+sub load_myopac_prefs_my_lists {
+    my $self = shift;
+
+    my @user_prefs = qw/
+        opac.list_items_per_page
+    /;
+
+    my $stat = $self->_load_user_with_prefs;
+    return $stat if $stat;
+
+    return Apache2::Const::OK
+        unless $self->cgi->request_method eq 'POST';
+
+    # some setting values from the form don't match the
+    # required value/format for the db, so they have to be
+    # individually translated.
+
+    my %settings;
+    my $set_map = $self->ctx->{user_setting_map};
+
+    foreach my $key (@user_prefs) {
+        my $val = $self->cgi->param($key);
+        $settings{$key}= $val unless $$set_map{$key} eq $val;
+    }
+
+    # Send the modified settings off to be saved
+    $U->simplereq(
+        'open-ils.actor',
+        'open-ils.actor.patron.settings.update',
+        $self->editor->authtoken, undef, \%settings);
+
+    # re-fetch user prefs
+    $self->ctx->{updated_user_settings} = \%settings;
+    return $self->_load_user_with_prefs || Apache2::Const::OK;
+}
+
 sub fetch_user_holds {
     my $self = shift;
     my $hold_ids = shift;
@@ -1705,6 +1741,22 @@ sub _update_bookbag_metadata {
     return 0;
 }
 
+sub _get_items_per_page {
+    my $self = shift;
+
+    if($self->editor->requestor) {
+        $self->timelog("Checking for opac.list_items_per_page preference");
+        # See if the user has a list items per page preference
+        my $ipp = $self->editor->search_actor_user_setting({
+            usr => $self->editor->requestor->id,
+            name => 'opac.list_items_per_page'
+        })->[0];
+        $self->timelog("Got opac.list_items_per_page preference");
+        return OpenSRF::Utils::JSON->JSON2perl($ipp->value) if $ipp;
+    }
+    return 10; # default
+}
+
 sub load_myopac_bookbags {
     my $self = shift;
     my $e = $self->editor;
@@ -1715,6 +1767,12 @@ sub load_myopac_bookbags {
     $ctx->{bookbags_limit} = $limit;
     $ctx->{bookbags_offset} = $offset;
 
+    # for list item pagination
+    my $itemLimit = $self->_get_items_per_page;
+    my $itemPage = $self->cgi->param('itemPage') || 1;
+    my $itemOffset = ($itemPage - 1) * $itemLimit;
+    $ctx->{bookbags_itemPage} = $itemPage;
+
     my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort");
     $e->xact_begin; # replication...
 
@@ -1753,13 +1811,71 @@ sub load_myopac_bookbags {
     $ctx->{bookbag_count} = $r->[0]->{'count'};
 
     # If the user wants a specific bookbag's items, load them.
-    # XXX add bookbag item paging support
 
     if ($self->cgi->param("bbid")) {
         my ($bookbag) =
             grep { $_->id eq $self->cgi->param("bbid") } @{$ctx->{bookbags}};
 
         if ($bookbag) {
+            # Calculate total count of the items in selected bookbag.
+            # This total includes record entries that have no assets available.
+            my $iq = {
+                'select' => { 'acn' => [ { 'column' => 'record', 'distinct' => 'true', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] },
+                'from' => {'cbrebi' =>
+                    { 'bre' =>
+                        { 'join' =>
+                            { 'acn' =>
+                                { 'join' =>
+                                    { 'acp' =>
+                                        { 'join' =>
+                                            { 'ccs' => {}
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                },
+                'where' => {
+                        '+cbrebi' => { 'bucket' => $bookbag->id },
+                        '+acn' => { 'deleted' => 'f' },
+                        '+ccs' => { 'opac_visible' => 't' },
+                        '+acp' => {
+                                'deleted' => 'f',
+                                'opac_visible' => 't'
+                            }
+                    }
+            };
+            my $ir = $e->json_query($iq);
+            $ctx->{bb_item_count} = $ir->[0]->{'count'};
+            #now add ebooks
+            my $ebook_q = {
+                'select' => { 'cbrebi' => [ { 'column' => 'target_biblio_record_entry', 'distinct' => 'true', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] },
+                'from' => {'cbrebi' =>
+                    { 'bre' =>
+                        { 'join' =>
+                            {
+                                'cbs' => {}
+                            }
+                        }
+                    }
+                },
+                'where' => {
+                        '+cbrebi' => { 'bucket' => $bookbag->id },
+                        '+bre' => {
+                                'deleted' => 'f',
+                                'active' => 't'
+                            },
+                        '+cbs' => { 'transcendant' => 't' }
+                    }
+            };
+            my $ebook_r = $e->json_query($ebook_q);
+            $ctx->{bb_item_count} = $ctx->{bb_item_count} + $ebook_r->[0]->{'count'};
+
+            #calculate page count
+            $ctx->{bb_page_count} = int ((($ctx->{bb_item_count} - 1) / $itemLimit) + 1);
+
             if ( ($self->cgi->param("action") || '') eq "editmeta") {
                 if (!$self->_update_bookbag_metadata($bookbag))  {
                     $e->rollback;
@@ -1789,11 +1905,10 @@ sub load_myopac_bookbags {
                 $bookbag->id, $sorter, $modifier
             );
 
-            # XXX Limiting to 1000 for now.  This way you should be able to see entire
-            # list contents.  Need to add paging here instead.
+            # For list items pagination
             my $args = {
-                "limit" => 1000,
-                "offset" => 0
+                "limit" => $itemLimit,
+                "offset" => $itemOffset
             };
 
             my $items = $U->bib_container_items_via_search($bookbag->id, $query, $args)
index 30e6b3e..77cdf76 100644 (file)
@@ -2556,6 +2556,25 @@ INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatyp
     oils_i18n_gettext('opac.default_pickup_location', 'Default location for holds pickup', 'cust', 'description'),
     'integer');
 
+INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
+    VALUES (
+        'opac.list_items_per_page',
+        TRUE,
+        oils_i18n_gettext(
+            'opac.list_items_per_page',
+            'List Items per Page',
+            'cust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'opac.list_items_per_page',
+            'A number designating the amount of list items displayed per page of a selected list.',
+            'cust',
+            'description'
+        ),
+        'string'
+    );
+
 -- Add groups for org_unit settings
 INSERT INTO config.settings_group (name, label) VALUES
 ('acq', oils_i18n_gettext('config.settings_group.system', 'Acquisitions', 'coust', 'label')),
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.add_setting_for_selecting_items_per_page_of_a_my_list.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.add_setting_for_selecting_items_per_page_of_a_my_list.sql
new file mode 100644 (file)
index 0000000..9aac3ee
--- /dev/null
@@ -0,0 +1,28 @@
+-- Evergreen DB patch XXXX.add_setting_for_selecting_items_per_page_of_a_my_list.sql
+--
+-- Adds a setting for selecting the number of items per page of a my list.
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
+    VALUES (
+        'opac.list_items_per_page',
+        TRUE,
+        oils_i18n_gettext(
+            'opac.list_items_per_page',
+            'List Items per Page',
+            'cust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'opac.list_items_per_page',
+            'A number designating the amount of list items displayed per page of a selected list.',
+            'cust',
+            'description'
+        ),
+        'string'
+    );
+
index ec729e7..7707624 100644 (file)
@@ -4,6 +4,7 @@
     myopac_page = "lists"  
     limit = ctx.bookbags_limit;
     offset = ctx.bookbags_offset;
+    itemPage = ctx.bookbags_itemPage;
 %]
 <div id='myopac_bookbag_div' style="padding:5px;">
 
@@ -86,7 +87,7 @@
             <div class="bookbag-controls most">
                 [% baseurl = ctx.opac_root _ '/myopac/lists';
                 IF bbag.id != CGI.param("bbid");
-                    url = mkurl(baseurl,{bbid => bbag.id},['edit_notes','sort']);
+                    url = mkurl(baseurl,{bbid => bbag.id, itemPage => 1},['edit_notes','sort']);
                     ltitle = l("Show items in list");
                 ELSE;
                     url = mkurl(baseurl, {}, ['bbid', 'edit_notes', 'sort']);
                 [% END %]
             </tbody>
         </table>
+
+        [% IF ctx.bb_page_count > 1; %]
+            <div class="header_middle" style="padding-top:7px;">
+                <span class="float-left" style="padding-left:34px;">[% l('Navigate Selected List ') %]</span>
+                <span class='float-left' style='padding-left: 10px;'>
+                    [%- IF itemPage > 1 -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage - 1
+                        }) %]'><span class="nav_arrow_fix">&#9668;</span>[% l('Previous') %]</a>
+                    [%- END; -%]
+
+                    [%- IF (itemPage - 3) >= 1 -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage - 3
+                        }) %]'>[% itemPage - 3 %]</a>
+                    [%- END; -%]
+                    [%- IF (itemPage - 2) >= 1 -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage - 2
+                        }) %]'>[% itemPage - 2 %]</a>
+                    [%- END; -%]
+                    [%- IF (itemPage - 1) >= 1 -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage - 1
+                        }) %]'>[% itemPage - 1%]</a>
+                    [%- END; -%]
+                    <span style="color:red;" >[% itemPage %]</span>
+                    [%- IF (itemPage + 1) <= ctx.bb_page_count -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage + 1
+                        }) %]'>[% itemPage + 1 %]</a>
+                    [%- END; -%]
+                    [%- IF (itemPage + 2) <= ctx.bb_page_count -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage + 2
+                        }) %]'>[% itemPage + 2 %]</a>
+                    [%- END; -%]
+                    [%- IF (itemPage + 3) <= ctx.bb_page_count -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage + 3
+                        }) %]'>[% itemPage + 3 %]</a>
+                    [%- END; -%]
+
+                    [%- IF (itemPage + 1) <= ctx.bb_page_count; -%]
+                        <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                            itemPage => itemPage + 1
+                        }) %]'>[% l('Next') %]<span class="nav_arrow_fix">&#9658;</span></a>
+                    [%- END; -%]
+                 </span>
+            </div>
+            <div class="clear-both"></div>
+        [% END %]
+        <br/>
+
         </form>
         [% END %]
         [% END %]
diff --git a/Open-ILS/src/templates/opac/myopac/prefs_my_lists.tt2 b/Open-ILS/src/templates/opac/myopac/prefs_my_lists.tt2
new file mode 100644 (file)
index 0000000..746df98
--- /dev/null
@@ -0,0 +1,45 @@
+[%  PROCESS "opac/parts/header.tt2";
+    WRAPPER "opac/parts/myopac/prefs_base.tt2";
+    myopac_page = "prefs";
+    prefs_page = 'my_lists' %]
+
+
+    <form method='post'>
+
+       <table class="full-width data_grid" id="acct_search_main">
+            <tbody>
+
+                [% IF ctx.updated_user_settings %]
+                <tr><td colspan='2'>
+                    <div class='renew-summary'>
+                        [% l('Account Successfully Updated') %]
+                    </div>
+                </td></tr>
+                [% END %]
+
+                [%- setting = 'opac.list_items_per_page' -%]
+                <tr >
+                    <td width='20%'><label for='[% setting %]'>[%l("List items per page") %]</label></td>
+                    <td>
+                        <select id='[% setting %]' name='[% setting %]'>
+                            [%  UNLESS ctx.user_setting_map.$setting;
+                                    ctx.user_setting_map.$setting = 10;
+                                END;
+                                FOR val IN [10, 15, 20, 25, 50] %]
+                                <option value='[% val | uri %]' 
+                                    [% IF ctx.user_setting_map.$setting == val %]
+                                        selected='selected'[% END %]>[% val | html %]</option>
+                            [% END %]
+                        </select>
+                        <img alt="[% l('List Items Help') %]"
+                            src="[% ctx.media_prefix %]/images/question-mark.png"
+                            title="[% l('The number of list items displayed per page when viewing a selected list.') %]"
+                        />
+                    </td>
+                </tr>
+            </tbody>
+        </table>
+        <input type="submit" value="[% l('Save') %]" alt="[% l('Save') %]" class="opac-button"/>
+    </form>
+    [% INCLUDE "opac/parts/myopac/prefs_hints.tt2" %]
+[% END %]
index 5f3a154..031da15 100644 (file)
@@ -15,6 +15,9 @@
             <div class="align">
                 <a href='[% mkurl('prefs_settings') %]'>[% l("Search and History Preferences") %]</a>
             </div>
+            <div class="align">
+                <a href='[% mkurl('prefs_my_lists') %]'>[% l("My Lists Preferences") %]</a>
+            </div>
         [% ELSIF prefs_page == 'notify' %]
             <div class="align">
                 <a href='[% mkurl('prefs') %]'>[% l("Personal Information") %]</a>
             <div class="align" >
                 <a href='[% mkurl('prefs_settings') %]'>[% l("Search and History Preferences") %]</a>
             </div>
-        [% ELSE %]
+            <div class="align">
+                <a href='[% mkurl('prefs_my_lists') %]'>[% l("My Lists Preferences") %]</a>
+            </div>
+        [% ELSIF prefs_page == 'settings' %]
             <div class="align">
                 <a href='[% mkurl('prefs') %]'>[% l("Personal Information") %]</a>
             </div>
             <div class="align selected" >
                 <a href='#'>[% l("Search and History Preferences") %]</a>
             </div>
+            <div class="align">
+                <a href='[% mkurl('prefs_my_lists') %]'>[% l("My Lists Preferences") %]</a>
+            </div>
+        [% ELSE %]
+            <div class="align">
+                <a href='[% mkurl('prefs') %]'>[% l("Personal Information") %]</a>
+            </div>
+            <div class="align">
+                <a href='[% mkurl('prefs_notify') %]'>[% l("Notification Preferences") %]</a>
+            </div>
+            <div class="align" >
+                <a href='[% mkurl('prefs_settings') %]'>[% l("Search and History Preferences") %]</a>
+            </div>
+            <div class="align selected">
+                <a href='#'>[% l("My Lists Preferences") %]</a>
+            </div>
         [% END %]
         </div>
     </div>