On 02/12/2011 01:34 PM, Lukas Fleischer wrote:
Wow, I finally found some time to rebase and review all those patches...

0001. 00e497a pkg_search_results: rewrite of page navigation

I have to admit that I don't really like that way of pagination. It just
feels odd and counter-intuitive imho. Right now, we have "First",
"Prev", "Next" and "Last" buttons as well as pages adjacent to the
current one. If you want to find a package that you remember to start
with the letter "r" and to contain the string "and" somewhere in the
package description, typing that into the search criteria and browsing
all results is not the right way to do it. The proper way to allow users
to search for such packages is to provide more powerful search criteria,
which is something we're already working on. Also, if we'd want to
implement something like that, I'd prefer some kind of binary search.
That might, in fact, be interesting :)

Moving parts of the paging stuff to "pkgfuncts.inc" makes sense tho.
I'll probably extract this from the patch.

I rewrote the pagination a second time, this time without changing the
behavoir. Probably the world isn't ready yet for a commit that
turns searching into something awesome (tm).
(Children would have known what "logarithmic scaling" means even before
doing their first polynomial division!)

On the search criteria: it would be great to have regexps!
Mysql even has support for that:
  SELECT * FROM foo WHERE foo REGEXP '^java';

0002. b65a5a3 pkg_search_results: increase size of links in
               page-navigation

I'm not sure about this. I've never heard any gripes about that links
being too small. Is there any feature request concerning this?

No. But this only grews one-digit-links to be of the size of two-digit-
links, so imo the usability gain outweights the space consumption.
I merged this change into the patch mentioned above.

0003. df02d42 pkg_search_results: replace blind-table with
               floating div's

Basically sounds like a good idea. I'll look into that!

0004. 76a874a Right-to-left written languages now supported

Basically looks ok, except that you revert some previous bug fixes.
Also, where's that "css/languages.css" that you link to in the new
header template?

The last two patches probably need a lot of updating, I will do that
next. I attached languages.css (forgot to git-add it)

Thanks for your contributions!

Thanks for reviewing them :-P

--
freenode/pyropeter                                         ETAOIN SHRDLU
>From 541c18f86d970051d837e9dd75e1122292d1fd4f Mon Sep 17 00:00:00 2001
From: PyroPeter <abi1...@googlemail.com>
Date: Mon, 14 Feb 2011 20:58:42 +0100
Subject: [PATCH] pkg_search_results: rewrite of pagination

* Most of the PHP-code was moved to pkgfuncs.php to keep the template simple.

Signed-off-by: PyroPeter <abi1...@googlemail.com>
---
 web/html/css/arch.css               |   17 +++++---
 web/lib/pkgfuncs.inc                |   28 +++++++++++++
 web/template/pkg_search_results.php |   77 ++++++----------------------------
 3 files changed, 53 insertions(+), 69 deletions(-)

diff --git a/web/html/css/arch.css b/web/html/css/arch.css
index c3ed3aa..203d9da 100644
--- a/web/html/css/arch.css
+++ b/web/html/css/arch.css
@@ -328,19 +328,24 @@ blockquote.code {
        text-decoration: none;
 }
 
-#pages { margin: 5px; }
-#pages .page_num {
+.pageNav {
+  margin:5px 0;
+}
+.pageNav .page_num {
        border: 1px solid #ddd;
        padding: 2px;
        color: #0771a6;
 }
-
-#pages .page_num:hover {
+.pageNav * {
+  display:inline-block;
+  text-align:center;
+  min-width:3ex;
+}
+.pageNav .page_num:hover {
        border: 1px solid #8faecd;
        color: #333;
 }
