From 2fa832ca8944619c6f1094173cc0f0e91fd61c22 Mon Sep 17 00:00:00 2001 From: Nisarg Jhaveri Date: Tue, 23 Jun 2015 17:01:45 +0530 Subject: [PATCH] rfe#1557 Hide groups from navi panel Signed-off-by: Nisarg Jhaveri --- ChangeLog | 1 + doc/config.rst | 38 ++++++++- libraries/config.default.php | 35 ++++++++ libraries/config/messages.inc.php | 17 ++++ libraries/config/setup.forms.php | 13 ++- libraries/config/user_preferences.forms.php | 13 ++- libraries/navigation/Navigation.class.php | 1 + libraries/navigation/NavigationTree.class.php | 40 +++++++-- libraries/navigation/Nodes/Node.class.php | 35 +++++++- .../navigation/Nodes/Node_Database.class.php | 83 ++++++++----------- .../Nodes/Node_DatabaseChild.class.php | 26 ------ .../Node_DatabaseChild_Container.class.php | 12 ++- 12 files changed, 226 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04e0227bad..cf5d8361ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -64,6 +64,7 @@ phpMyAdmin - ChangeLog - bug #4966 MySQL errors are not shown when DebugSQL is enabled + rfe #342 One file per table and one file per database export option + rfe #1060 Designer settings should be part of saved state ++ rfe #1557 Option to remove functions, procedures, etc., from navigation tree 4.4.11.0 (not yet released) diff --git a/doc/config.rst b/doc/config.rst index baa96b283a..0bc8c41fb9 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1560,7 +1560,7 @@ Navigation panel setup :type: string :default: ``'index.php'`` - Enter :term:`URL` where logo in the navigation panel will point to. + Enter :term:`URL` where logo in the navigation panel will point to. For use especially with self made theme which changes this. For external URLs, you should include URL scheme as well. @@ -1647,6 +1647,42 @@ Navigation panel setup Whether to offer the possibility of tree expansion in the navigation panel. +.. config:option:: $cfg['NavigationTreeShowTables'] + + :type: boolean + :default: true + + Whether to show tables under database in the navigation panel. + +.. config:option:: $cfg['NavigationTreeShowViews'] + + :type: boolean + :default: true + + Whether to show views under database in the navigation panel. + +.. config:option:: $cfg['NavigationTreeShowFunctions'] + + :type: boolean + :default: true + + Whether to show functions under database in the navigation panel. + +.. config:option:: $cfg['NavigationTreeShowProcedures'] + + :type: boolean + :default: true + + Whether to show procedures under database in the navigation panel. + +.. config:option:: $cfg['NavigationTreeShowEvents'] + + :type: boolean + :default: true + + Whether to show events under database in the navigation panel. + + Main panel ---------- diff --git a/libraries/config.default.php b/libraries/config.default.php index 8aebb25197..409ae20e11 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -999,6 +999,41 @@ $cfg['NavigationTreeDefaultTabTable2'] = ''; */ $cfg['NavigationTreeEnableExpansion'] = true; +/** + * Show tables in navigation panel + * + * @global boolean $cfg['NavigationTreeShowTables'] + */ +$cfg['NavigationTreeShowTables'] = true; + +/** + * Show views in navigation panel + * + * @global boolean $cfg['NavigationTreeShowViews'] + */ +$cfg['NavigationTreeShowViews'] = true; + +/** + * Show functions in navigation panel + * + * @global boolean $cfg['NavigationTreeShowFunctions'] + */ +$cfg['NavigationTreeShowFunctions'] = true; + +/** + * Show procedures in navigation panel + * + * @global boolean $cfg['NavigationTreeShowProcedures'] + */ +$cfg['NavigationTreeShowProcedures'] = true; + +/** + * Show events in navigation panel + * + * @global boolean $cfg['NavigationTreeShowEvents'] + */ +$cfg['NavigationTreeShowEvents'] = true; + /******************************************************************************* * In the main panel, at startup... */ diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 498cabe743..a896098c88 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -245,6 +245,8 @@ $strConfigForm_Navi_databases = __('Databases'); $strConfigForm_Navi_databases_desc = __('Databases display options.'); $strConfigForm_Navi_panel = __('Navigation panel'); $strConfigForm_Navi_panel_desc = __('Customize appearance of the navigation panel.'); +$strConfigForm_Navi_tree = __('Navigation tree'); +$strConfigForm_Navi_tree_desc = __('Customize the navigation tree.'); $strConfigForm_Navi_servers = __('Servers'); $strConfigForm_Navi_servers_desc = __('Servers display options.'); $strConfigForm_Navi_tables = __('Tables'); @@ -482,6 +484,21 @@ $strConfigNavigationTreeEnableExpansion_desc = __('Whether to offer the possibility of tree expansion in the navigation panel.'); $strConfigNavigationTreeEnableExpansion_name = __('Enable navigation tree expansion'); +$strConfigNavigationTreeShowTables_name = __('Show tables in tree'); +$strConfigNavigationTreeShowTables_desc + = __('Whether to show tables under database in the navigation tree'); +$strConfigNavigationTreeShowViews_name = __('Show views in tree'); +$strConfigNavigationTreeShowViews_desc + = __('Whether to show views under database in the navigation tree'); +$strConfigNavigationTreeShowFunctions_name = __('Show functions in tree'); +$strConfigNavigationTreeShowFunctions_desc + = __('Whether to show functions under database in the navigation tree'); +$strConfigNavigationTreeShowProcedures_name = __('Show procedures in tree'); +$strConfigNavigationTreeShowProcedures_desc + = __('Whether to show procedures under database in the navigation tree'); +$strConfigNavigationTreeShowEvents_name = __('Show events in tree'); +$strConfigNavigationTreeShowEvents_desc + = __('Whether to show events under database in the navigation tree'); $strConfigNumRecentTables_desc = __('Maximum number of recently used tables; set 0 to disable.'); $strConfigNumFavoriteTables_desc diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index af54ad52a3..992e14204d 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -176,13 +176,20 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', 'FirstLevelNavigationItems', - 'MaxNavigationItems', - 'NavigationTreeEnableGrouping', - 'NavigationTreeEnableExpansion', 'NavigationTreeDisplayItemFilterMinimum', 'NumRecentTables', 'NumFavoriteTables' ); +$forms['Navi_panel']['Navi_tree'] = array( + 'MaxNavigationItems', + 'NavigationTreeEnableGrouping', + 'NavigationTreeEnableExpansion', + 'NavigationTreeShowTables', + 'NavigationTreeShowViews', + 'NavigationTreeShowFunctions', + 'NavigationTreeShowProcedures', + 'NavigationTreeShowEvents' +); $forms['Navi_panel']['Navi_servers'] = array( 'NavigationDisplayServers', 'DisplayServersList'); diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index ef9487f70a..73208b01de 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -85,13 +85,20 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', 'FirstLevelNavigationItems', - 'MaxNavigationItems', - 'NavigationTreeEnableGrouping', - 'NavigationTreeEnableExpansion', 'NavigationTreeDisplayItemFilterMinimum', 'NumRecentTables', 'NumFavoriteTables' ); +$forms['Navi_panel']['Navi_tree'] = array( + 'MaxNavigationItems', + 'NavigationTreeEnableGrouping', + 'NavigationTreeEnableExpansion', + 'NavigationTreeShowTables', + 'NavigationTreeShowViews', + 'NavigationTreeShowFunctions', + 'NavigationTreeShowProcedures', + 'NavigationTreeShowEvents' +); $forms['Navi_panel']['Navi_databases'] = array( 'NavigationTreeDisplayDbFilterMinimum', 'NavigationTreeDbSeparator'); diff --git a/libraries/navigation/Navigation.class.php b/libraries/navigation/Navigation.class.php index 481351bafa..bdfb44fa15 100644 --- a/libraries/navigation/Navigation.class.php +++ b/libraries/navigation/Navigation.class.php @@ -189,6 +189,7 @@ class PMA_Navigation $GLOBALS['dbi']->freeResult($result); $typeMap = array( + 'group' => __('Groups:'), 'event' => __('Events:'), 'function' => __('Functions:'), 'procedure' => __('Procedures:'), diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index 14c3a55483..2b60246709 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -560,29 +560,57 @@ class PMA_NavigationTree */ private function _addDbContainers($db, $type, $pos2) { + // Get items to hide + $hidden = $db->getHiddenItems('group'); + if (!$GLOBALS['cfg']['NavigationTreeShowTables'] + && !in_array('tables', $hidden) + ) { + $hidden[] = 'tables'; + } + if (!$GLOBALS['cfg']['NavigationTreeShowViews'] + && !in_array('views', $hidden) + ) { + $hidden[] = 'views'; + } + if (!$GLOBALS['cfg']['NavigationTreeShowFunctions'] + && !in_array('functions', $hidden) + ) { + $hidden[] = 'functions'; + } + if (!$GLOBALS['cfg']['NavigationTreeShowProcedures'] + && !in_array('procedures', $hidden) + ) { + $hidden[] = 'procedures'; + } + if (!$GLOBALS['cfg']['NavigationTreeShowEvents'] + && !in_array('events', $hidden) + ) { + $hidden[] = 'events'; + } + $retval = array(); if ($db->hasChildren(true) == 0) { - if ($db->getPresence('tables')) { + if (!in_array('tables', $hidden) && $db->getPresence('tables')) { $retval['tables'] = PMA_NodeFactory::getInstance( 'Node_Table_Container' ); } - if ($db->getPresence('views')) { + if (!in_array('views', $hidden) && $db->getPresence('views')) { $retval['views'] = PMA_NodeFactory::getInstance( 'Node_View_Container' ); } - if ($db->getPresence('functions')) { + if (!in_array('functions', $hidden) && $db->getPresence('functions')) { $retval['functions'] = PMA_NodeFactory::getInstance( 'Node_Function_Container' ); } - if ($db->getPresence('procedures')) { + if (!in_array('procedures', $hidden) && $db->getPresence('procedures')) { $retval['procedures'] = PMA_NodeFactory::getInstance( 'Node_Procedure_Container' ); } - if ($db->getPresence('events')) { + if (!in_array('events', $hidden) && $db->getPresence('events')) { $retval['events'] = PMA_NodeFactory::getInstance( 'Node_Event_Container' ); @@ -1124,10 +1152,10 @@ class PMA_NavigationTree } else { $retval .= " {$node->name}"; } + $retval .= $node->getHtmlForControlButtons(); if ($node->type == Node::CONTAINER) { $retval .= ""; } - $retval .= $node->getHtmlForControlButtons(); $retval .= '
'; $wrap = true; } else { diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 96aefe1bb3..83c53aea1c 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -741,7 +741,40 @@ class Node */ public function getHtmlForControlButtons() { - return ''; + $ret = ''; + $cfgRelation = PMA_getRelationsParam(); + if (isset($cfgRelation['navwork']) && $cfgRelation['navwork']) { + if ($this instanceof Node_DatabaseChild_Container + || $this instanceof Node_DatabaseChild + ) { + $db = $this->realParent()->real_name; + $item = $this->real_name; + $ret = '' + . '' + . PMA_Util::getImage('lightbulb_off.png', __('Hide')) + . ''; + } else if ($this instanceof Node_Database) { + if ($this->hiddenCount > 0) { + $ret = '' + . '' + . PMA_Util::getImage( + 'lightbulb.png', __('Show hidden items') + ) + . ''; + } + } + } + return $ret; } /** diff --git a/libraries/navigation/Nodes/Node_Database.class.php b/libraries/navigation/Nodes/Node_Database.class.php index 4f23938a87..f3530e07bb 100644 --- a/libraries/navigation/Nodes/Node_Database.class.php +++ b/libraries/navigation/Nodes/Node_Database.class.php @@ -21,7 +21,7 @@ class Node_Database extends Node * * @var int */ - private $_hiddenCount = 0; + protected $hiddenCount = 0; /** * Initialises the class @@ -338,7 +338,6 @@ class Node_Database extends Node public function getData($type, $pos, $searchClause = '') { $retval = array(); - $db = $this->real_name; switch ($type) { case 'tables': $retval = $this->_getTables($pos, $searchClause); @@ -362,30 +361,46 @@ class Node_Database extends Node // Remove hidden items so that they are not displayed in navigation tree $cfgRelation = PMA_getRelationsParam(); if (isset($cfgRelation['navwork']) && $cfgRelation['navwork']) { - $navTable = PMA_Util::backquote($cfgRelation['db']) - . "." . PMA_Util::backquote($cfgRelation['navigationhiding']); - $sqlQuery = "SELECT `item_name` FROM " . $navTable - . " WHERE `username`='" . $cfgRelation['user'] . "'" - . " AND `item_type`='" . substr($type, 0, -1) - . "'" . " AND `db_name`='" . PMA_Util::sqlAddSlashes($db) . "'"; - $result = PMA_queryAsControlUser($sqlQuery, false); - if ($result) { - $hiddenItems = array(); - while ($row = $GLOBALS['dbi']->fetchArray($result)) { - $hiddenItems[] = $row[0]; - } - foreach ($retval as $key => $item) { - if (in_array($item, $hiddenItems)) { - unset($retval[$key]); - } + $hiddenItems = $this->getHiddenItems(substr($type, 0, -1)); + foreach ($retval as $key => $item) { + if (in_array($item, $hiddenItems)) { + unset($retval[$key]); } } - $GLOBALS['dbi']->freeResult($result); } return $retval; } + /** + * Return list of hidden items of given type + * + * @param string $type The type of items we are looking for + * ('table', 'function', 'group', etc.) + * + * @return array Array containing hidden items of given type + */ + public function getHiddenItems($type) + { + $db = $this->real_name; + $cfgRelation = PMA_getRelationsParam(); + $navTable = PMA_Util::backquote($cfgRelation['db']) + . "." . PMA_Util::backquote($cfgRelation['navigationhiding']); + $sqlQuery = "SELECT `item_name` FROM " . $navTable + . " WHERE `username`='" . $cfgRelation['user'] . "'" + . " AND `item_type`='" . $type + . "'" . " AND `db_name`='" . PMA_Util::sqlAddSlashes($db) . "'"; + $result = PMA_queryAsControlUser($sqlQuery, false); + $hiddenItems = array(); + if ($result) { + while ($row = $GLOBALS['dbi']->fetchArray($result)) { + $hiddenItems[] = $row[0]; + } + } + $GLOBALS['dbi']->freeResult($result); + return $hiddenItems; + } + /** * Returns the list of tables or views inside this database * @@ -624,32 +639,6 @@ class Node_Database extends Node return $retval; } - /** - * Returns HTML for show hidden button displayed infront of database node - * - * @return String HTML for show hidden button - */ - public function getHtmlForControlButtons() - { - $ret = ''; - $cfgRelation = PMA_getRelationsParam(); - if (isset($cfgRelation['navwork']) && $cfgRelation['navwork']) { - if ($this->_hiddenCount > 0) { - $ret = '' - . '' - . PMA_Util::getImage( - 'lightbulb.png', __('Show hidden items') - ) - . ''; - } - } - return $ret; - } - /** * Sets the number of hidden items in this database * @@ -659,7 +648,7 @@ class Node_Database extends Node */ public function setHiddenCount($count) { - $this->_hiddenCount = $count; + $this->hiddenCount = $count; } /** @@ -669,7 +658,7 @@ class Node_Database extends Node */ public function getHiddenCount() { - return $this->_hiddenCount; + return $this->hiddenCount; } } diff --git a/libraries/navigation/Nodes/Node_DatabaseChild.class.php b/libraries/navigation/Nodes/Node_DatabaseChild.class.php index 398d0b2178..d75cec0f62 100644 --- a/libraries/navigation/Nodes/Node_DatabaseChild.class.php +++ b/libraries/navigation/Nodes/Node_DatabaseChild.class.php @@ -16,32 +16,6 @@ if (! defined('PHPMYADMIN')) { */ abstract class Node_DatabaseChild extends Node { - /** - * Returns HTML for hide button displayed infront of the database child node - * - * @return String HTML for hide button - */ - public function getHtmlForControlButtons() - { - $ret = ''; - $cfgRelation = PMA_getRelationsParam(); - if (isset($cfgRelation['navwork']) && $cfgRelation['navwork']) { - $db = $this->realParent()->real_name; - $item = $this->real_name; - $ret = '' - . '' - . PMA_Util::getImage('lightbulb_off.png', __('Hide')) - . ''; - } - return $ret; - } - /** * Returns the type of the item represented by the node. * diff --git a/libraries/navigation/Nodes/Node_DatabaseChild_Container.class.php b/libraries/navigation/Nodes/Node_DatabaseChild_Container.class.php index 0664203e6b..3b80c36660 100644 --- a/libraries/navigation/Nodes/Node_DatabaseChild_Container.class.php +++ b/libraries/navigation/Nodes/Node_DatabaseChild_Container.class.php @@ -32,5 +32,15 @@ abstract class Node_DatabaseChild_Container extends Node ); } } + + /** + * Returns the type of the item represented by the node. + * + * @return string type of the item + */ + protected function getItemType() + { + return 'group'; + } } -?> \ No newline at end of file +?>