From 3c56e4b9afe64620b1653b04c2e0f1d643a7181e Mon Sep 17 00:00:00 2001 From: Durgesh <007durgesh219@gmail.com> Date: Tue, 23 Feb 2016 14:14:58 +0530 Subject: [PATCH] Templating Console.php, Issue #12007 Signed-off-by: Durgesh <007durgesh219@gmail.com> --- libraries/Console.php | 290 ++--------------------- templates/console/bookmark_content.phtml | 30 +++ templates/console/display.phtml | 227 ++++++++++++++++++ templates/console/query_action.phtml | 12 + templates/console/toolbar.phtml | 10 + 5 files changed, 303 insertions(+), 266 deletions(-) create mode 100644 templates/console/bookmark_content.phtml create mode 100644 templates/console/display.phtml create mode 100644 templates/console/query_action.phtml create mode 100644 templates/console/toolbar.phtml diff --git a/libraries/Console.php b/libraries/Console.php index 7ce772c947..d033828ac0 100644 --- a/libraries/Console.php +++ b/libraries/Console.php @@ -6,6 +6,7 @@ * @package PhpMyAdmin */ namespace PMA\libraries; +use PMA\libraries\Template; if (! defined('PHPMYADMIN')) { exit; @@ -77,25 +78,12 @@ class Console */ public static function getBookmarkContent() { - $output = ''; $cfgBookmark = PMA_Bookmark_getParams(); if ($cfgBookmark) { - - $tpl_bookmark_actions - = '' . __('Collapse') . ' ' - . '' . __('Expand') . ' ' - . '' . __('Requery') . ' ' - . '' . __('Edit') . ' ' - . '' . __('Delete') - . ' ' - . '' . __('Database') - . ': %s'; - $bookmarks = PMA_Bookmark_getList(); - $output .= '
'; $count_bookmarks = count($bookmarks); if ($count_bookmarks > 0) { - $output .= sprintf( + $welcomeMessage = sprintf( _ngettext( 'Showing %1$d bookmark (both private and shared)', 'Showing %1$d bookmarks (both private and shared)', @@ -104,24 +92,18 @@ class Console $count_bookmarks ); } else { - $output .= __('No bookmarks'); + $welcomeMessage = __('No bookmarks'); } unset($count_bookmarks, $private_message, $shared_message); - $output .= '
'; - foreach ($bookmarks as $val) { - $output .= ''; - } + return Template::get('console/bookmark_content') + ->render( + array( + 'welcomeMessage' => $welcomeMessage, + 'bookmarks' => $bookmarks, + ) + ); } - return $output; + return ''; } /** @@ -134,48 +116,6 @@ class Console return array('console.js'); } - /** - * Gets the history - * - * @param string $tpl_query_actions the template for query actions - * - * @return string $output the generated HTML for history - * - * @access private - * - */ - private function _getHistory($tpl_query_actions) - { - $output = ''; - - $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); - if (! empty($_sql_history)) { - foreach (array_reverse($_sql_history) as $record) { - $isSelect = preg_match( - '@^SELECT[[:space:]]+@i', $record['sqlquery'] - ); - $output .= ''; - } - } - return $output; - } - /** * Renders the console * @@ -184,206 +124,24 @@ class Console */ public function getDisplay() { - $output = ''; if ((! $this->_isAjax) && $this->_isEnabled) { $cfgBookmark = PMA_Bookmark_getParams(); - $output .= '
'; - // The templates, use sprintf() to output them - // There're white space at the end of every , - // for double-click selection - $tpl_query_actions = '' . __('Collapse') - . ' ' - . '' . __('Expand') . ' ' - . '' . __('Requery') . ' ' - . '' . __('Edit') . ' ' - . '' . __('Explain') . ' ' - . '' . __('Profiling') . ' ' - . ($cfgBookmark ? '' - . __('Bookmark') . ' ' : '') - . '' . __('Query failed') . ' ' - . '' . __('Database') - . ': %s ' - . '' . __( - 'Queried time' - ) . ': %s '; + $image = Util::getImage('console.png', __('SQL Query Console')); + $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); + $bookmarkContent = static::getBookmarkContent(); - // Console toolbar - $output .= ''; // Toolbar end - - // Console messages - $output .= '
'; - $output .= '
' - . '
' - . '' - . __('Press Ctrl+Enter to execute query') . '' - . '' - . __('Press Enter to execute query') . '' - . '
'; - - $output .= $this->_getHistory($tpl_query_actions); - - $output .= '
'; // .console_message_container - $output .= '
' - . '' - . '
'; - $output .= '
'; // Messages end - - // Dark the console while other cards cover it - $output .= '
'; - - // Debug SQL card - $output .= '
'; - $output .= '
' - . '
' - . '' . __('ascending') . '' - . '
' - . '
' - . '' . __('descending') . '' - . '
' - . '
' - . '' . __('Order:') . '' - . '
' - . '
' - . '' . __('Debug SQL') . '' - . '
' - . '
' - . '' . __('Count') . '' - . '
' - . '
' - . '' . __('Execution order') . '' - . '
' - . '
' - . '' . __('Time taken') . '' - . '
' - . '
' - . '' . __('Order by:') . '' - . '
' - . '
' - . '' . __('Group queries') . '' - . '
' - . '
' - . '' . __('Ungroup queries') . '' - . '
' - . '
'; // Toolbar - $output .= '
'; - $output .= '
'; - $output .= '
'; - $output .= '
'; // Content - $output .= '
' - . '
' - . '' . __('Collapse') . ' ' - . '' . __('Expand') . ' ' - . '' . __('Show trace') - . ' ' - . '' . __('Hide trace') - . ' ' - . '' . __('Count:') - . ' ' - . '' . __('Time taken:') - . ' ' - . '
' - . '
'; // Template - $output .= '
'; // Debug SQL card - - // Bookmarks card: - - if ($cfgBookmark) { - $output .= '
'; - $output .= '
' - . '
' . __('Bookmarks') - . '
'; - - $output .= '
' - . __('Refresh') . '
'; - - $output .= '
' - . __('Add') . '
'; - - $output .= '
'; - $output .= static::getBookmarkContent(); - $output .= '
'; - $output .= '
'; - $output .= '
'; - $output .= '
' - . '
' - . __('Add bookmark') - . '
'; - $output .= '
' - . '
' - . ' ' - . ' ' - . '' - . '' - . '
' // .options - . '
' - . '
'; - $output .= '
'; - $output .= '
'; // Add bookmark card - $output .= '
'; // Bookmarks card - } - - // Options card: - $output .= '
'; - $output .= '
' - . '
' . __('Options') - . '
'; - - $output .= '
' - . __('Set default') . '
'; - - $output .= '
' - . '
' - . '
' - . '
' - . '
' - . '
' - . '
'; - $output .= '
'; // Options card - - $output .= '
' - // Templates for console message actions - . '
' - . sprintf($tpl_query_actions, '', '') - . '
' - . '
'; - $output .= '
'; // #console and #pma_console_container ends + return Template::get('console/display') + ->render( + array( + 'cfgBookmark' => $cfgBookmark, + 'image' => $image, + '_sql_history' => $_sql_history, + 'bookmarkContent' => $bookmarkContent, + ) + ); } - return $output; + return ''; } } diff --git a/templates/console/bookmark_content.phtml b/templates/console/bookmark_content.phtml new file mode 100644 index 0000000000..24f5982344 --- /dev/null +++ b/templates/console/bookmark_content.phtml @@ -0,0 +1,30 @@ +
+ +
+ + + diff --git a/templates/console/display.phtml b/templates/console/display.phtml new file mode 100644 index 0000000000..1640b6c050 --- /dev/null +++ b/templates/console/display.phtml @@ -0,0 +1,227 @@ +
+
+ + render( + array( + 'parentDivClasses' => 'collapsed', + 'contentArray' => [ + ['switch_button console_switch', __('Console'),'image'=> $image], + ['button clear', __('Clear')], + ['button history', __('History')], + ['button options', __('Options')], + isset($cfgBookmark) + ? ['button bookmarks', __('Bookmarks')] : null, + ['button debug hide', __('Debug SQL')], + ], + ) + ); + ?> + + +
+
+
+ + + + + + +
+ + + +
+
+ +
+
+ +
+ +
+ render( + array( + 'parentDivClasses' => '', + 'contentArray' => [ + ['button order order_asc', __('ascending')], + ['button order order_desc', __('descending')], + ['text', __('Order:')], + ['switch_button', __('Debug SQL')], + ['button order_by sort_count', __('Count')], + ['button order_by sort_exec', __('Execution order')], + ['button order_by sort_time', __('Time taken')], + ['text', __('Order by:')], + ['button group_queries', __('Group queries')], + ['button ungroup_queries', __('Ungroup queries')], + ] + ) + ); + ?> +
+
+
+
+
+ render( + array( + 'parentDivClasses' => 'debug_query action_content', + 'contentArray' => [ + ['action collapse', __('Collapse')], + ['action expand', __('Expand')], + ['action dbg_show_trace', __('Show trace')], + ['action dbg_hide_trace', __('Hide trace')], + ['text count hide', __('Count'), 'extraSpan' => ''], + ['text time', __('Time taken'), 'extraSpan' => ''], + ] + ) + ); + ?> +
+
+ +
+ render( + array( + 'parentDivClasses' => '', + 'contentArray' => [ + ['switch_button', __('Bookmarks')], + ['button refresh', __('Refresh')], + ['button add', __('Add')], + ] + ) + ); + ?> +
+ +
+
+
+ render( + array( + 'parentDivClasses' => '', + 'contentArray' => [ + ['switch_button', __('Add bookmark')] + ] + ) + ); + ?> +
+
+ + + + +
+
+ +
+
+
+
+ + +
+ render( + array( + 'parentDivClasses' => '', + 'contentArray' => [ + ['switch_button', __('Options')], + ['button default', __('Set default')] + ] + ) + ); + ?> +
+ +
+ +
+ +
+ +
+ +
+
+
+
+ + render( + array( + 'parentDivClasses' => 'query_actions', + 'contentArray' => [ + ['action collapse', __('Collapse')], + ['action expand', __('Expand')], + ['action requery', __('Requery')], + ['action edit', __('Edit')], + ['action explain', __('Explain')], + ['action profiling', __('Profiling')], + isset($cfgBookmark) + ? ['action bookmark', __('Bookmark')] : null, + ['text failed', __('Query failed')], + ['text targetdb', __('Database'), 'extraSpan' => ''], + ['text query_time', __('Queried time'), 'extraSpan' => ''], + ], + ) + ); + ?> +
+
+
diff --git a/templates/console/query_action.phtml b/templates/console/query_action.phtml new file mode 100644 index 0000000000..a63e7b1f01 --- /dev/null +++ b/templates/console/query_action.phtml @@ -0,0 +1,12 @@ +
+ + + + + : + + + +
diff --git a/templates/console/toolbar.phtml b/templates/console/toolbar.phtml new file mode 100644 index 0000000000..084785705b --- /dev/null +++ b/templates/console/toolbar.phtml @@ -0,0 +1,10 @@ +
+ +
+ + +
+ +