-
-#pages #page_sel {
+.pageNav .page_sel {
        border: 1px solid #8faecd;
        padding: 2px;
        color: #333;
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index 2f69321..0420054 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -559,6 +559,34 @@ function pkg_search_page($SID="") {
 
 
        if ($total > 1 || $total == 0) {
+               # calculation of pagination links
+               $per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 25;
+               $current = ceil($first / $per_page);
+               $pages = ceil($total / $per_page);
+               $templ_pages = array();
+
+               if ($current - 1 > 1)
+                       $templ_pages[__('First')] = 0;
+
+               if ($current > 1)
+                       $templ_pages[__('Previous')] = ($current - 2) * 
$per_page;
+
+               if ($current - 5 > 1)
+                       $templ_pages[] = "ellipsis";
+
+               for ($i = max($current - 5, 1) ; $i <= min($pages, $current + 
5) ; $i++) {
+                       $templ_pages[$i] = ($i - 1) * $per_page;
+               }
+
+               if ($current + 5 < $pages)
+                       $templ_pages[] = "ellipsis";
+
+               if ($current < $pages)
+                       $templ_pages[__('Next')] = $current * $per_page;
+
+               if ($current + 1 < $pages)
+                       $templ_pages[__('Last')] = ($pages - 1) * $per_page;
+
                include('pkg_search_form.php');
                include('pkg_search_results.php');
        }
diff --git a/web/template/pkg_search_results.php 
b/web/template/pkg_search_results.php
index 4830ca8..57d574c 100644
--- a/web/template/pkg_search_results.php
+++ b/web/template/pkg_search_results.php
@@ -113,73 +113,24 @@ for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
                </td>
 
                <td align='right'>
-               <span class='f4'><span class='blue'>
-               <?php print __("Showing results %s - %s of %s", $first, $last, 
$total) ?>
-               </span></span>
-               <br />
-
-               <div id="pages">
-               <?php
-                       if ($_GET['O'] > 0):
-                               $O = $_GET['O'] - $_GET['PP'];
-
-                               if ($_GET['O'] < $_GET['PP']) {
-                                       $O = 0;
-                               }
-               ?>
-                       <a class="page_num" href="packages.php?<?php print 
mkurl("O=0") ?>"><?php echo __('First') ?></a>
-                       <a class="page_num" href="packages.php?<?php print 
mkurl("O=$O") ?>"><?php echo __('Previous') ?></a>
-               <?php   endif; ?>
-
-                       <?php
-                       if ($_GET['PP'] > 0) {
-                               $pages = ceil($total / $_GET['PP']);
-                       }
-
-                       if ($pages > 1) {
-                               if ($_GET['O'] > 0) {
-                                       $currentpage = ceil(($_GET['O'] + 1) / 
$_GET['PP']);
-                               }
-                               else {
-                                       $currentpage = 1;
-                               }
-
-                               $morepages = $currentpage + 5;
-
-                               print (($currentpage-5) > 1) ? '...' : '';
-
-                               # Display links for more search results.
-                               for ($i = ($currentpage - 5); $i <= $morepages 
&& $i <= $pages; $i++) {
-                                       if ($i < 1) {
-                                               $i = 1;
-                                       }
-
-                                       $pagestart = ($i - 1) * $_GET['PP'];
-
-                                       if ($i <> $currentpage) :
-                                       ?>
-                               <a class="page_num" href="packages.php?<?php 
print mkurl('O=' . ($pagestart)) ?>"><?php echo $i ?></a>
-                                       <?php else : echo "<span 
id=\"page_sel\">$i</span>";
-                                       endif;
-                               }
-
-                               print ($pages > $morepages) ? '...' : '';
-                               ?>
-
-                       <?php if ($total - $_GET['PP'] - $_GET['O'] > 0): ?>
-                               <a class="page_num" href='packages.php?<?php 
print mkurl('O=' . ($_GET['O'] + $_GET['PP'])) ?>'><?php echo __('Next') ?></a>
-                               <a class="page_num" href='packages.php?<?php 
print mkurl('O=' . ($total - $_GET['PP'])) ?>'><?php echo __('Last') ?></a>
-                       <?php endif; ?>
-
+                       <div class="pageStats f4 blue">
+                               <?php print __("Showing results %s - %s of %s", 
$first, $last, $total) ?>
+                       </div>
+                       <div class="pageNav">
+                               <?php foreach($templ_pages as $pagenr => 
$pagestart) { ?>
+                                       <?php if ($pagestart === "ellipsis") { 
?>
+                                               ...
+                                       <?php } else if ($pagestart + 1 == 
$first) { ?>
+                                               <span class="page_sel"><?php 
echo $pagenr ?></span>
+                                       <?php } else { ?>
+                                               <a class="page_num" 
href="packages.php?<?php print mkurl('O=' . (       $pagestart)) ?>"><?php echo 
$pagenr ?></a>
+                                       <?php } ?>
+                               <?php } ?>
                        </div>
-
                </td>
        </tr>
 
-<?php
-                       }
-}
-?>
+<?php } ?>
        </table>
 </div>
 </form>
-- 
1.7.4.1

/**
 * 
 * Language-specific declarations
 * 
 * (e.g. right-to-left texts for Hebrew)
 * 
 * */


/**
 *                 RIGHT - TO - LEFT
 * 
 * Too add a language, just add it's language code to all
 * :lang()-pseudo-classes, delimited by a hyphen ("-").
 * */

body:lang(he) {
  direction:rtl;
}
th:lang(he) {
  text-align:right;
}
#lang_sub:lang(he) {
  text-align:left;
}
.pkgSearchResultsFooter:lang(he) .legendAndActions {
  float:right;
}
.pkgSearchResultsFooter:lang(he) .pageLinks {
  float:left;
}
div.version {
  text-align:left;
}

Reply via email to