Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

OT: Better TT pager?

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


jester at panix

Dec 23, 2008, 3:34 AM

Post #1 of 20 (3316 views)
Permalink
OT: Better TT pager?

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?

Thanks.

Jesse

_______________________________________________
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/


zzbbyy at gmail

Dec 23, 2008, 5:13 AM

Post #2 of 20 (3213 views)
Permalink
Re: OT: Better TT pager? [In reply to]

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/


fernan.aguero at gmail

Dec 23, 2008, 6:19 AM

Post #3 of 20 (3221 views)
Permalink
Re: OT: Better TT pager? [In reply to]

On Tue, Dec 23, 2008 at 9:34 AM, 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:

[snipped code]

> 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?
>
> Thanks.
>
> Jesse

This is what I use in my template:

<script type="text/javascript" language="JavaScript">
function resize(uri) { eval( location = uri ); }
</script>

[% IF pager.total_entries() > 0 -%]
<p><b>[% pager.total_entries() -%]</b> records found <b>|</b>
Showing page <b>[% pager.current_page() -%]</b> of [% pager.last_page() -%]
(records [% pager.first() -%]-[% pager.last() -%]) <b>|</b>
Number of records to display
<select name="pagesize" onChange="resize(this.value)" style="width: 60px">
[% FOREACH val = [ "25", "50", "100", "150", "200" ] -%]
<option [% IF val == pagesize -%]selected[% END -%]
value="[% Catalyst.request.uri_with( rows => val ) -%]">[% val -%]</option>
[% END -%]
</select>
</p>

<p><small><b>Go to page:</b> &nbsp;
[% IF page != pager.first_page() -%]
<a href="[% Catalyst.request.uri_with( page => pager.first_page() )
-%]">first</a>
[% END -%]

[% IF pager.previous_page -%]
<a href="[% Catalyst.request.uri_with( page => pager.previous_page() )
-%]">previous</a>
[% END -%]

[% IF pager.next_page -%]
<a href="[% Catalyst.request.uri_with( page => pager.next_page() ) -%]">next</a>
[% END -%]

[% IF page != pager.last_page() -%]
<a href="[% Catalyst.request.uri_with( page => pager.last_page() )-%]">
last</a>
[% END -%]
</small></p>


In the controller, as Zbigniew suggested, you just have to:

