From aba183c386cc99ba56aa3c43f9cf36ffbe34c417 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 4 Jul 2012 16:42:13 +0100 Subject: [PATCH] Preload the navigation tree to save an ajax request and don't store the pagination position in the session --- js/navigation.js | 22 ++--- libraries/Header.class.php | 4 +- libraries/navigation/Navigation.class.php | 87 ++++++++++++++++--- .../navigation/NavigationHeader.class.php | 19 +--- libraries/navigation/NavigationTree.class.php | 2 +- navigation.php | 25 ------ 6 files changed, 88 insertions(+), 71 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index bdba43a17b..661eef5bb5 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -38,7 +38,8 @@ $(document).ready(function() { $throbber.insertBefore($icon); var params = { a_path: $(this).find('span.a_path').text(), - v_path: $(this).find('span.v_path').text() + v_path: $(this).find('span.v_path').text(), + pos: $(this).find('span.pos').text() }; var url = $('#pma_navigation').find('a.navigation_url').attr('href'); $.get(url, params, function (data) { @@ -48,8 +49,8 @@ $(document).ready(function() { $destination.append(data.message); $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); $destination.children('div.list_container').show('fast', function () { - ScrollHandler.displayScrollbar(); - }); + ScrollHandler.displayScrollbar(); + }); if ($destination.find('ul > li').length == 1) { $destination.find('ul > li') .find('a.expander.container') @@ -78,7 +79,8 @@ function PMA_reloadNavigation() { .first() .css('visibility', 'visible'); var params = { - reload: true + reload: true, + pos: $('#pma_navigation_tree').find('a.expander:first > span.pos').text() }; var count = 0; $('#pma_navigation_tree').find('a.expander:visible').each(function () { @@ -366,18 +368,10 @@ var ResizeHandler = function () { $collapser.html(this.getSymbol($('#pma_navigation').width())); }; // End of ResizeHandler - /* Performed on load */ $(function(){ - if ($('#pma_navigation_tree').length) { - // Load the navigation into the initial page - var url = $('#pma_navigation').find('a.navigation_url').attr('href'); - $.get(url, 'full=true', function (data) { - if (data.success) { - $('#pma_navigation_tree').html(data.message).children('div').show(); - ScrollHandler.displayScrollbar(); - } - }); + if ($('#pma_navigation').length) { + $('#pma_navigation_tree').children('div').show(); // Fire up the resize and scroll handlers new ResizeHandler(); ScrollHandler.init(); diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 14d2579f88..94b1c4d329 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -12,7 +12,7 @@ if (! defined('PHPMYADMIN')) { require_once 'libraries/Scripts.class.php'; require_once 'libraries/RecentTable.class.php'; require_once 'libraries/Menu.class.php'; -require_once 'libraries/navigation/NavigationHeader.class.php'; +require_once 'libraries/navigation/Navigation.class.php'; /** * Class used to output the HTTP and HTML headers @@ -312,7 +312,7 @@ class PMA_Header $retval .= $this->_scripts->getDisplay(); $retval .= $this->_getBodyStart(); if ($this->_menuEnabled && $GLOBALS['server'] > 0) { - $nav = new PMA_NavigationHeader(); + $nav = new PMA_Navigation(); $retval .= $nav->getDisplay(); } // Include possible custom headers diff --git a/libraries/navigation/Navigation.class.php b/libraries/navigation/Navigation.class.php index 8db733f5c5..fddea68d32 100644 --- a/libraries/navigation/Navigation.class.php +++ b/libraries/navigation/Navigation.class.php @@ -1,5 +1,33 @@ pos = $_SESSION['tmp_user_values']['navi_limit_offset']; if (isset($_REQUEST['pos'])) { - $pos = (int) $_REQUEST['pos']; - $_SESSION['tmp_user_values']['navi_limit_offset'] = $pos; - $this->pos = $pos; + $this->pos = (int) $_REQUEST['pos']; } + if (! isset($this->pos)) { + $this->pos = $this->_getNavigationDbPos(); + } + } + + /** + * Returns the database position for the page selector + * + * return int + */ + private function _getNavigationDbPos() { + $query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d "; + $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; + $query .= "WHERE `SCHEMA_NAME` <= '%s'"; + + return PMA_DBI_fetch_value( + sprintf( + $query, + (int)$GLOBALS['cfg']['MaxDbList'], + (int)$GLOBALS['cfg']['MaxDbList'], + PMA_CommonFunctions::getInstance()->sqlAddSlashes($GLOBALS['db']) + ) + ); } /** @@ -44,8 +88,15 @@ class PMA_Navigation { { /* Init */ $retval = ''; - $tree = new PMA_NavigationTree($this->pos); - if (! empty($_REQUEST['full']) || ! empty($_REQUEST['reload'])) { + if (! PMA_Response::getInstance()->isAjax()) { + $header = new PMA_NavigationHeader(); + $retval = $header->getDisplay(); + } + $tree = new PMA_NavigationTree($this->pos); + if (! PMA_Response::getInstance()->isAjax() + || ! empty($_REQUEST['full']) + || ! empty($_REQUEST['reload']) + ) { $_url_params = array('pos' => $this->pos, 'server' => $GLOBALS['server']); $num_db = PMA_DBI_fetch_value( "SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`SCHEMATA`" @@ -58,15 +109,23 @@ class PMA_Navigation { 'frame_navigation', $GLOBALS['cfg']['MaxDbList'] ); - $retval .= $tree->renderState(); + $treeRender = $tree->renderState(); } else { - $retval = $tree->renderPath(); + $treeRender = $tree->renderPath(); } - if (! $retval) { - $retval = PMA_Message::error( + if (! $treeRender) { + $retval .= PMA_Message::error( __('An error has occured while loading the navigation tree') ); + } else { + $retval .= $treeRender; + } + + if (! PMA_Response::getInstance()->isAjax()) { + $retval .= ''; + $retval .= ''; + $retval .= ''; } return $retval; diff --git a/libraries/navigation/NavigationHeader.class.php b/libraries/navigation/NavigationHeader.class.php index 770fd60131..6ef287f136 100644 --- a/libraries/navigation/NavigationHeader.class.php +++ b/libraries/navigation/NavigationHeader.class.php @@ -20,16 +20,11 @@ class PMA_NavigationHeader if (empty($GLOBALS['url_query'])) { $GLOBALS['url_query'] = PMA_generate_common_url(); } - $link_url = PMA_generate_common_url( array( 'ajax_request' => true ) ); - $link = sprintf( - '', - $link_url - ); $buffer = '
'; $buffer .= '
'; @@ -39,21 +34,15 @@ class PMA_NavigationHeader $buffer .= '
'; $buffer .= '
'; $buffer .= '
'; - $buffer .= $link; + $buffer .= sprintf( + '', + $link_url + ); $buffer .= $this->logo(); $buffer .= $this->links(); $buffer .= $this->serverChoice(); $buffer .= $this->recent(); $buffer .= '
'; - $buffer .= '
'; - $buffer .= $this->_commonFunctions->getImage( - 'ajax_clock_small.gif', - __('Loading') - ); - $buffer .= '
'; - $buffer .= '
'; - $buffer .= ''; - $buffer .= ''; return $buffer; } diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index d7acd58b53..9d2c58a675 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -535,7 +535,7 @@ class PMA_NavigationTree { $retval .= ""; $retval .= "" . $a_path . ""; $retval .= "" . $v_path . ""; - + $retval .= "" . $this->pos . ""; $retval .= $icon; $retval .= ""; diff --git a/navigation.php b/navigation.php index e999d7492c..7e94ef9d79 100644 --- a/navigation.php +++ b/navigation.php @@ -9,31 +9,6 @@ // Include common functionalities require_once './libraries/common.inc.php'; -// The Nodes are the building blocks for the navigation tree -require_once './libraries/navigation/Nodes/Node.class.php'; -// All of the below Nodes inherit from the base Node -require_once './libraries/navigation/Nodes/Node_Column.class.php'; -require_once './libraries/navigation/Nodes/Node_Database.class.php'; -require_once './libraries/navigation/Nodes/Node_Event.class.php'; -require_once './libraries/navigation/Nodes/Node_Function.class.php'; -require_once './libraries/navigation/Nodes/Node_Index.class.php'; -require_once './libraries/navigation/Nodes/Node_Procedure.class.php'; -require_once './libraries/navigation/Nodes/Node_Table.class.php'; -require_once './libraries/navigation/Nodes/Node_Trigger.class.php'; -require_once './libraries/navigation/Nodes/Node_View.class.php'; -// Containers. Also inherit from the base Node -require_once './libraries/navigation/Nodes/Node_Column_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Event_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Function_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Index_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Procedure_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Table_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_Trigger_Container.class.php'; -require_once './libraries/navigation/Nodes/Node_View_Container.class.php'; - -// Generates a collapsible tree of database objects -require_once './libraries/navigation/NavigationTree.class.php'; - // Also initialises the collapsible tree class require_once './libraries/navigation/Navigation.class.php';