
zzbbyy at gmail
Dec 23, 2008, 5:13 AM
Post #2 of 20
(3216 views)
Permalink
|
On Tue, Dec 23, 2008 at 12:34 PM, Jesse Sheidlower <jester [at] panix> wrote: > > Some time ago, I developed or stole a TT pager that I now use > in all of my Cat apps. It looks like this, though occasionally > with minor CSS tweaks: > > --- > > <hr> > [% IF pager.last_page > 1 %] > <p><span class="lead"> > [% IF pager.previous_page %] > [<a href="[% c.req.uri_with({'page' => pager.previous_page}) %]">previous</a >>] > [% ELSE %] > [previous] > [% END %] > [% FOR page IN [1..pager.last_page] %] > [% IF page == pager.current_page %] > [[% page %]] > [% ELSE %] > [<a href="[% c.req.uri_with({'page' => page}) %]">[% page %]</a>] > [% END %] > [% END # FOR...%] > > [% IF pager.next_page %] > [<a href="[% c.req.uri_with({'page' => pager.next_page}) %]">next</a>] > [% ELSE %] > [next] > [% END %] > </span></p> > [% END # IF... %] > > --- > > However, a frustration is that when I have excessively large > result sets (such as might generate dozens or hundreds of > pages), it takes a long to generate and looks like hell. So > I'd like to change this to one that only shows, say, 10 pages, > and then has a "previous ten/next ten" and/or "first"/"last" > or something like that, whatever the standard is now. > > Does someone have a model I can steal from? > In my very old code I have: sub pages_links { my ( $c, $pages_count, $valid ) = @_; my $curr_page = $valid->{page} || 1; my $result = ''; if ( $curr_page > 12 ){ $result .= create_param_link ( $c, 'page', 1, $valid ) . ' ... '; } for my $page ( max ( 1, $curr_page - 10 ) .. min ( $curr_page + 10, $pages_count ) ){ $result .= create_param_link ( $c, 'page', $page, $valid ); } if ( $curr_page < $pages_count - 11 ){ $result .= ' ... ' . create_param_link ( $c, 'page', $pages_count, $valid ); } return $result; } This was before I discovered uri_with (or perhaps even before that was introduced) and create_param_link is what I wrote instead. $valid is a hash ref of the rest of the parameters. -- Zbigniew Lukasiak http://brudnopis.blogspot.com/ http://perlalchemy.blogspot.com/ _______________________________________________ List: Catalyst [at] lists Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst [at] lists/ Dev site: http://dev.catalyst.perl.org/
|