my $page = $c->req->param('page') || 1;
my $rows = $c->req->param('rows') || 25;
$c->stash->{page} = $page;
$c->stash->{pagesize} = $rows;
my $where = { # your SQL/DBIC conditions here };
my $attr = { page => $page, rows => $rows };
my $rs = $model->search( $where, $attr );
my $pager = $rs->pager();
$c->stash->{pager} = $pager;
$c->stash->{template} = 'your_template.tt';

HTH,

--
fernan

_______________________________________________
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/


emarkert at aim

Dec 23, 2008, 7:35 AM

Post #4 of 20 (3226 views)
Permalink
Re: OT: Better TT pager? [In reply to]

On Tue, Dec 23, 2008 at 9:34 AM, 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:

Have you checked out Template::Plugin::Pagination?

http://cpan.org/modules/by-module/Template/Template-Plugin-Pagination-0.90.readme

This looks like it might do what you're asking.


moseley at hank

Dec 23, 2008, 7:49 AM

Post #5 of 20 (3225 views)
Permalink
Re: OT: Better TT pager? [In reply to]

On Tue, Dec 23, 2008 at 06:34:06AM -0500, Jesse Sheidlower 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:

Well, FWIW, here's my old code. I probably should clean up before
posting and provide some config instead of hard-coded values, but...


[%
# pager.tt
#
# Creates stash entries: (all localized)
# page_nav.summary = "Viewing: 41 - 50 of 200"
# page_nav.previous = "Previous" link if exists
# page_nav.next = "Next" link if exists
# page_nav.pages = list of pages as html

RETURN UNLESS pager.last_page > 1;




page_nav.summary = loc( [
'<em>Viewing Page:</em> [_1] of [_2]',
pager.current_page,
pager.last_page,
] );



# Create url object to modify

USE u = URL(c.uri_path, c.req.parameters );


IF pager.current_page > 1;
lnk = u( p = pager.current_page - 1);
label = loc('Previous');
page_nav.previous = "<a href='$lnk'><em>$label</em></a>";
END;


IF pager.current_page < pager.last_page;
lnk = u( p = pager.current_page + 1);
label = loc('Next');
page_nav.next = "<a href='$lnk'><em>$label</em></a>";
END;

# Set start and end position of sliding window
IF pager.current_page <= 6;
page_start = 1;
page_end = 10;
ELSE;
page_start = pager.current_page - 5;
page_end = page_start + 9;
END;

SET page_end = pager.last_page IF page_end > pager.last_page;


pg = []; # list of pages

FOR num IN [ page_start .. page_end ];

IF num == pager.current_page;
pg.push( '<em>' _ num _ '</em>' );
NEXT;
END;

lnk = u( p = num);
pg.push( "<a href='$lnk'>$num</a>");
END;

page_nav.pages = pg;

%]

[% BLOCK formatted_page_nav %]
<div class="pager">
<p>
[% page_nav.summary %]
</p>
<ol>
[%- "<li>$page_nav.previous</li>" IF page_nav.previous %]
[%- FOR p = page_nav.pages %]
<li>[% p %]</li>
[%- END %]
[%- "<li>$page_nav.next</li>" IF page_nav.next %]
</ol>
</div>
[% END %]


--
Bill Moseley
moseley [at] hank
Sent from my iMutt


_______________________________________________
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/


pagaltzis at gmx

Dec 24, 2008, 3:18 PM

Post #6 of 20 (3199 views)
Permalink
Re: OT: Better TT pager? [In reply to]

* Jesse Sheidlower <jester [at] panix> [2008-12-23 12:45]:
> Does someone have a model I can steal from?

I have something pretty close to that. Not entirely happy insofar
as that I want to add the ability show a few links to skip 10 and
20 pages as appropriate, and it’s not abstracted as it should be,
but as a starting point it should work.

USE decimal = format('%d') ;
BLOCK pagination ;
IF NOT page ; page = 0 ; END ;
last_page = decimal( ( num_trials - 1 ) / per_page );

IF last_page ;
%]<div class="pagination">[%
%]<a href="[% c.req.uri_with( page = [] ) %]"[% ' class="current"' IF NOT page %]>1</a>[%

linked_page = page - 4 ;
IF linked_page < 1 ; linked_page = 1 ; END ;

until_page = linked_page + 7 ;
IF last_page <= until_page ;
until_page = last_page - 1 ;
linked_page = until_page - 7 ;
IF linked_page < 1 ; linked_page = 1 ; END ;
END ;

'<i>&#x2026;</i>' IF 1 < linked_page ;

WHILE ( linked_page <= until_page ) AND ( linked_page < last_page ) ;
%]<a href="[% c.req.uri_with( page = linked_page ) %]"[% ' class="current"' IF page == linked_page %]>[% linked_page + 1 %]</a>[%
linked_page = linked_page + 1 ;
END ;

'<i>&#x2026;</i>' IF linked_page < last_page ;
%]<a href="[% c.req.uri_with( page = last_page ) %]"[% ' class="current"' IF page == last_page %]>[% last_page + 1 %]</a>[%

%]</div>[%
END ;
END ;

This is also a perfect demonstration of why I say that TT sucks.
This should by all rights be handled in the template since it’s
display logic, but writing it in that TT mini-language rather
than Perl is fugly. And PERL and RAWPERL blocks have their own
problems. Anyway. Someday I’ll quit yapping and write some code.

The CSS for styling that looks like this:

div.pagination {
margin: 1.1em 0 0.5em;
text-align: right;
padding: 0.2em 0;
}

div.pagination i {
font-style: normal;
}

div.pagination a:link,
div.pagination a:visited {
border: 1px solid #359;
background-color: #f0f0e6;
padding: 0.1em 0.3em;
margin: 0 0.2em;
}

div.pagination a.current,
div.pagination a:focus,
div.pagination a:hover,
div.pagination a:active {
background-color: #47b;
color: #fff;
}

I’m not sure how selfcontained that is, but I can’t be bothered
to dig through the rest of my stylesheets right now.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
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/


davewood at gmx

Jan 22, 2009, 4:54 AM

Post #7 of 20 (2980 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

On Thu, Dec 25, 2008 at 12:18 AM, Aristotle Pagaltzis <pagaltzis [at] gmx> wrote:
> * Jesse Sheidlower <jester [at] panix> [2008-12-23 12:45]:
>> Does someone have a model I can steal from?
>
> I have something pretty close to that. Not entirely happy insofar
> as that I want to add the ability show a few links to skip 10 and
> 20 pages as appropriate, and it's not abstracted as it should be,
> but as a starting point it should work.
>
> USE decimal = format('%d') ;
> BLOCK pagination ;
> IF NOT page ; page = 0 ; END ;
> last_page = decimal( ( num_trials - 1 ) / per_page );
>
> IF last_page ;
> %]<div class="pagination">[%
> %]<a href="[% c.req.uri_with( page = [] ) %]"[% ' class="current"' IF NOT page %]>1</a>[%
>
> linked_page = page - 4 ;
> IF linked_page < 1 ; linked_page = 1 ; END ;
>
> until_page = linked_page + 7 ;
> IF last_page <= until_page ;
> until_page = last_page - 1 ;
> linked_page = until_page - 7 ;
> IF linked_page < 1 ; linked_page = 1 ; END ;
> END ;
>
> '<i>&#x2026;</i>' IF 1 < linked_page ;
>
> WHILE ( linked_page <= until_page ) AND ( linked_page < last_page ) ;
> %]<a href="[% c.req.uri_with( page = linked_page ) %]"[% ' class="current"' IF page == linked_page %]>[% linked_page + 1 %]</a>[%
> linked_page = linked_page + 1 ;
> END ;
>
> '<i>&#x2026;</i>' IF linked_page < last_page ;
> %]<a href="[% c.req.uri_with( page = last_page ) %]"[% ' class="current"' IF page == last_page %]>[% last_page + 1 %]</a>[%
>
> %]</div>[%
> END ;
> END ;
>
> This is also a perfect demonstration of why I say that TT sucks.
> This should by all rights be handled in the template since it's
> display logic, but writing it in that TT mini-language rather
> than Perl is fugly. And PERL and RAWPERL blocks have their own
> problems. Anyway. Someday I'll quit yapping and write some code.
>
> The CSS for styling that looks like this:
>
> div.pagination {
> margin: 1.1em 0 0.5em;
> text-align: right;
> padding: 0.2em 0;
> }
>
> div.pagination i {
> font-style: normal;
> }
>
> div.pagination a:link,
> div.pagination a:visited {
> border: 1px solid #359;
> background-color: #f0f0e6;
> padding: 0.1em 0.3em;
> margin: 0 0.2em;
> }
>
> div.pagination a.current,
> div.pagination a:focus,
> div.pagination a:hover,
> div.pagination a:active {
> background-color: #47b;
> color: #fff;
> }
>
> I'm not sure how selfcontained that is, but I can't be bothered
> to dig through the rest of my stylesheets right now.
>
> Regards,
> --
> Aristotle Pagaltzis // <http://plasmasturm.org/>
>
> _______________________________________________
> 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/
>

I adapted one of the proposals and felt I should share it with you.

in my Controller:
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
my $page = $c->req->param('page') || 1;
my $rows = $c->req->param('rows') || 3;
my $where = { };
my $attr = { page => $page, rows => $rows, order_by => "created desc" };
my $rs = $c->model('DB::Pictures')->search( $where, $attr );
my $pager = $rs->pager();
$c->stash->{pager} = $pager;
$c->stash->{pictures} = [$rs->all];
$c->stash->{template} = 'pictures/list.tt2';
}


