From 66d01fcffb40eecde04bcb35119b2011f42626e9 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Sat, 20 Jul 2013 23:13:25 +0530 Subject: [PATCH] Hide tables in navigation tree --- examples/create_tables.sql | 5 ++-- examples/create_tables_drizzle.sql | 5 ++-- js/navigation.js | 15 +++++++++++ libraries/navigation/NavigationTree.class.php | 1 + libraries/navigation/Nodes/Node.class.php | 9 +++++++ .../navigation/Nodes/Node_Database.class.php | 25 +++++++++++++++++++ .../navigation/Nodes/Node_Table.class.php | 20 +++++++++++++++ navigation.php | 21 +++++++++++++++- themes/original/css/navigation.css.php | 12 +++++++++ themes/pmahomme/css/navigation.css.php | 12 +++++++++ 10 files changed, 120 insertions(+), 5 deletions(-) diff --git a/examples/create_tables.sql b/examples/create_tables.sql index 41eb7fdb89..1e98d884fc 100644 --- a/examples/create_tables.sql +++ b/examples/create_tables.sql @@ -313,8 +313,9 @@ CREATE TABLE IF NOT EXISTS `pma__navigation` ( `username` varchar(64) NOT NULL, `item_name` varchar(64) NOT NULL, `item_type` varchar(64) NOT NULL, - `db_name` varchar(64) DEFAULT NULL, - `table_name` varchar(64) DEFAULT NULL + `db_name` varchar(64) NOT NULL, + `table_name` varchar(64) NOT NULL, + PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) ) COMMENT='Hidden items of navigation tree' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; diff --git a/examples/create_tables_drizzle.sql b/examples/create_tables_drizzle.sql index 7b0391368a..e8713517af 100644 --- a/examples/create_tables_drizzle.sql +++ b/examples/create_tables_drizzle.sql @@ -299,8 +299,9 @@ CREATE TABLE IF NOT EXISTS `pma__navigation` ( `username` varchar(64) NOT NULL, `item_name` varchar(64) NOT NULL, `item_type` varchar(64) NOT NULL, - `db_name` varchar(64) DEFAULT NULL, - `table_name` varchar(64) DEFAULT NULL + `db_name` varchar(64) NOT NULL, + `table_name` varchar(64) NOT NULL, + PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) ) COMMENT='Hidden items of navigation tree' COLLATE utf8_bin; diff --git a/js/navigation.js b/js/navigation.js index 40de3a85e0..b89d3453ed 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -211,6 +211,21 @@ $(function () { event.preventDefault(); PMA_createViewDialog($(this)); }); + + /** Hide navigation tree item */ + $('.hideNavItem').live('click', function (event) { + event.preventDefault(); + $.ajax({ + url: $(this).attr('href') + '&ajax_request=true', + success: function(data) { + if (data.success === true) { + PMA_reloadNavigation(); + } else { + PMA_ajaxShowMessage(data.error); + } + } + }); + }); }); /** diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index bbfcf5a21f..7e3a9764af 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -949,6 +949,7 @@ class PMA_NavigationTree if ($node->type == Node::CONTAINER) { $retval .= ""; } + $retval .= $node->getHtmlForHideButton(); $wrap = true; } else { $node->visible = true; diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 07c1d00842..90db97ab44 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -451,5 +451,14 @@ class Node return $whereClause; } + /** + * Returns HTML for hide button displayed infront of a node + * + * @return HTML for hide button + */ + public function getHtmlForHideButton() + { + return ''; + } } ?> diff --git a/libraries/navigation/Nodes/Node_Database.class.php b/libraries/navigation/Nodes/Node_Database.class.php index 46c555fd14..b5e2b56363 100644 --- a/libraries/navigation/Nodes/Node_Database.class.php +++ b/libraries/navigation/Nodes/Node_Database.class.php @@ -440,6 +440,31 @@ class Node_Database extends Node default: break; } + + // Remove hidden items so that they are not displayed in navigation tree + $cfgRelation = PMA_getRelationsParam(); + if ($cfgRelation['navwork']) { + $navTable = PMA_Util::backquote($cfgRelation['db']) + . "." . PMA_Util::backquote($cfgRelation['navigation']); + $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]); + } + } + } + $GLOBALS['dbi']->freeResult($result); + } + return $retval; } diff --git a/libraries/navigation/Nodes/Node_Table.class.php b/libraries/navigation/Nodes/Node_Table.class.php index e5d4d2d77e..542dcf6211 100644 --- a/libraries/navigation/Nodes/Node_Table.class.php +++ b/libraries/navigation/Nodes/Node_Table.class.php @@ -230,6 +230,26 @@ class Node_Table extends Node } return $retval; } + + /** + * Returns HTML for hide button displayed infront of a node + * + * @return HTML for hide button + */ + public function getHtmlForHideButton() + { + $db = $this->realParent()->real_name; + $table = $this->real_name; + return '' + . '' + . PMA_Util::getImage('b_close', 'Hide') + . ''; + } } ?> diff --git a/navigation.php b/navigation.php index 4b4b3b36f7..2c5080d5b2 100644 --- a/navigation.php +++ b/navigation.php @@ -1,7 +1,7 @@ isAjax()) { diff --git a/themes/original/css/navigation.css.php b/themes/original/css/navigation.css.php index 2cb8d8f5b2..ccdcc4c7f3 100644 --- a/themes/original/css/navigation.css.php +++ b/themes/original/css/navigation.css.php @@ -119,6 +119,18 @@ if (! defined('PMA_MINIMUM_COMMON') && ! defined('TESTSUITE')) { color: ; background-color: ; } +#pma_navigation_tree li .tableControls { + display: none; + padding-left: 4px; +} +#pma_navigation_tree li.activePointer .tableControls { + display: inline; + opacity: 0.5; +} +#pma_navigation_tree li.activePointer .tableControls:hover { + display: inline; + opacity: 1.0; +} #pma_navigation_tree ul { clear: both; padding: 0; diff --git a/themes/pmahomme/css/navigation.css.php b/themes/pmahomme/css/navigation.css.php index 0b9068446d..95c2c9106a 100644 --- a/themes/pmahomme/css/navigation.css.php +++ b/themes/pmahomme/css/navigation.css.php @@ -104,6 +104,18 @@ if (! defined('PMA_MINIMUM_COMMON') && ! defined('TESTSUITE')) { color: ; background-color: ; } +#pma_navigation_tree li .tableControls { + display: none; + padding-left: 4px; +} +#pma_navigation_tree li.activePointer .tableControls { + display: inline; + opacity: 0.5; +} +#pma_navigation_tree li.activePointer .tableControls:hover { + display: inline; + opacity: 1.0; +} #pma_navigation_tree ul { clear: both; padding: 0;