From c0206e61f59cab1e542dff6e45ea43d88522632f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 20 Mar 2010 21:48:09 -0700 Subject: [PATCH] Fix more thread search pagination issues. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Post/Thread.pm | 3 ++- lib/WebGUI/Asset/Wobject/Collaboration.pm | 2 +- t/Asset/Post/Thread.t | 7 +++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2c7053f83..351c58b1b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -6,6 +6,7 @@ - fixed #11476: Missing override in Page Layout shortcut - fixed: Unable to add threads with permission to edit CS but not in post group - fixed #11478: Overzealous removal of double slashes in FilePump macro + - fixed thread pagination on search results, off by 1 error and modal direction 7.9.0 - added #11383: AJAX username checks at registration (Luke Robinson / Orchard Solutions) diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 9181df243..d87d2bc3d 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -19,6 +19,7 @@ use WebGUI::International; use WebGUI::Paginator; use WebGUI::SQL; use WebGUI::Utility; +use POSIX qw/ceil/; our @ISA = qw(WebGUI::Asset::Post); @@ -383,7 +384,7 @@ EOSQL } $sth->finish; return $self->get('url') if !$found; - my $page = int($place/$page_size) + 1; + my $page = ceil($place/$page_size); my $page_frag = 'pn='.$page.';sortBy=lineage;sortOrder=desc'; $url = $session->url->append($cs->get('url'), $page_frag); return $url; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index da3606598..3dbb64f45 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1173,7 +1173,7 @@ sub getThreadsPaginator { $self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy")); $self->session->scratch->set($scratchSortOrder, $sortOrder); } - elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") { + elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave" && ! $self->session->form->process('sortOrder')) { if ($sortOrder eq "asc") { $sortOrder = "desc"; } diff --git a/t/Asset/Post/Thread.t b/t/Asset/Post/Thread.t index 00459839e..b89ae98ec 100644 --- a/t/Asset/Post/Thread.t +++ b/t/Asset/Post/Thread.t @@ -13,7 +13,7 @@ use strict; use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 12; # increment this value for each test you create +use Test::More tests => 15; # increment this value for each test you create use Test::MockObject::Extends; use Test::Exception; use WebGUI::Asset::Wobject::Collaboration; @@ -88,8 +88,11 @@ $versionTag2->commit; my $csUrl = $collab->get('url'); like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of the parent CS with no gateway'; -like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, 'and has the right page number'; +like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, '... and has the right page number'; like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1;sortBy=lineage;sortOrder=desc/, 'and has the right sort parameters'; +like $newThreads[-2]->getCSLinkUrl, qr/\?pn=1/, '... second to last has right page number'; +like $newThreads[-3]->getCSLinkUrl, qr/\?pn=1/, '... and third to last'; +like $newThreads[-4]->getCSLinkUrl, qr/\?pn=2/, '... and fourth to last'; $thread->restore(); like $thread->getCSLinkUrl, qr/\?pn=6/, 'checking 2nd thread on another page';