Render tables tree on selecting a database using select box

Signed-off-by: Atul Pratap Singh <atulpratapsingh05@gmail.com>
This commit is contained in:
Atul Pratap Singh 2015-01-18 02:34:02 +05:30
parent b295b6442c
commit 4fa06442c5
7 changed files with 98 additions and 49 deletions

View File

@ -8,36 +8,49 @@
/**
* Loads child items of a node and executes a given callback
*
* @param isNode
* @param $expandElem expander
* @param callback callback function
*
* @returns void
*/
function loadChildNodes($expandElem, callback) {
if (!$expandElem.hasClass('expander')) {
return;
function loadChildNodes(isNode, $expandElem, callback) {
if (isNode) {
if (!$expandElem.hasClass('expander')) {
return;
}
var $destination = $expandElem.closest('li');
var searchClause = PMA_fastFilter.getSearchClause();
var searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
var params = {
aPath: $expandElem.find('span.aPath').text(),
vPath: $expandElem.find('span.vPath').text(),
pos: $expandElem.find('span.pos').text(),
pos2_name: $expandElem.find('span.pos2_name').text(),
pos2_value: $expandElem.find('span.pos2_value').text(),
searchClause: searchClause,
searchClause2: searchClause2
};
} else {
var $destination = $('#pma_navigation_tree_content');
var params = {
aPath: $expandElem.attr('aPath'),
vPath: $expandElem.attr('vPath'),
pos: $expandElem.attr('pos')
};
}
var $destination = $expandElem.closest('li');
var searchClause = PMA_fastFilter.getSearchClause();
var searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
var params = {
aPath: $expandElem.find('span.aPath').text(),
vPath: $expandElem.find('span.vPath').text(),
pos: $expandElem.find('span.pos').text(),
pos2_name: $expandElem.find('span.pos2_name').text(),
pos2_value: $expandElem.find('span.pos2_value').text(),
searchClause: searchClause,
searchClause2: searchClause2
};
var url = $('#pma_navigation').find('a.navigation_url').attr('href');
$.get(url, params, function (data) {
if (typeof data !== 'undefined' && data.success === true) {
$expandElem.addClass('loaded');
if (isNode) {
$expandElem.addClass('loaded');
}
$destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there
$destination.append(data.message);
$destination.children('div.list_container').first().show();
if (data._debug){
$('#session_debug').replaceWith(data._debug);
}
@ -135,6 +148,10 @@ $(function () {
$icon.attr('src', icon_reload_src);
}, 1000);
});
$(document).on("change", '#navi_db_select', function (event) {
$(this).closest('form').trigger('submit');
});
/**
* Register event handler for click on the collapse all
@ -510,7 +527,7 @@ function expandTreeNode($expandElem, callback) {
$icon.hide();
$throbber.insertBefore($icon);
loadChildNodes($expandElem, function (data) {
loadChildNodes(true, $expandElem, function (data) {
if (typeof data !== 'undefined' && data.success === true) {
var $destination = $expandElem.closest('li');
$icon.removeClass('ic_b_plus').addClass('ic_b_minus');
@ -586,6 +603,13 @@ function PMA_showCurrentNavigation() {
} else {
handleTableOrDb(table, $dbItem);
}
} else {
if (! PMA_commonParams.get('show_navigation_as_tree')) {
loadChildNodes(false, $('option:selected', $('#navi_db_select')), function (data) {
return;
});
return;
}
}
}
PMA_showFullName($('#pma_navigation_tree'));
@ -688,7 +712,7 @@ function PMA_showCurrentNavigation() {
}
function loadAndShowTableOrView($expander, $relatedContainer, itemName) {
loadChildNodes($expander, function (data) {
loadChildNodes(true, $expander, function (data) {
var $whichItem = findLoadedItem(
$relatedContainer.children('div.list_container'),
itemName, null, true
@ -825,12 +849,17 @@ function PMA_navigationTreePagination($this) {
if (typeof data !== 'undefined' && data.success) {
if (isDbSelector) {
var val = PMA_fastFilter.getSearchClause();
$('#pma_navigation_tree')
if (PMA_commonParams.get('show_navigation_as_tree')) {
var $div_elem = $('#pma_navigation_tree');
} else {
var $div_elem = $('#pma_navigation_select_database');
}
$div_elem
.html(data.message)
.children('div')
.show();
if (val) {
$('#pma_navigation_tree')
$div_elem
.find('li.fast_filter input.searchClause')
.val(val);
}

View File

@ -33,19 +33,11 @@ class PMA_Navigation
if (! PMA_Response::getInstance()->isAjax()) {
$header = new PMA_NavigationHeader();
$retval = $header->getDisplay();
$class = ' class="list_container';
if ($GLOBALS['cfg']['NavigationLinkWithMainPanel']) {
$class .= ' synced';
}
if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
$class .= ' highlight';
}
$class .= '"';
$retval .= '<div id="pma_navigation_tree"' . $class . '>';
}
$tree = new PMA_NavigationTree();
if ($GLOBALS['cfg']['ShowNavigationAsTree']) {
$tree = new PMA_NavigationTree();
if ($GLOBALS['cfg']['ShowNavigationAsTree']
// || $GLOBALS['db'] == ''
) {
if (! PMA_Response::getInstance()->isAjax()
|| ! empty($_REQUEST['full'])
|| ! empty($_REQUEST['reload'])
@ -64,9 +56,16 @@ class PMA_Navigation
$retval .= $treeRender;
}
} else {
// provide legacy pre-4.0 navigation
$retval .= $this->_quickWarp();
$retval .= $tree->renderDbSelect();
// provide legacy pre-4.0 navigation
if (! PMA_Response::getInstance()->isAjax()
|| ! empty($_REQUEST['full'])
|| ! empty($_REQUEST['reload'])
) {
$retval .= $this->_quickWarp();
$retval .= $tree->renderDbSelect();
} else {
$retval = $tree->renderPath();
}
}
if (! PMA_Response::getInstance()->isAjax()) {

View File

@ -32,6 +32,14 @@ class PMA_NavigationHeader
'ajax_request' => true
)
);
$class = ' class="list_container';
if ($GLOBALS['cfg']['NavigationLinkWithMainPanel']) {
$class .= ' synced';
}
if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
$class .= ' highlight';
}
$class .= '"';
$buffer = '<div id="pma_navigation">';
$buffer .= '<div id="pma_navigation_resizer"></div>';
$buffer .= '<div id="pma_navigation_collapser"></div>';
@ -53,6 +61,7 @@ class PMA_NavigationHeader
)
);
$buffer .= '</div>'; // pma_navigation_header
$buffer .= '<div id="pma_navigation_tree"' . $class . '>';
return $buffer;
}

View File

@ -630,7 +630,7 @@ class PMA_NavigationTree
{
if ($node->type != Node::CONTAINER
|| $GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']
|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
//|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
) {
return;
}
@ -775,7 +775,7 @@ class PMA_NavigationTree
$retval .= '<ul>';
$retval .= $this->_fastFilterHtml($this->_tree);
if (! $GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']
|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
//|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
) {
$retval .= $this->_controls();
}
@ -817,6 +817,9 @@ class PMA_NavigationTree
$retval .= $this->_fastFilterHtml($node);
$retval .= $this->_getPageSelector($node);
$children = $node->children;
if (! $GLOBALS['cfg']['ShowNavigationAsTree']) {
$this->_setVisibility();
}
usort($children, array('PMA_NavigationTree', 'sortNode'));
for ($i=0, $nbChildren = count($children); $i < $nbChildren; $i++) {
if ($i + 1 != $nbChildren) {
@ -1163,21 +1166,25 @@ class PMA_NavigationTree
);
$children = $this->_tree->children;
$node = $children[0];
$retval .= '<form method="post" action="index.php" target="_parent" id="left">';
$url_params = array(
'token' => $_SESSION[' PMA_token '],
'server' => $GLOBALS['server']
);
$retval .= '<form action="db_structure.php">';
$retval .= PMA_getHiddenFields($url_params);
$retval .= '<select name="db" id="navi_db_select">'
. '<option value="" dir="' . $GLOBALS['text_dir'] . '">'
. '(' . __('Databases') . ') ...</option>' . "\n";
$selected = $GLOBALS['db'];
foreach ($children as $node) {
$paths = $node->getPaths();
if (isset($node->links['text'])) {
$args = array();
foreach ($node->parents(true) as $parent) {
$args[] = urlencode($parent->real_name);
}
$link = vsprintf($node->links['text'], $args);
$title = empty($node->links['title']) ? '' : $node->links['title'];
$retval .= '<option value="' . htmlspecialchars($node->real_name) . '"'
.' title="' . htmlspecialchars($title) . '"';
.' title="' . htmlspecialchars($title) . '"'
.' apath="' . $paths['aPath'] . '"'
.' vpath="' . $paths['vPath'] . '"'
.' pos="' . $this->_pos . '"';
if ($node->real_name == $selected || (PMA_DRIZZLE && strtolower($node->real_name) == strtolower($selected))) {
$retval .= ' selected="selected"';
}
@ -1188,7 +1195,8 @@ class PMA_NavigationTree
$retval .= '</option>';
}
}
$retval .= '</select></form></div>';
$retval .= '</select></form>';
$retval .= '</div><div id="pma_navigation_tree_content"></div>';
return $retval;
}

View File

@ -716,7 +716,7 @@ class Node
public function getCssClasses($match)
{
if ($GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']
|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
//|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
) {
return '';
}
@ -743,7 +743,7 @@ class Node
public function getIcon($match)
{
if ($GLOBALS['cfg']['NavigationTreeDisableDatabaseExpansion']
|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
//|| ! $GLOBALS['cfg']['ShowNavigationAsTree']
) {
return '';
} elseif ($match && ! $this->is_group) {

View File

@ -120,6 +120,8 @@ if (! defined('PMA_MINIMUM_COMMON') && ! defined('TESTSUITE')) {
height: 74%;
position: relative;
}
#pma_navigation_select_database {
}
#pma_navigation_tree_content {
width: 100%;
overflow: hidden;

View File

@ -106,6 +106,8 @@ if (! defined('PMA_MINIMUM_COMMON') && ! defined('TESTSUITE')) {
height: 74%;
position: relative;
}
#pma_navigation_select_database {
}
#pma_navigation_tree_content {
width: 100%;
overflow: hidden;