in my template.tt2:
</div>
[% IF pager.current_page() != pager.first_page() -%]
<a href="[% c.request.uri_with( page => pager.first_page() )
-%]">&lt;&lt;</a>
[% END -%]

[% IF pager.previous_page -%]
<a href="[% c.request.uri_with( page => pager.previous_page() )
-%]"> &lt;</a>
[% END -%]

[% IF pager.next_page -%]
<a href="[% c.request.uri_with( page => pager.next_page() ) -%]"> &gt;</a>
[% END -%]

[% IF pager.current_page != pager.last_page() -%]
<a href="[% c.request.uri_with( page => pager.last_page() )-%]">
&gt;&gt;</a>
[% END -%]
</div>
<div>
[% IF pager.total_entries() > 0 -%]
[% pager.total_entries() -%] pictures found |
Showing page <b>[% pager.current_page() -%]</b> of [% pager.last_page() -%]
[% END -%]
</div>

Works fine so far.

david

--
David Schmidt | http://www.fm5.at

_______________________________________________
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/


oliver.g.charles at googlemail

Jan 22, 2009, 7:48 AM

Post #8 of 20 (2981 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

I might as well join in with this :) Here's what we use at work:

[% IF pager %]
<ul class="paginator">
<li class="counter">Page [% pager.current_page %] of [%
pager.last_page %]</li>
<li><a href="[% c.req.uri_with( page => pager.first_page )
%]">&laquo;</a></li>
[% IF pager.previous_page %]
<li><a href="[% c.req.uri_with( page =>
pager.previous_page ) %]">&lt;</a></li>
[% END %]

