Skip to content

Commit

Permalink
Implemented navigation pagination for all second level items: tables,…
Browse files Browse the repository at this point in the history
… views, routines and events
  • Loading branch information
roccivic committed Oct 30, 2012
1 parent 46f8092 commit 0fb0c31
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 102 deletions.
4 changes: 2 additions & 2 deletions js/functions.js
Expand Up @@ -3189,7 +3189,7 @@ AJAX.registerOnload('functions.js', function() {
} else {
var $this = $(this);
var $msgbox = PMA_ajaxShowMessage();
var isDbSelector = $this.closest('.pageselector').is('.dbselector');
var isDbSelector = $this.parent().closest('.pageselector').is('.dbselector');
var params = $(this).closest("form").serialize() + '&ajax_request=true';
if (isDbSelector) {
params += '&full=true';
Expand All @@ -3203,7 +3203,7 @@ AJAX.registerOnload('functions.js', function() {
var $parent = $this.closest('.list_container').parent();
$this.closest('.list_container').remove();
$parent.append(data.message).children('div').show();
$parent.find('span.pos2:first').text($parent.find('span.pos2:last').text());
$parent.find('span.pos2_value:first').text($parent.find('span.pos2_value:last').text());
}
} else {
PMA_ajaxShowMessage(data.error);
Expand Down
18 changes: 15 additions & 3 deletions js/navigation.js
Expand Up @@ -40,7 +40,8 @@ $(document).ready(function() {
a_path: $(this).find('span.a_path').text(),
v_path: $(this).find('span.v_path').text(),
pos: $(this).find('span.pos').text(),
pos2: $(this).find('span.pos2').text()
pos2_name: $(this).find('span.pos2_name').text(),
pos2_value: $(this).find('span.pos2_value').text()
};
var url = $('#pma_navigation').find('a.navigation_url').attr('href');
$.get(url, params, function (data) {
Expand Down Expand Up @@ -93,7 +94,18 @@ function PMA_reloadNavigation() {
params['a_path_' + count] = $(this).find('span.a_path').text();
params['v_path_' + count] = $(this).find('span.v_path').text();
params['v_path_' + count] = $(this).find('span.v_path').text();
params['pos2_' + count] = $(this).find('span.pos2').text();

var pos2_name = $(this).find('span.pos2_name').text();
if (! pos2_name) {
pos2_name = $(this).parent().parent().find('span.pos2_name:last').text();
}
var pos2_value = $(this).find('span.pos2_value').text();
if (! pos2_value) {
pos2_value = $(this).parent().parent().find('span.pos2_value:last').text();
}

params['pos2_name_' + count] = pos2_name;
params['pos2_value_' + count] = pos2_value;
count++;
}
});
Expand Down Expand Up @@ -403,7 +415,7 @@ $(function(){
var $parent = $this.closest('.list_container').parent();
$this.closest('.list_container').remove();
$parent.append(data.message).children('div').show();
$parent.find('span.pos2:first').text($parent.find('span.pos2:last').text());
$parent.find('span.pos2_value:first').text($parent.find('span.pos2_value:last').text());
}
} else {
PMA_ajaxShowMessage(data.error);
Expand Down
2 changes: 1 addition & 1 deletion libraries/navigation/Navigation.class.php
Expand Up @@ -99,7 +99,7 @@ public function getDisplay()
|| ! empty($_REQUEST['full'])
|| ! empty($_REQUEST['reload'])
) {
$_url_params = array('pos' => $this->pos, 'server' => $GLOBALS['server']);
$_url_params = array('server' => $GLOBALS['server']);
$num_db = PMA_DBI_fetch_value(
"SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`SCHEMATA`"
);
Expand Down
145 changes: 85 additions & 60 deletions libraries/navigation/NavigationTree.class.php
Expand Up @@ -35,10 +35,17 @@ class PMA_NavigationTree {
private $pos;

/**
* @var int Positions of nodes in the list of tables, views, routines or events
* @var int The names of the type of items that are being paginated on the second
* level of the navigation tree. These may be tables, views, functions,
* procedures or events.
*/
private $pos2_name = array();

/**
* @var int The positions of nodes in the lists of tables, views, routines or events
* used for pagination
*/
private $pos2 = array();
private $pos2_value = array();

/**
* @var object A reference to the common functions object
Expand All @@ -62,14 +69,16 @@ public function __construct($pos)
// Get the active node
if (isset($_REQUEST['a_path'])) {
$this->a_path[0] = $this->parsePath($_REQUEST['a_path']);
$this->pos2[0] = $_REQUEST['pos2'];
$this->pos2_name[0] = $_REQUEST['pos2_name'];
$this->pos2_value[0] = $_REQUEST['pos2_value'];
} else if (isset($_REQUEST['a_path_0'])) {
$count = 0;
while (isset($_REQUEST['a_path_' . $count])) {
$this->a_path[$count] = $this->parsePath(
$_REQUEST['a_path_' . $count]
);
$this->pos2[$count] = $_REQUEST['pos2_' . $count];
$this->pos2_name[$count] = $_REQUEST['pos2_name_' . $count];
$this->pos2_value[$count] = $_REQUEST['pos2_value_' . $count];
$count++;
}
}
Expand Down Expand Up @@ -127,20 +136,24 @@ private function buildPath()
// Whether build other parts of the tree depends
// on whether we have any paths in $this->a_path
foreach ($this->a_path as $key => $path) {
$retval = $this->buildPathPart($path, $this->pos2[$key]);
$retval = $this->buildPathPart($path, $this->pos2_name[$key], $this->pos2_value[$key]);
}
return $retval;
}

/**
* Builds a branch of the tree
*
* @param array $path A paths pointing to the branch
* of the tree that needs to be built
* @param array $path A paths pointing to the branch
* of the tree that needs to be built
* @param string $type The type of item being paginated on
* the second level of the tree
* @param int $pos2 The position for the pagination of
* the branch at the second level of the tree
*
* @return Node|false The active node or false in case of failure
*/
private function buildPathPart($path, $pos2)
private function buildPathPart($path, $type, $pos2)
{
if (count($path) > 1) {
array_shift($path); // remove 'root'
Expand All @@ -151,7 +164,7 @@ private function buildPathPart($path, $pos2)
return false;
}

$containers = $this->addDbContainers($db, $pos2);
$containers = $this->addDbContainers($db, $type, $pos2);

array_shift($path); // remove db

Expand Down Expand Up @@ -188,7 +201,9 @@ private function buildPathPart($path, $pos2)
break;
}
if (isset($node)) {
$node->pos2 = $pos2;
if ($type == $container->real_name) {
$node->pos2 = $pos2;
}
$container->addChild($node);
}
}
Expand Down Expand Up @@ -242,6 +257,8 @@ private function buildPathPart($path, $pos2)
*
* @param Node $table The table node, new containers will be
* attached to this node
* @param int $pos2 The position for the pagination of
* the branch at the second level of the tree
*
* @return array An array of new nodes
*/
Expand Down Expand Up @@ -277,12 +294,16 @@ private function addTableContainers($table, $pos2)
* References to existing children are returned
* if this function is called twice on the same node
*
* @param Node $db The database node, new containers will be
* attached to this node
* @param Node $db The database node, new containers will be
* attached to this node
* @param string $type The type of item being paginated on
* the second level of the tree
* @param int $pos2 The position for the pagination of
* the branch at the second level of the tree
*
* @return array An array of new nodes
*/
private function addDbContainers($db, $pos2)
private function addDbContainers($db, $type, $pos2)
{
$retval = array();
if ($db->hasChildren(true) == 0) {
Expand All @@ -303,11 +324,16 @@ private function addDbContainers($db, $pos2)
}
// Add all new Nodes to the tree
foreach ($retval as $node) {
$node->pos2 = $pos2;
if ($type == $node->real_name) {
$node->pos2 = $pos2;
}
$db->addChild($node);
}
} else {
foreach ($db->children as $node) {
if ($type == $node->real_name) {
$node->pos2 = $pos2;
}
$retval[$node->real_name] = $node;
}
}
Expand Down Expand Up @@ -378,13 +404,15 @@ public function groupNode($node)
} else {
$groups[$key]->icon = '';
}
$groups[$key]->pos2 = $node->pos2;
$node->addChild($groups[$key]);
foreach ($node->children as $child) { // FIXME: this could be more efficient
if (substr($child->name, 0, strlen($key)) == $key && $child->type == Node::OBJECT) {
$new_child = new Node(substr($child->name, strlen($key)));
$new_child->real_name = $child->real_name;
$new_child->icon = $child->icon;
$new_child->links = $child->links;
$new_child->pos2 = $child->pos2;
$groups[$key]->addChild($new_child);
foreach ($child->children as $elm) {
$new_child->addChild($elm);
Expand Down Expand Up @@ -458,7 +486,7 @@ public function renderPath()
}


if ($node->real_name == 'tables') {
if ($node->type == Node::CONTAINER && ! $node->is_group) {
$retval .= $this->getPageSelector($node);
}

Expand Down Expand Up @@ -491,6 +519,7 @@ public function renderPath()
public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
{
$retval = '';
$paths = $node->getPaths();
if ($node->hasSiblings()) {
if ( $node->type == Node::CONTAINER
&& count($node->children) == 0
Expand All @@ -505,8 +534,6 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
if (($GLOBALS['is_ajax_request'] || $hasChildren || $GLOBALS['cfg']['LeftFrameLight'])
&& ! in_array($node->parent->real_name, $sterile) && ! preg_match('/^' . __('New') . '/', $node->real_name)
) {
$paths = $this->getPaths($node);

$loaded = '';
if ($node->is_group || $GLOBALS['cfg']['LeftFrameLight'] != true) {
$loaded = ' loaded';
Expand All @@ -522,11 +549,30 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
}

$icon = $this->_commonFunctions->getImage('b_plus.png');
$match = 1;
foreach ($this->a_path as $path) {
$match = 1;
foreach ($paths['a_path_clean'] as $key => $part) {
if (! isset($path[$key]) || $part != $path[$key]) {
$match = 0;
break;
}
}
if ($match) {
$loaded = ' loaded';
if (! $node->is_group) {
$icon = $this->_commonFunctions->getImage('b_minus.png');
}
break;
}
}

foreach ($this->v_path as $path) {
$match = 1;
foreach ($paths['v_path_clean'] as $key => $part) {
if ((! isset($path[$key]) || $part != $path[$key])) {
$match = 0;
break;
}
}
if ($match) {
Expand All @@ -540,14 +586,21 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
$retval .= "<span class='hide a_path'>" . $paths['a_path'] . "</span>";
$retval .= "<span class='hide v_path'>" . $paths['v_path'] . "</span>";
$retval .= "<span class='hide pos'>" . $this->pos . "</span>";
$retval .= "<span class='hide pos2'>" . $node->pos2 . "</span>";
if (isset($paths['a_path_clean'][2])) {
$retval .= "<span class='hide pos2_name'>" . $paths['a_path_clean'][2] . "</span>";
$retval .= "<span class='hide pos2_value'>" . $node->pos2 . "</span>";
}
$retval .= $icon;

$retval .= "</a>";
$retval .= "</div>";
} else {
$retval .= "<div class='block'>";
$retval .= "<i" . ( $class == 'first' ? " class='first'" : '') . "></i>";
if (isset($paths['a_path_clean'][2])) {
$retval .= "<span class='hide pos2_name'>" . $paths['a_path_clean'][2] . "</span>";
$retval .= "<span class='hide pos2_value'>" . $node->pos2 . "</span>";
}
$retval .= "</div>";
}

Expand Down Expand Up @@ -589,6 +642,10 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
} else {
$node->visible = true;
$wrap = false;
if (isset($paths['a_path_clean'][2])) {
$retval .= "<span class='hide pos2_name'>" . $paths['a_path_clean'][2] . "</span>";
$retval .= "<span class='hide pos2_value'>" . $node->pos2 . "</span>";
}
}

if ($recursive) {
Expand All @@ -615,7 +672,7 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
) {
$retval .= $this->fastFilterHtml();
}
if ($node->real_name == 'tables') {
if ($node->type == Node::CONTAINER && ! $node->is_group) {
$retval .= $this->getPageSelector($node);
}
$retval .= $buffer;
Expand All @@ -628,35 +685,6 @@ public function renderNode($node, $recursive = -1, $indent = ' ', $class = '')
return $retval;
}

/**
* Returns the actual path and the virtual paths for a node
*
* @return array
*/
private function getPaths($node)
{
$a_path = array();
$a_path_clean = array();
foreach ($node->parents(true, true, false) as $parent) {
$a_path[] = base64_encode($parent->real_name);
$a_path_clean[] = $parent->real_name;
}
$a_path = implode('.', array_reverse($a_path));
$a_path_clean = array_reverse($a_path_clean);

$v_path = array();
foreach ($node->parents(true, true, true) as $parent) {
$v_path[] = base64_encode($parent->name);
}
$v_path = implode('.', array_reverse($v_path));

return array(
'a_path' => $a_path,
'a_path_clean' => $a_path_clean,
'v_path' => $v_path
);
}

/**
* Makes some nodes visible based on the which node is active
*
Expand Down Expand Up @@ -693,34 +721,31 @@ private function fastFilterHtml()
/**
* Generates the HTML code for displaying the list pagination
*
* @param Node $node The node for whose children the page
* selector will be created
*
* @return string
*/
private function getPageSelector($node)
{
$paths = $this->getPaths($node);
$paths = $node->getPaths();
$_url_params = array(
'a_path' => $paths['a_path'],
'v_path' => $paths['v_path'],
'pos' => $this->pos,
'server' => $GLOBALS['server']
);
$db = $this->_commonFunctions->sqlAddSlashes(
$node->realParent()->real_name
);
$num_tbl = PMA_DBI_fetch_value(
"SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`TABLES` "
. "WHERE TABLE_TYPE = 'Base Table' "
. "AND TABLE_SCHEMA = '" . $db . "'"
'server' => $GLOBALS['server'],
'pos2_name' => $paths['a_path_clean'][2]
);
$num = $node->realParent()->getPresence($node->real_name);

return $this->_commonFunctions->getListNavigator(
$num_tbl,
$num,
$node->pos2,
$_url_params,
'navigation.php',
'frame_navigation',
$GLOBALS['cfg']['MaxTableList'],
'pos2'
'pos2_value'
);
}

Expand Down

0 comments on commit 0fb0c31

Please sign in to comment.