added page range to paginator variables

This commit is contained in:
Doug Bell 2008-09-03 21:56:43 +00:00
parent a0a02e8d6e
commit 01cbbf2e60
4 changed files with 51 additions and 14 deletions

View file

@ -17,6 +17,7 @@
- fixed: PurgeOldInboxMessages just didn't work
- fixed: Unable to delete data form entries
- fixed: Select All checkbox in Asset Manager has returned
- added: Page range (start-finish) to available paginator text
7.5.22
- fixed: Layout template now gets prepared correctly

View file

@ -34,15 +34,15 @@ our $HELP = {
{ 'name' => 'pagination.pageCount.isMultiple' },
{ 'name' => 'pagination.pageList', },
{ 'name' => 'pagination.pageLoop',
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' } ]
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ]
},
{ 'name' => 'pagination.pageList.upTo20' },
{ 'name' => 'pagination.pageLoop.upTo20',
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' } ]
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ]
},
{ 'name' => 'pagination.pageList.upTo10' },
{ 'name' => 'pagination.pageLoop.upTo10',
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' } ]
'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ]
}
],
fields => [],

View file

@ -470,10 +470,10 @@ sub getPageLinks {
my @pages_loop;
for (my $i=0; $i<$self->getNumberOfPages; $i++) {
my $altTag;
my $first = $i * $self->{_rpp};
my $last = (($i+1) * $self->{_rpp})-1;
$last = $self->{_totalRows} - 1 if $last >= $self->{_totalRows};
if ($self->{abKey}) {
my $first = $i * $self->{_rpp};
my $last = (($i+1) * $self->{_rpp})-1;
$last = $self->{_totalRows} - 1 if $last >= $self->{_totalRows};
if ($self->{abInitialOnly}) {
$altTag = ' title="'.substr($self->{_rowRef}[$first]->{$self->{abKey}},0,1).'-'.substr($self->{_rowRef}[$last]->{$self->{abKey}},0,1).'"';
} else {
@ -481,11 +481,19 @@ sub getPageLinks {
}
}
if ($i+1 == $pn) {
push(@pages,($i+1));
push(@pages_loop,{ "pagination.url" => '', "pagination.text" => $i+1});
push @pages, $i+1;
push @pages_loop, {
"pagination.url" => '',
"pagination.text" => $i+1,
'pagination.range' => ($first+1) . "-" . ($last+1),
};
} else {
push(@pages,'<span><a href="'.$self->session->url->append($self->{_url},($self->{_formVar}.'='.($i+1))).'"'.$altTag.'>'.($i+1).'</a></span>');
push(@pages_loop,{ "pagination.url" => $self->session->url->append($self->{_url},($self->{_formVar}.'='.($i+1))), "pagination.text" => $i+1});
push @pages, '<span><a href="'.$self->session->url->append($self->{_url},($self->{_formVar}.'='.($i+1))).'"'.$altTag.'>'.($i+1).'</a></span>';
push @pages_loop, {
"pagination.url" => $self->session->url->append($self->{_url},($self->{_formVar}.'='.($i+1))),
"pagination.text" => $i+1,
'pagination.range' => ($first+1) . "-" . ($last+1),
};
}
}
if ($limit) {

View file

@ -27,12 +27,13 @@ my $startingRowNum = 0;
my $endingRowNum = 99;
my @paginatingData = ($startingRowNum..$endingRowNum);
plan tests => 13; # increment this value for each test you create
plan tests => 15; # increment this value for each test you create
my $rowCount = $endingRowNum - $startingRowNum + 1;
my $NumberOfPages = ceil($rowCount/25); ##Default page size=25
my $rowCount = $endingRowNum - $startingRowNum + 1;
my $NumberOfPages = ceil($rowCount/25); ##Default page size=25
my $url = "/home";
my $p = WebGUI::Paginator->new($session, '/home');
my $p = WebGUI::Paginator->new($session, $url);
isa_ok($p, 'WebGUI::Paginator', 'paginator object returned');
@ -46,6 +47,19 @@ cmp_bag([0..24], $p->getPageData(1), 'page 1 data correct');
cmp_bag([25..49], $p->getPageData(2), 'page 2 data correct');
cmp_bag([ ], $p->getPageData(5), 'page 5 data correct');
# Test getPageLinks
cmp_deeply(
[
map { +{
'pagination.text' => ( $_ + 1 ),
'pagination.range' => ( 25 * $_ + 1 ) . "-" . ( $_ * 25 + 25 <= $endingRowNum + 1 ? $_ * 25 + 25 : $endingRowNum + 1 ), # First row number - Last row number
'pagination.url' => ( $_ != 0 ? $url . '?pn=' . ( $_ + 1 ) : '' ), # Current page has no URL
} } (0..$NumberOfPages-1)
],
($p->getPageLinks)[0],
'page links correct',
);
$startingRowNum = 0;
$endingRowNum = 100;
@paginatingData = ($startingRowNum..$endingRowNum);
@ -68,3 +82,17 @@ cmp_bag([100 ], $p->getPageData(5), '(101) page 5 data correct');
is('100', $p->getPage(5), '(101) page 5 stringification okay');
is($p->getPageNumber, 1, 'Default page number is 1'); ##Additional page numbers are specified at instantiation
# Test getPageLinks
cmp_deeply(
($p->getPageLinks)[0],
[
map { +{
'pagination.text' => ( $_ + 1 ),
'pagination.range' => ( 25 * $_ + 1 ) . "-" . ( $_ * 25 + 25 <= $endingRowNum + 1 ? $_ * 25 + 25 : $endingRowNum + 1 ), # First row number - Last row number
'pagination.url' => ( $_ != 0 ? $url . '?pn=' . ( $_ + 1 ) : '' ), # Current page has no URL
} } (0..$NumberOfPages-1)
],
'page links correct',
);