[.% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3) : 1;
FOREACH page IN [ start .. pager.last_page ] %]
[% LAST IF loop.count > 6 %]
<li[% IF pager.current_page == page; ' class="current"'; END %]>
<a href="[% c.req.uri_with( page => page ) %]">[% page %]</a>
</li>
[% END %]

[% IF pager.next_page %]
<li><a href="[% c.req.uri_with( page => pager.next_page )
%]">&gt;</a></li>
[% END %]
<li><a href="[% c.req.uri_with( page => pager.last_page )
%]">&raquo;</a></li>
</ul>
[% END %]

Though my colleague rightly suggested we subclass Data::Page and
perform the sliding window in there. This shows first page, previous
page, the current page surrounded by near-by pages. Seems to do the
job so far!

On Thu, Jan 22, 2009 at 12:54 PM, David Schmidt <davewood [at] gmx> wrote:
> On Thu, Dec 25, 2008 at 12:18 AM, Aristotle Pagaltzis <pagaltzis [at] gmx> wrote:
>> * Jesse Sheidlower <jester [at] panix> [2008-12-23 12:45]:
>>> Does someone have a model I can steal from?
>>
>> I have something pretty close to that. Not entirely happy insofar
>> as that I want to add the ability show a few links to skip 10 and
>> 20 pages as appropriate, and it's not abstracted as it should be,
>> but as a starting point it should work.
>>
>> USE decimal = format('%d') ;
>> BLOCK pagination ;
>> IF NOT page ; page = 0 ; END ;
>> last_page = decimal( ( num_trials - 1 ) / per_page );
>>
>> IF last_page ;
>> %]<div class="pagination">[%
>> %]<a href="[% c.req.uri_with( page = [] ) %]"[% ' class="current"' IF NOT page %]>1</a>[%
>>
>> linked_page = page - 4 ;
>> IF linked_page < 1 ; linked_page = 1 ; END ;
>>
>> until_page = linked_page + 7 ;
>> IF last_page <= until_page ;
>> until_page = last_page - 1 ;
>> linked_page = until_page - 7 ;
>> IF linked_page < 1 ; linked_page = 1 ; END ;
>> END ;
>>
>> '<i>&#x2026;</i>' IF 1 < linked_page ;
>>
>> WHILE ( linked_page <= until_page ) AND ( linked_page < last_page ) ;
>> %]<a href="[% c.req.uri_with( page = linked_page ) %]"[% ' class="current"' IF page == linked_page %]>[% linked_page + 1 %]</a>[%
>> linked_page = linked_page + 1 ;
>> END ;
>>
>> '<i>&#x2026;</i>' IF linked_page < last_page ;
>> %]<a href="[% c.req.uri_with( page = last_page ) %]"[% ' class="current"' IF page == last_page %]>[% last_page + 1 %]</a>[%
>>
>> %]</div>[%
>> END ;
>> END ;
>>
>> This is also a perfect demonstration of why I say that TT sucks.
>> This should by all rights be handled in the template since it's
>> display logic, but writing it in that TT mini-language rather
>> than Perl is fugly. And PERL and RAWPERL blocks have their own
>> problems. Anyway. Someday I'll quit yapping and write some code.
>>
>> The CSS for styling that looks like this:
>>
>> div.pagination {
>> margin: 1.1em 0 0.5em;
>> text-align: right;
>> padding: 0.2em 0;
>> }
>>
>> div.pagination i {
>> font-style: normal;
>> }
>>
>> div.pagination a:link,
>> div.pagination a:visited {
>> border: 1px solid #359;
>> background-color: #f0f0e6;
>> padding: 0.1em 0.3em;
>> margin: 0 0.2em;
>> }
>>
>> div.pagination a.current,
>> div.pagination a:focus,
>> div.pagination a:hover,
>> div.pagination a:active {
>> background-color: #47b;
>> color: #fff;
>> }
>>
>> I'm not sure how selfcontained that is, but I can't be bothered
>> to dig through the rest of my stylesheets right now.
>>
>> Regards,
>> --
>> Aristotle Pagaltzis // <http://plasmasturm.org/>
>>
>> _______________________________________________
>> 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/
>>
>
> I adapted one of the proposals and felt I should share it with you.
>
> in my Controller:
> sub index :Path :Args(0) {
> my ( $self, $c ) = @_;
> my $page = $c->req->param('page') || 1;
> my $rows = $c->req->param('rows') || 3;
> my $where = { };
> my $attr = { page => $page, rows => $rows, order_by => "created desc" };
> my $rs = $c->model('DB::Pictures')->search( $where, $attr );
> my $pager = $rs->pager();
> $c->stash->{pager} = $pager;
> $c->stash->{pictures} = [$rs->all];
> $c->stash->{template} = 'pictures/list.tt2';
> }
>
>
> in my template.tt2:
> </div>
> [% IF pager.current_page() != pager.first_page() -%]
> <a href="[% c.request.uri_with( page => pager.first_page() )
> -%]">&lt;&lt;</a>
> [% END -%]
>
> [% IF pager.previous_page -%]
> <a href="[% c.request.uri_with( page => pager.previous_page() )
> -%]"> &lt;</a>
> [% END -%]
>
> [% IF pager.next_page -%]
> <a href="[% c.request.uri_with( page => pager.next_page() ) -%]"> &gt;</a>
> [% END -%]
>
> [% IF pager.current_page != pager.last_page() -%]
> <a href="[% c.request.uri_with( page => pager.last_page() )-%]">
> &gt;&gt;</a>
> [% END -%]
> </div>
> <div>
> [% IF pager.total_entries() > 0 -%]
> [% pager.total_entries() -%] pictures found |
> Showing page <b>[% pager.current_page() -%]</b> of [% pager.last_page() -%]
> [% END -%]
> </div>
>
> Works fine so far.
>
> david
>
> --
> David Schmidt | http://www.fm5.at
>
> _______________________________________________
> 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/
>

