RFE #925817, better page selector with flexible jumping/pagination controls

This commit is contained in:
Garvin Hicking
2004-11-02 15:47:19 +00:00
parent bb4bc45976
commit 2a3da9f8f6
4 changed files with 116 additions and 42 deletions

View File

@@ -7,6 +7,10 @@ $Source$
2004-11-09 Garvin Hicking 2004-11-09 Garvin Hicking
* libraries/display_tbl.lib.php, libraries/common.lib.php,
browse_foreigners.php: RFE #925817 - Abstracted page selector to
its own function, now create sloped pagination to easily jump
to any wanted page.
* read_dump.php: RFE #1053039, show filename of uploaded SQL file * read_dump.php: RFE #1053039, show filename of uploaded SQL file
* sql.php, tbl_indexes.php, libraries/tbl_indexes.lib.php, * sql.php, tbl_indexes.php, libraries/tbl_indexes.lib.php,
lang/*: Added checks for common problems with table indices. lang/*: Added checks for common problems with table indices.

View File

@@ -112,25 +112,16 @@ $pageNow = @floor($pos / $session_max_rows) + 1;
$nbTotalPage = @ceil($the_total / $session_max_rows); $nbTotalPage = @ceil($the_total / $session_max_rows);
if ($the_total > $per_page) { if ($the_total > $per_page) {
$gotopage = '<br />' . $GLOBALS['strPageNumber'] $gotopage = PMA_pageselector(
. '<select name="goToPage" onchange="goToUrl(this, \'browse_foreigners.php?field=' . urlencode($field) . '&amp;' . PMA_generate_common_url($db, $table) . $pk_uri . '&amp;fieldkey=' . (isset($fieldkey) ? $fieldkey : '') . '&amp;\');">'; 'browse_foreigners.php?field=' . urlencode($field) .
if ($nbTotalPage < 200) { '&amp;' . PMA_generate_common_url($db, $table)
$firstPage = 1; . $pk_uri .
$lastPage = $nbTotalPage; '&amp;fieldkey=' . (isset($fieldkey) ? $fieldkey : '') .
} else { '&amp;',
$range = 20; $session_max_rows,
$firstPage = ($pageNow - $range < 1 ? 1 : $pageNow - $range); $pageNow,
$lastPage = ($pageNow + $range > $nbTotalPage ? $nbTotalPage : $pageNow + $range); $nbTotalPage
} );
for ($i=$firstPage; $i<=$lastPage; $i++){
if ($i == $pageNow) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$gotopage .= ' <option ' . $selected . ' value="' . (($i - 1) * $session_max_rows) . '">' . $i . '</option>' . "\n";
}
} else { } else {
$gotopage = ''; $gotopage = '';
} }

View File

@@ -2335,6 +2335,94 @@ if (typeof(document.getElementById) != 'undefined'
} }
} // end function } // end function
/**
* Generate a pagination selector for browsing resultsets
*
* @param string URL for the JavaScript
* @param string Number of rows in the pagination set
* @param string current page number
* @param string number of total pages
* @param string If the number of pages is lower than this
* variable, no pages will be ommitted in
* pagination
* @param string How many rows at the beginning should always
* be shown?
* @param string How many rows at the end should always
* be shown?
* @param string Percentage of calculation page offsets to
* hop to a next page
* @param string Near the current page, how many pages should
* be considered "nearby" and displayed as
* well?
*
* @access public
* @author Garvin Hicking (pma@supergarv.de)
*/
function PMA_pageselector($url, $rows, $pageNow = 1, $nbTotalPage = 1, $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20, $range = 10) {
$gotopage = '<br />' . $GLOBALS['strPageNumber']
. '<select name="goToPage" onchange="goToUrl(this, \'' . $url . '\');">' . "\n";
if ($nbTotalPage < $showAll) {
$pages = range(1, $nbTotalPage);
} else {
$pages = array();
// Always show first X pages
for ($i = 1; $i <= $sliceStart; $i++) {
$pages[] = $i;
}
// Always show last X pages
for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++) {
$pages[] = $i;
}
// garvin: Based on the number of results we add the specified $percent percentate to each page number,
// so that we have a representing page number every now and then to immideately jump to specific pages.
// As soon as we get near our currently chosen page ($pageNow - $range), every page number will be
// shown.
$i = $sliceStart;
$x = $nbTotalPage - $sliceEnd;
$met_boundary = false;
while($i <= $x) {
if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range)) {
// If our pageselector comes near the current page, we use 1 counter increments
$i++;
$met_boundary = true;
} else {
// We add the percentate increment to our current page to hop to the next one in range
$i = $i + floor($nbTotalPage / $percent);
// Make sure that we do not cross our boundaries.
if ($i > ($pageNow - $range) && !$met_boundary) {
$i = $pageNow - $range;
}
}
if ($i > 0 && $i <= $x) {
$pages[] = $i;
}
}
// Since because of ellipsing of the current page some numbers may be double,
// we unify our array:
sort($pages);
$pages = array_unique($pages);
}
foreach($pages AS $i) {
if ($i == $pageNow) {
$selected = 'selected="selected" style="font-weight: bold"';
} else {
$selected = '';
}
$gotopage .= ' <option ' . $selected . ' value="' . (($i - 1) * $rows) . '">' . $i . '</option>' . "\n";
}
$gotopage .= ' </select>';
return $gotopage;
}
} // end if: minimal common.lib needed? } // end if: minimal common.lib needed?
?> ?>

View File

@@ -349,29 +349,20 @@ function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
<td> <td>
<?php //<form> for keep the form alignment of button < and << ?> <?php //<form> for keep the form alignment of button < and << ?>
<form> <form>
<?php echo $GLOBALS['strPageNumber']; ?> <?php echo PMA_pageselector(
<select name="goToPage" onchange="goToUrl(this, '<?php echo "sql.php?sql_query=".$encoded_query."&amp;session_max_rows=".$session_max_rows."&amp;disp_direction=".$disp_direction."&amp;repeat_cells=".$repeat_cells."&amp;goto=".$goto."&amp;dontlimitchars=".$dontlimitchars."&amp;".PMA_generate_common_url($db, $table)."&amp;"; ?>')"> 'sql.php?sql_query=' . $encoded_query .
'&amp;session_max_rows=' . $session_max_rows .
<?php '&amp;disp_direction=' . $disp_direction .
if ($nbTotalPage < 200) { '&amp;repeat_cells=' . $repeat_cells .
$firstPage = 1; '&amp;goto=' . $goto .
$lastPage = $nbTotalPage; '&amp;dontlimitchars=' . $dontlimitchars .
} else { '&amp;' . PMA_generate_common_url($db, $table) .
$range = 20; '&amp;',
$firstPage = ($pageNow - $range < 1 ? 1 : $pageNow - $range); $session_max_rows,
$lastPage = ($pageNow + $range > $nbTotalPage ? $nbTotalPage : $pageNow + $range); $pageNow,
} $nbTotalPage
for ($i=$firstPage; $i<=$lastPage; $i++){ );
if ($i == $pageNow) { ?>
$selected = 'selected="selected"';
} else {
$selected = "";
}
echo " <option ".$selected." value=\"".(($i - 1) * $session_max_rows)."\">".$i."</option>\n";
}
?>
</select>
</form> </form>
</td> </td>
<?php <?php