Date: Wed, 20 Jul 2005 11:19:50 -0500 (CDT)
From: Gilles Detillieux <grdetil@scrc.umanitoba.ca>
To: Jose Ortiz <jose@calcugator.com>
Cc: htdig-dev@lists.sourceforge.net
Subject: [htdig-dev] Re: Patch for bug #1236435

On July 13, Jose Ortiz wrote:
> Hi,
> 
> Regarding bug #1236435, here is a patch for htsearch/Display.cc.
> 
> The patch is similar to this one:
> http://sourceforge.net/mailarchive/forum.php?thread_id=1377415&forum_id=2688
> 
> The patch I'm attaching has these features:
> 
> 1. It provides a Google-style paging. Say the current page is 9,
> maximum_page_buttons
> is 10 and the number of pages matching the search is bigger than 30, we
> get this
> for PAGELIST:
> 
> [prev] 4 5 6 7 8 9 10 11 12 13 [next]
> 
> The current page is centered if possible.
> 
> 2. If an insufficient number of pictures is provided, it mixes up
> graphics and text:
> 
> [pic prev] [pic 4] [pic 5] [pic 6] [pic 7] [pic 8] [pic 9] [pic 10] 11
> 12 13 [pic next]
> 
> To install the patch, update htsearch/Display.cc, compile the code and copy
> % cp htsearch/.lig/htsearch to your cgi-bin directory.
> 
> Jose

Thanks, Jose.  Sorry for the delay in responding.  Looking over your
code, I do think it's an improvement on Adam Ness's patch.  By the way,
your patch was reversed.  You should use "diff -up oldsource newsource"
to get a forward patch.  Not a problem, though.  Here's a reposting of
it with the fix.  It can be applied to the htdig-3.2.0b6 source using
"patch -p0 < this-message-file".

As it turns out, this seems all to be a moot point.  Looking at the CVS
source tree, I see that Lachalan already committed a third variation
on this theme over a year ago (just after 3.2.0b6 was released).
His is a bit more elaborate, in that it will make all page links text
if there aren't enough images for all of them.  In his ChangeLog entry,
he cites 3 RFE numbers (#601177, #600959, #405679) but no bug entries.
We can probably close bug #1236435.


--- htsearch/Display.cc.back	2005-07-12 23:11:39.000000000 -0400
+++ htsearch/Display.cc	2005-07-13 20:10:25.000000000 -0400
@@ -694,6 +694,38 @@ Display::setVariables(int pageNumber, Li
     //
     if (nPages > 1)
     {
+	// Assume number of page links is equal to maximum_page_buttons
+	// For example, if pageNumber=9, maximum_page_buttons=10,
+	// and nPages>=13, we get:
+	//
+	// [prev] 4 5 6 7 8 9 10 11 12 13 [next]
+
+	int nPageButtons = config->Value("maximum_page_buttons", 10);
+
+	// Initialize indexes of pages links
+	int first_page_index = 1;
+	int last_page_index  = nPages;
+
+	if (nPages > nPageButtons) 
+	{
+	   // Try to center the current page
+	   int links_on_the_left = nPageButtons/2;
+	   first_page_index = pageNumber - links_on_the_left;
+	   last_page_index  = first_page_index + nPageButtons - 1;
+
+	   // Adjust if required
+	   if (first_page_index < 1) 
+	   {
+	      first_page_index = 1;
+	      last_page_index  = nPageButtons;
+	   }
+	   else if (last_page_index > nPages )
+	   {
+	      last_page_index  = nPages;
+	      first_page_index = nPages - nPageButtons + 1;
+	   }
+	}
+
 	if (pageNumber > 1)
 	{
 	    str = new String("<a href=\"");
@@ -725,9 +757,8 @@ Display::setVariables(int pageNumber, Li
 	QuotedStringList	pnt(config->Find("page_number_text"), " \t\r\n");
 	QuotedStringList	npnt(config->Find("no_page_number_text"), " \t\r\n");
 	QuotedStringList	sep(config->Find("page_number_separator"), " \t\r\n");
-	if (nPages > config->Value("maximum_page_buttons", 10))
-	    nPages = config->Value("maximum_page_buttons", 10);
-	for (i = 1; i <= nPages; i++)
+
+	for (i = first_page_index; i <= last_page_index; i++)
 	{
 	    if (i == pageNumber)
 	    {


-- 
Gilles R. Detillieux              E-mail: <grdetil@scrc.umanitoba.ca>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/
Dept. Physiology, U. of Manitoba  Winnipeg, MB  R3E 3J7  (Canada)