_______________________________________________
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/


orasnita at gmail

Jan 22, 2009, 7:59 AM

Post #9 of 20 (2984 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

From: "Oliver Charles" <oliver.g.charles [at] googlemail>
>I might as well join in with this :) Here's what we use at work:
>
> [% IF pager %]
> <ul class="paginator">
> <li class="counter">Page [% pager.current_page %] of [%
> pager.last_page %]</li>
> <li><a href="[% c.req.uri_with( page => pager.first_page )
> %]">&laquo;</a></li>
> [% IF pager.previous_page %]
> <li><a href="[% c.req.uri_with( page =>
> pager.previous_page ) %]">&lt;</a></li>
> [% END %]
>
> [.% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3)
> : 1;
> FOREACH page IN [ start .. pager.last_page ] %]
> [% LAST IF loop.count > 6 %]
> <li[% IF pager.current_page == page; ' class="current"'; END
> %]>
> <a href="[% c.req.uri_with( page => page ) %]">[% page
> %]</a>
> </li>
> [% END %]
>
> [% IF pager.next_page %]
> <li><a href="[% c.req.uri_with( page => pager.next_page )
> %]">&gt;</a></li>
> [% END %]
> <li><a href="[% c.req.uri_with( page => pager.last_page )
> %]">&raquo;</a></li>
> </ul>
> [% END %]
>

Can you also provide the CSS classes used by this example?

Thank you.

Octavian


_______________________________________________
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/


oliver.g.charles at googlemail

Jan 22, 2009, 10:27 AM

Post #10 of 20 (2983 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

> Can you also provide the CSS classes used by this example?

Sure, here it is - not particularly amazing though, but I'm no designer :) [1]:

.paginator ul {
margin: 0;
}

.paginator .counter {
margin-right: 20pt;
}

.paginator li {
display: inline;
}

.paginator li a {
padding: 0pt 5pt;
color: #777;
border: 1px solid;
}

.paginator li.current a,
.paginator li a:hover {
color: #000;
}

.paginator li.current a {
background: #FFBA58;
font-weight: bold;
}

-- Ollie

[1]: http://test.musicbrainz.org/search/simple?type=artist&query=catalyst&submit=Search

_______________________________________________
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/


Byron.Young at riverbed

Jan 22, 2009, 10:30 AM

Post #11 of 20 (2972 views)
Permalink
RE: Re: OT: Better TT pager? [In reply to]

Aristotle Pagaltzis wrote on 2008-12-24:

[snip]

> This is also a perfect demonstration of why I say that TT sucks.
> This should by all rights be handled in the template since it’s
> display logic, but writing it in that TT mini-language rather
> than Perl is fugly. And PERL and RAWPERL blocks have their own
> problems. Anyway. Someday I’ll quit yapping and write some code.

Have you tried Mason? It's delicious.

Byron


jester at panix

