Skip to content

Commit

Permalink
Item11050: delay evaluating the pager UI - there are some times when …
Browse files Browse the repository at this point in the history
…we can know there are no pages left

git-svn-id: http://svn.foswiki.org/trunk@15996 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Nov 12, 2012
1 parent 164202e commit f1075a5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 44 deletions.
23 changes: 20 additions & 3 deletions core/lib/Foswiki/Iterator/PagerIterator.pm
Expand Up @@ -66,15 +66,32 @@ sub showpage {
}

#lie - give the requested pagesize - it might be less, if we're at the end of the list
#and we can never know if there is just one more, as the underlying iterator may have only asked for pagesize reaults
#so it can't tell us
sub numberOfTopics {
my $this = shift;
return $this->{pagesize};
if ( !$this->hasNext() && ( $this->{pager_result_count} > 0 ) ) {
return $this->{pagesize} - $this->{pager_result_count};
}
else {
#we're still iterating, so we don't know the page size
return $this->{pagesize};
}
}

#another lie - this hopes that the inner iterator knows the number, and isn't just guessing.
sub numberOfPages {
my $this = shift;
return int( $this->{iterator}->numberOfTopics() / $this->{pagesize} ) + 1;
if ( !$this->hasNext() && ( $this->{pager_result_count} > 0 ) ) {

#if we've exhausted the undelying iterator, and have not got pagesize elements, then we know there are no more.
return $this->showpage();
}
else {
#we're still iterating, so we don't know the page size
return
int( $this->{iterator}->numberOfTopics() / $this->{pagesize} ) + 1;
}
}

sub nextWeb {
Expand Down Expand Up @@ -194,7 +211,7 @@ sub reset {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
102 changes: 61 additions & 41 deletions core/lib/Foswiki/Search.pm
Expand Up @@ -601,6 +601,9 @@ sub formatResults {
my %pager_formatting;
if ( $params->{paging_on} ) #TODO: if can skip()
{
#TODO: this is a dangerous assumption that should be abstracted
ASSERT( $infoCache->isa('Foswiki::Iterator::PagerIterator') ) if DEBUG;

$limit = $infoCache->pagesize();

my $paging_ID = $params->{pager_urlparam_id};
Expand All @@ -626,54 +629,71 @@ sub formatResults {

$session->templates->readTemplate('searchformat');

my $previouspagebutton = '';
my $previouspageurl = '';
if ( $previousidx >= 1 ) {
$new_params{$paging_ID} = $previousidx;
$previouspageurl =
Foswiki::Func::getScriptUrl( $baseWeb, $baseTopic, 'view',
%new_params );
$previouspagebutton =
$session->templates->expandTemplate('SEARCH:pager_previous');
}
my $nextpagebutton = '';
my $nextpageurl = '';
if ( $nextidx <= $numberofpages ) {
$new_params{$paging_ID} = $nextidx;
$nextpageurl =
Foswiki::Func::getScriptUrl( $baseWeb, $baseTopic, 'view',
%new_params );
$nextpagebutton =
$session->templates->expandTemplate('SEARCH:pager_next');
}
%pager_formatting = (
'previouspage' => sub { return $previousidx },
'currentpage' => sub { return $showpage },
'nextpage' => sub { return $showpage + 1 },
'numberofpages' => sub { return $numberofpages },
'numberofpages' => sub { return $infoCache->numberOfPages() },
'pagesize' => sub { return $infoCache->pagesize() },
'previousurl' => sub { return $previouspageurl },
'nexturl' => sub { return $nextpageurl },
'sep' => sub { return $sep; }
);

$previouspagebutton =
$this->formatCommon( $previouspagebutton, \%pager_formatting );
$pager_formatting{'previousbutton'} =
sub { return $previouspagebutton };

$nextpagebutton =
$this->formatCommon( $nextpagebutton, \%pager_formatting );
$pager_formatting{'nextbutton'} = sub { return $nextpagebutton };

my $pager_control = '';
if ( $numberofpages > 1 ) {
$pager_control = $params->{pagerformat}
|| $session->templates->expandTemplate('SEARCH:pager');
$pager_control =
$this->formatCommon( $pager_control, \%pager_formatting );
}
$pager_formatting{'pager'} = sub { return $pager_control; };
$pager_formatting{'previousurl'} = sub {
my $previouspageurl = '';
if ( $previousidx >= 1 ) {
$new_params{$paging_ID} = $previousidx;
$previouspageurl =
Foswiki::Func::getScriptUrl( $baseWeb, $baseTopic, 'view',
%new_params );
}
return $previouspageurl;
};

$pager_formatting{'previousbutton'} = sub {
my $previouspagebutton = '';
if ( $previousidx >= 1 ) {
$new_params{$paging_ID} = $previousidx;
$previouspagebutton =
$session->templates->expandTemplate('SEARCH:pager_previous');
}
$previouspagebutton =
$this->formatCommon( $previouspagebutton, \%pager_formatting );
return $previouspagebutton;
};

$pager_formatting{'nexturl'} = sub {
my $nextpageurl = '';
if ( $nextidx <= $infoCache->numberOfPages() ) {
$new_params{$paging_ID} = $nextidx;
$nextpageurl =
Foswiki::Func::getScriptUrl( $baseWeb, $baseTopic, 'view',
%new_params );
}
return $nextpageurl;
};

$pager_formatting{'nextbutton'} = sub {
my $nextpagebutton = '';
if ( $nextidx <= $infoCache->numberOfPages() ) {
$new_params{$paging_ID} = $nextidx;
$nextpagebutton =
$session->templates->expandTemplate('SEARCH:pager_next');
}
$nextpagebutton =
$this->formatCommon( $nextpagebutton, \%pager_formatting );
return $nextpagebutton;
};

$pager_formatting{'pager'} = sub {
my $pager_control = '';
if ( $infoCache->numberOfPages() > 1 ) {
$pager_control = $params->{pagerformat}
|| $session->templates->expandTemplate('SEARCH:pager');
$pager_control =
$this->formatCommon( $pager_control, \%pager_formatting );
}
return $pager_control;
};
}

#TODO: multiple is an attribute of the ResultSet
Expand Down Expand Up @@ -1364,7 +1384,7 @@ sub _collate_to_list {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down

0 comments on commit f1075a5

Please sign in to comment.