Jan 23, 2009, 7:00 AM

Post #12 of 20 (2961 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

On Thu, Jan 22, 2009 at 03:48:58PM +0000, Oliver Charles wrote:
> I might as well join in with this :) Here's what we use at work:

[...]

> Though my colleague rightly suggested we subclass Data::Page and
> perform the sliding window in there. This shows first page, previous
> page, the current page surrounded by near-by pages. Seems to do the
> job so far!

I like this quite a bit, more than some of the other solutions
which I tried, and think I'll use this.

One question, from an arithmetically-challenged one: How would
I modify this to allow the user to skip by, say, tens? If you
have a search with 1000 pages, you can only go to the
beginning or end, but getting to the middle would be
unbearably tedious (it would be only slight less tedious
having to do it be tens, but still better).

Jesse Sheidlower

_______________________________________________
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/


oliver.g.charles at googlemail

Jan 23, 2009, 11:31 AM

Post #13 of 20 (2948 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

On 23 Jan 2009, at 15:00, Jesse Sheidlower wrote:
> I like this quite a bit, more than some of the other solutions
> which I tried, and think I'll use this.

Glad you like it :)

> One question, from an arithmetically-challenged one: How would
> I modify this to allow the user to skip by, say, tens? If you
> have a search with 1000 pages, you can only go to the
> beginning or end, but getting to the middle would be
> unbearably tedious (it would be only slight less tedious
> having to do it be tens, but still better).

Well, it really depends on how you want to display the results. But I
guess you'd do some kind of loop, doing (i * 10) to get the multiples
of 10 - the just looping until you exceed total_pages. However, this
is really getting a bit more complex than should be in a template
(arguably, even my template is too complex) - so you should look to
maybe subclass Data::Page to do this for you.
>
>
> Jesse Sheidlower
>
> _______________________________________________
> 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/


_______________________________________________
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/


peter at peknet

Jan 23, 2009, 11:45 AM

Post #14 of 20 (2959 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

Oliver Charles wrote on 01/23/2009 01:31 PM:
>
> On 23 Jan 2009, at 15:00, Jesse Sheidlower wrote:
>> I like this quite a bit, more than some of the other solutions
>> which I tried, and think I'll use this.
>
> Glad you like it :)
>
>> One question, from an arithmetically-challenged one: How would
>> I modify this to allow the user to skip by, say, tens? If you
>> have a search with 1000 pages, you can only go to the
>> beginning or end, but getting to the middle would be
>> unbearably tedious (it would be only slight less tedious
>> having to do it be tens, but still better).
>
> Well, it really depends on how you want to display the results. But I
> guess you'd do some kind of loop, doing (i * 10) to get the multiples of
> 10 - the just looping until you exceed total_pages. However, this is
> really getting a bit more complex than should be in a template
> (arguably, even my template is too complex) - so you should look to
> maybe subclass Data::Page to do this for you.


Data::Pageset or even Data::Pageset::Render

I use Data::Pageset in all my apps. See e.g. SWISH::WebService, which
includes TT snippets implementing XML and HTML pagers.

--
Peter Karman . peter [at] peknet . http://peknet.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/


oliver.g.charles at googlemail

Jan 24, 2009, 9:32 AM

Post #15 of 20 (2940 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

> Data::Pageset or even Data::Pageset::Render

Saddly won't work for me because they same to require knowing
total_entries at the point of creation - I did look at them, but for
reasons I couldn't use them. At least I'm pretty sure that's the
problem I had.

- Ollie

_______________________________________________
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/


zzbbyy at gmail

Feb 28, 2009, 1:44 AM

Post #16 of 20 (2686 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

On Thu, Jan 22, 2009 at 4:48 PM, Oliver Charles
<oliver.g.charles [at] googlemail> wrote:
> I might as well join in with this :) Here's what we use at work:
>
> [% IF pager %]
>    <ul class="paginator">
>        <li class="counter">Page [% pager.current_page %] of [%
> pager.last_page %]</li>
>        <li><a href="[% c.req.uri_with( page => pager.first_page )
> %]">&laquo;</a></li>
>        [% IF pager.previous_page %]
>            <li><a href="[% c.req.uri_with( page =>
> pager.previous_page ) %]">&lt;</a></li>
>        [% END %]
>
>        [.% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3) : 1;
>         FOREACH page IN [ start .. pager.last_page ] %]
>            [% LAST IF loop.count > 6 %]
>            <li[% IF pager.current_page == page; ' class="current"'; END %]>
>                <a href="[% c.req.uri_with( page => page ) %]">[% page %]</a>
>            </li>
>        [% END %]
>
>        [% IF pager.next_page %]
>            <li><a href="[% c.req.uri_with( page => pager.next_page )
> %]">&gt;</a></li>
>        [% END %]
>        <li><a href="[% c.req.uri_with( page => pager.last_page )
> %]">&raquo;</a></li>
>    </ul>
> [% END %]
>
> Though my colleague rightly suggested we subclass Data::Page and
> perform the sliding window in there. This shows first page, previous
> page, the current page surrounded by near-by pages. Seems to do the
> job so far!

Hi,

I've just adopted your example and replaced my pager in InstantCRUD.
I added credit note like that:

=head1 AUTHOR

<Zbigniew Lukasiak> C<< <<zz bb yy @ gmail.com>> >>
Pager adapted from example by Oliver Charles.


I hope you are satisfied.

Cheers,
Zbigniew

PS. Here is the adopted version:

[% IF pager %]
<div class="pager">
<div class="counter">
Page [% pager.current_page %] of [% pager.last_page %]
</div>
<div>
[% IF pager.previous_page %]
<span><a href="[% c.req.uri_with( page => pager.first_page
) %]">&laquo;</a></span>
<span><a href="[% c.req.uri_with( page =>
pager.previous_page ) %]">&lt;</a></span>
[% END %]

[.% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3) : 1;
FOREACH page IN [ start .. pager.last_page ] %]
[% LAST IF loop.count > 6 %]
[% IF pager.current_page == page %]
<span class="current"> [% page %] </span>
[% ELSE %]
<span> <a href="[% c.req.uri_with( page => page )
%]">[% page %]</a> </span>
[% END %]
[% END %]

[% IF pager.next_page %]
<span><a href="[% c.req.uri_with( page => pager.next_page )
%]">&gt;</a></span>
<span><a href="[% c.req.uri_with( page => pager.last_page )
%]">&raquo;</a></span>
[% END %]
</div>
</div>
[% END %]

_______________________________________________
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/


kakimoto at tpg

Jun 20, 2009, 9:37 PM

Post #17 of 20 (2176 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

Hi, there, Oliver and everyone:)

Thanks for your posting:)
Referring to
http://www.mail-archive.com/catalyst [at] lists/msg05232.html, I
adopted the code given into my template and it looks really good but the
hyperlink doesn't have any value. I suppose it's because [%
c.req.uri_with(...) %] is not defined.

1)why is the Catalyst request variable being used instead of the
Catalyst object?
2)how can we get the Catalyst request working properly (ie to be defined)?


thank you :)

K . akimoto




---------------------

Oliver Charles
Thu, 22 Jan 2009 07:50:17 -0800

I might as well join in with this :) Here's what we use at work:

[% IF pager %]
<ul class="paginator">
<li class="counter">Page [% pager.current_page %] of [%
pager.last_page %]</li>
<li><a href="[% c.req.uri_with( page => pager.first_page )
%]">&laquo;</a></li>
[% IF pager.previous_page %]
<li><a href="[% c.req.uri_with( page =>
pager.previous_page ) %]">&lt;</a></li>
[% END %]

[.% start = (pager.current_page - 3) > 0 ? (pager.current_page -
3) : 1;
FOREACH page IN [ start .. pager.last_page ] %]
[% LAST IF loop.count > 6 %]
<li[% IF pager.current_page == page; ' class="current"'; END %]>
<a href="[% c.req.uri_with( page => page ) %]">[% page
%]</a>
</li>
[% END %]

[% IF pager.next_page %]
<li><a href="[% c.req.uri_with( page => pager.next_page )
%]">&gt;</a></li>
[% END %]
<li><a href="[% c.req.uri_with( page => pager.last_page )
%]">&raquo;</a></li>
</ul>
[% END %]

Though my colleague rightly suggested we subclass Data::Page and
perform the sliding window in there. This shows first page, previous
page, the current page surrounded by near-by pages. Seems to do the
job so far!


_______________________________________________
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/


kakimoto at tpg

Jun 20, 2009, 10:16 PM

Post #18 of 20 (2178 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

Hi, all,

Looked at J. Rockway's Catalyst book (page 69) and although there were
some typo errors( ie. c.req was represented as c.res in the final
paragraph ), I got it working in that I just had to make the parameters
to c.req.uri_with as hash references instead of just hashes.

Thanks

K. akimoto



On Sun, Jun 21st, 2009 at 2:37 PM, kakimoto [at] tpg wrote:

> Hi, there, Oliver and everyone:)
>
> Thanks for your posting:)
> Referring to
> http://www.mail-archive.com/catalyst [at] lists/msg05232.html,
> I
> adopted the code given into my template and it looks really good but
> the
> hyperlink doesn't have any value. I suppose it's because [%
> c.req.uri_with(...) %] is not defined.
>
> 1)why is the Catalyst request variable being used instead of the
> Catalyst object?
> 2)how can we get the Catalyst request working properly (ie to be
> defined)?
>
>
> thank you :)
>
> K . akimoto
>
>
>
>
> ---------------------
>
> Oliver Charles
> Thu, 22 Jan 2009 07:50:17 -0800
>
> I might as well join in with this :) Here's what we use at work:
>
> [% IF pager %]
> <ul class="paginator">
> <li class="counter">Page [% pager.current_page %] of [%
> pager.last_page %]</li>
> <li><a href="[% c.req.uri_with( page => pager.first_page )
> %]">&laquo;</a></li>
> [% IF pager.previous_page %]
> <li><a href="[% c.req.uri_with( page =>
> pager.previous_page ) %]">&lt;</a></li>
> [% END %]
>
> [.% start = (pager.current_page - 3) > 0 ? (pager.current_page
> -
> 3) : 1;
> FOREACH page IN [ start .. pager.last_page ] %]
> [% LAST IF loop.count > 6 %]
> <li[% IF pager.current_page == page; ' class="current"';
> END %]>
> <a href="[% c.req.uri_with( page => page ) %]">[%
> page
> %]</a>
> </li>
> [% END %]
>
> [% IF pager.next_page %]
> <li><a href="[% c.req.uri_with( page => pager.next_page
> )
> %]">&gt;</a></li>
> [% END %]
> <li><a href="[% c.req.uri_with( page => pager.last_page )
> %]">&raquo;</a></li>
> </ul>
> [% END %]
>
> Though my colleague rightly suggested we subclass Data::Page and
> perform the sliding window in there. This shows first page, previous
> page, the current page surrounded by near-by pages. Seems to do the
> job so far!
>
>
> _______________________________________________
> 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/
>
>
>




_______________________________________________
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/


fernan.aguero at gmail

Jun 21, 2009, 7:18 AM

Post #19 of 20 (2172 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

On Sun, Jun 21, 2009 at 1:37 AM, <kakimoto [at] tpg> wrote:
>
> Hi, there, Oliver and everyone:)
>
>  Thanks for your posting:)
>  Referring to
> http://www.mail-archive.com/catalyst [at] lists/msg05232.html, I
> adopted the code given into my template and it looks really good but the
> hyperlink doesn't have any value. I suppose it's because [%
> c.req.uri_with(...) %] is not defined.
>
> 1)why is the Catalyst request variable being used instead of the
> Catalyst object?

K,

this may change depending on your configuration of the TT view. In my
case it's not 'c' but 'Catalyst', as in

[% Catalyst.req.uri_with() -%]

> 2)how can we get the Catalyst request working properly (ie to be defined)?

You should look into your lib/yourapp/View/TT.pm file for
CATALYST_VAR. This sets the name of the variable that contains the
catalyst context object in your templates. This is what mine looks
like:

package portfolio::View::TT;

use strict;
use base 'Catalyst::View::TT';

__PACKAGE__->config({
CATALYST_VAR => 'Catalyst',
INCLUDE_PATH => [
portfolio->path_to( 'root', 'src' ),
portfolio->path_to( 'root', 'lib' )
],
PRE_PROCESS => 'config/main',
WRAPPER => 'site/wrapper',
ERROR => 'error.tt2',
TIMER => 0,
DEBUG => 'vars',
});


> thank you :)
>
>  K . akimoto

HTH. Cheers,

--
fernan

_______________________________________________
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/


kakimoto at tpg

Jun 21, 2009, 3:53 PM

Post #20 of 20 (2157 views)
Permalink
Re: Re: OT: Better TT pager? [In reply to]

helllo, there, Fernan and everyone :)

good morning!


> this may change depending on your configuration of the TT view. In
> my
> case it's not 'c' but 'Catalyst', as in
>
> [% Catalyst.req.uri_with() -%]
>

yes, i know that we can either use [% c %] or [% Catalyst %]. My actual
question is that why are we using the request object in the view ?
Anyway , sorted it out.
All good. thank you:)


_______________________________________________
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/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.