diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index e01438264b..10050acb23 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -723,10 +723,15 @@ class Results * _getMoveForwardButtonsForTableNavigation() */ private function _getTableNavigationButton( - $caption, $title, $pos, $html_sql_query, $back, $onsubmit = '', - $input_for_real_end = '', $onclick = '' + $caption, + $title, + $pos, + $html_sql_query, + $back, + $onsubmit = '', + $input_for_real_end = '', + $onclick = '' ) { - $caption_output = ''; if ($back) { if (Util::showIcons('TableNavigationLinksMode')) { @@ -743,29 +748,21 @@ class Results $caption_output .= ' ' . $caption; } } - $title_output = ' title="' . $title . '"'; - - return '' - . '
' - . Url::getHiddenInputs( - $this->__get('db'), $this->__get('table') - ) - . '' - . '' - . '' - . '' - . $input_for_real_end - . '' - . '
' - . ''; - - } // end function _getTableNavigationButton() + return Template::get('display/results/table_navigation_button')->render([ + 'db' => $this->__get('db'), + 'table' => $this->__get('table'), + 'sql_query' => $html_sql_query, + 'pos' => $pos, + 'is_browse_distinct' => $this->__get('is_browse_distinct'), + 'goto' => $this->__get('goto'), + 'input_for_real_end' => $input_for_real_end, + 'caption_output' => $caption_output, + 'title' => $title, + 'onsubmit' => $onsubmit, + 'onclick' => $onclick, + ]); + } /** * Possibly return a page selector for table navigation @@ -1018,28 +1015,16 @@ class Results private function _getShowAllCheckboxForTableNavigation( $showing_all, $html_sql_query ) { - return "\n" - . '' - . '
' - . Url::getHiddenInputs( - $this->__get('db'), $this->__get('table') - ) - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '
' - . ''; + return Template::get('display/results/show_all_checkbox')->render([ + 'db' => $this->__get('db'), + 'table' => $this->__get('table'), + 'is_browse_distinct' => $this->__get('is_browse_distinct'), + 'goto' => $this->__get('goto'), + 'unique_id' => $this->__get('unique_id'), + 'html_sql_query' => $html_sql_query, + 'showing_all' => $showing_all, + 'max_rows' => intval($GLOBALS['cfg']['MaxRows']), + ]); } // end of the '_getShowAllButtonForTableNavigation()' function @@ -1110,30 +1095,16 @@ class Results * Prepare fields for table navigation * Number of rows * - * @param string $html_sql_query the sql encoded by htmlspecialchars() + * @param string $sqlQuery the sql encoded by htmlspecialchars() * - * @return string $additional_fields_html html content + * @return string html content * * @access private * * @see _getTableNavigation() */ - private function _getAdditionalFieldsForTableNavigation( - $html_sql_query - ) { - - $additional_fields_html = ''; - - $additional_fields_html .= '' - . '' - . '' - . '' ; - + private function _getAdditionalFieldsForTableNavigation($sqlQuery) + { $numberOfRowsPlaceholder = null; if ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS) { $numberOfRowsPlaceholder = __('All'); @@ -1146,17 +1117,17 @@ class Results '250' => 250, '500' => 500 ); - $additional_fields_html .= __('Number of rows:') . ' '; - $additional_fields_html .= Util::getDropdown( - 'session_max_rows', $numberOfRowsChoices, - $_SESSION['tmpval']['max_rows'], '', - 'autosubmit', $numberOfRowsPlaceholder - ); - - return $additional_fields_html; - - } // end of the '_getAdditionalFieldsForTableNavigation()' function + return Template::get('display/results/additional_fields')->render([ + 'goto' => $this->__get('goto'), + 'is_browse_distinct' => $this->__get('is_browse_distinct'), + 'sql_query' => $sqlQuery, + 'number_of_rows_choices' => $numberOfRowsChoices, + 'number_of_rows_placeholder' => $numberOfRowsPlaceholder, + 'pos' => $_SESSION['tmpval']['pos'], + 'max_rows' => $_SESSION['tmpval']['max_rows'], + ]); + } /** * Get the headers of the results table, for all of the columns @@ -1696,137 +1667,30 @@ class Results /** * Prepare option fields block * - * @return string $options_html html content + * @return string html content * - * @access private + * @access private * - * @see _getTableHeaders() + * @see _getTableHeaders() */ private function _getOptionsBlock() { - - $options_html = ''; - - $options_html .= '
render([ + 'unique_id' => $this->__get('unique_id'), + 'geo_option' => $_SESSION['tmpval']['geoOption'], + 'hide_transformation' => $_SESSION['tmpval']['hide_transformation'], + 'display_blob' => $_SESSION['tmpval']['display_blob'], + 'display_binary' => $_SESSION['tmpval']['display_binary'], + 'relational_display' => $_SESSION['tmpval']['relational_display'], + 'displaywork' => $GLOBALS['cfgRelation']['displaywork'], + 'relwork' => $GLOBALS['cfgRelation']['relwork'], + 'pftext' => $_SESSION['tmpval']['pftext'], 'db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $this->__get('sql_query'), 'goto' => $this->__get('goto'), - 'display_options_form' => 1 - ); - - $options_html .= Url::getHiddenInputs($url_params) - . '
' - . Util::getDivForSliderEffect( - '', __('Options') - ) - . '
'; - - $options_html .= '
'; - $choices = array( - 'P' => __('Partial texts'), - 'F' => __('Full texts') - ); - - // pftext means "partial or full texts" (done to reduce line lengths) - $options_html .= Util::getRadioFields( - 'pftext', $choices, - $_SESSION['tmpval']['pftext'], - true, true, '', 'pftext_' . $this->__get('unique_id') - ) - . '
'; - - if ($GLOBALS['cfgRelation']['relwork'] - && $GLOBALS['cfgRelation']['displaywork'] - ) { - $options_html .= '
'; - $choices = array( - 'K' => __('Relational key'), - 'D' => __('Display column for relationships') - ); - - $options_html .= Util::getRadioFields( - 'relational_display', $choices, - $_SESSION['tmpval']['relational_display'], - true, true, '', 'relational_display_' . $this->__get('unique_id') - ) - . '
'; - } - - $options_html .= '
' - . Template::get('checkbox') - ->render( - array( - 'html_field_name' => 'display_binary', - 'label' => __('Show binary contents'), - 'checked' => ! empty($_SESSION['tmpval']['display_binary']), - 'onclick' => false, - 'html_field_id' => 'display_binary_' . $this->__get('unique_id'), - ) - ) - . '
' - . Template::get('checkbox') - ->render( - array( - 'html_field_name' => 'display_blob', - 'label' => __('Show BLOB contents'), - 'checked' => ! empty($_SESSION['tmpval']['display_blob']), - 'onclick' => false, - 'html_field_id' => 'display_blob_' . $this->__get('unique_id'), - ) - ) - . '
'; - - // I would have preferred to name this "display_transformation". - // This is the only way I found to be able to keep this setting sticky - // per SQL query, and at the same time have a default that displays - // the transformations. - $options_html .= '
' - . Template::get('checkbox') - ->render( - array( - 'html_field_name' => 'hide_transformation', - 'label' => __('Hide browser transformation'), - 'checked' => ! empty($_SESSION['tmpval']['hide_transformation']), - 'onclick' => false, - 'html_field_id' => 'hide_transformation_' . $this->__get('unique_id'), - ) - ) - . '
'; - - $options_html .= '
'; - $choices = array( - 'GEOM' => __('Geometry'), - 'WKT' => __('Well Known Text'), - 'WKB' => __('Well Known Binary') - ); - - $options_html .= Util::getRadioFields( - 'geoOption', $choices, - $_SESSION['tmpval']['geoOption'], - true, true, '', 'geoOption_' . $this->__get('unique_id') - ); - $options_html .= '
'; - - $options_html .= '
' - . '
'; - - $options_html .= '
' - . '' - . '
' - . '' - . '
'; - - return $options_html; - - } // end of the '_getOptionsBlock()' function - + ]); + } /** * Get full/partial text button or link @@ -1871,7 +1735,7 @@ class Results /** * Prepare html form for multi row operations * - * @param string $del_lnk the delete link of current row + * @param string $deleteLink the delete link of current row * * @return string $form_html html content * @@ -1879,71 +1743,38 @@ class Results * * @see _getTableHeaders() */ - private function _getFormForMultiRowOperations($del_lnk) + private function _getFormForMultiRowOperations($deleteLink) { - - $form_html = ''; - - if (($del_lnk == self::DELETE_ROW) || ($del_lnk == self::KILL_PROCESS)) { - - $form_html .= '
__get('db'), $this->__get('table'), 1 - ) - . ''; - } - - $form_html .= '
__get('unique_id') . '"'; - $form_html .= '>'; - - return $form_html; - - } // end of the '_getFormForMultiRowOperations()' function - + return Template::get('display/results/multi_row_operations_form')->render([ + 'delete_link' => $deleteLink, + 'delete_row' => self::DELETE_ROW, + 'kill_process' => self::KILL_PROCESS, + 'unique_id' => $this->__get('unique_id'), + 'db' => $this->__get('db'), + 'table' => $this->__get('table'), + ]); + } /** * Get comment for row * - * @param array $comments_map comments array - * @param array $fields_meta set of field properties + * @param array $commentsMap comments array + * @param array $fieldsMeta set of field properties * - * @return string $comment html content + * @return string html content * - * @access private + * @access private * - * @see _getTableHeaders() + * @see _getTableHeaders() */ - private function _getCommentForRow(array $comments_map, $fields_meta) + private function _getCommentForRow(array $commentsMap, $fieldsMeta) { - $comments = ''; - if (isset($comments_map[$fields_meta->table]) - && isset($comments_map[$fields_meta->table][$fields_meta->name]) - ) { - $sanitized_comments = htmlspecialchars( - $comments_map[$fields_meta->table][$fields_meta->name] - ); - - $comments = ''; - $limitChars = $GLOBALS['cfg']['LimitChars']; - if (mb_strlen($sanitized_comments) > $limitChars) { - $sanitized_comments = mb_substr( - $sanitized_comments, 0, $limitChars - ) . '…'; - } - $comments .= $sanitized_comments; - $comments .= ''; - } - return $comments; - } // end of the '_getCommentForRow()' function - + return Template::get('display/results/comment_for_row')->render([ + 'comments_map' => $commentsMap, + 'fields_meta' => $fieldsMeta, + 'limit_chars' => $GLOBALS['cfg']['LimitChars'], + ]); + } /** * Prepare parameters and html for sorted table header fields @@ -2508,9 +2339,9 @@ class Results /** * Prepares the display for a value * - * @param string $class class of table cell - * @param bool $condition_field whether to add CSS class condition - * @param string $value value to display + * @param string $class class of table cell + * @param bool $conditionField whether to add CSS class condition + * @param string $value value to display * * @return string the td * @@ -2519,20 +2350,22 @@ class Results * @see _getDataCellForGeometryColumns(), * _getDataCellForNonNumericColumns() */ - private function _buildValueDisplay($class, $condition_field, $value) + private function _buildValueDisplay($class, $conditionField, $value) { - return ''; - } // end of the '_buildValueDisplay()' function - + return Template::get('display/results/value_display')->render([ + 'class' => $class, + 'condition_field' => $conditionField, + 'value' => $value, + ]); + } /** * Prepares the display for a null value * - * @param string $class class of table cell - * @param bool $condition_field whether to add CSS class condition - * @param object $meta the meta-information about this field - * @param string $align cell alignment + * @param string $class class of table cell + * @param bool $conditionField whether to add CSS class condition + * @param object $meta the meta-information about this field + * @param string $align cell alignment * * @return string the td * @@ -2542,26 +2375,24 @@ class Results * _getDataCellForGeometryColumns(), * _getDataCellForNonNumericColumns() */ - private function _buildNullDisplay($class, $condition_field, $meta, $align = '') + private function _buildNullDisplay($class, $conditionField, $meta, $align = '') { - // the null class is needed for grid editing - $decimals = isset($meta->decimals) ? $meta->decimals : '-1'; - return ''; - } // end of the '_buildNullDisplay()' function + $classes = $this->_addClass($class, $conditionField, $meta, ''); + return Template::get('display/results/null_display')->render([ + 'align' => $align, + 'meta' => $meta, + 'classes' => $classes, + ]); + } /** * Prepares the display for an empty value * - * @param string $class class of table cell - * @param bool $condition_field whether to add CSS class condition - * @param object $meta the meta-information about this field - * @param string $align cell alignment + * @param string $class class of table cell + * @param bool $conditionField whether to add CSS class condition + * @param object $meta the meta-information about this field + * @param string $align cell alignment * * @return string the td * @@ -2571,15 +2402,15 @@ class Results * _getDataCellForGeometryColumns(), * _getDataCellForNonNumericColumns() */ - private function _buildEmptyDisplay($class, $condition_field, $meta, $align = '') + private function _buildEmptyDisplay($class, $conditionField, $meta, $align = '') { - return ''; - } // end of the '_buildEmptyDisplay()' function + $classes = $this->_addClass($class, $conditionField, $meta, 'nowrap'); + return Template::get('display/results/empty_display')->render([ + 'align' => $align, + 'classes' => $classes, + ]); + } /** * Adds the relevant classes. diff --git a/templates/display/results/additional_fields.twig b/templates/display/results/additional_fields.twig new file mode 100644 index 0000000000..745b3bbdcb --- /dev/null +++ b/templates/display/results/additional_fields.twig @@ -0,0 +1,14 @@ + + +{# Do not change the position when changing the number of rows #} + + +{% trans 'Number of rows:' %} +{{ Util_getDropdown( + 'session_max_rows', + number_of_rows_choices, + max_rows, + '', + 'autosubmit', + number_of_rows_placeholder +) }} diff --git a/templates/display/results/comment_for_row.twig b/templates/display/results/comment_for_row.twig new file mode 100644 index 0000000000..5380b71dc0 --- /dev/null +++ b/templates/display/results/comment_for_row.twig @@ -0,0 +1,10 @@ +{% if comments_map[fields_meta.table] is defined + and comments_map[fields_meta.table][fields_meta.name] is defined %} + + {% if comments_map[fields_meta.table][fields_meta.name]|length > limit_chars %} + {{ comments_map[fields_meta.table][fields_meta.name]|slice(0, limit_chars) }}… + {% else %} + {{ comments_map[fields_meta.table][fields_meta.name] }} + {% endif %} + +{% endif %} diff --git a/templates/display/results/empty_display.twig b/templates/display/results/empty_display.twig new file mode 100644 index 0000000000..cd43ebc756 --- /dev/null +++ b/templates/display/results/empty_display.twig @@ -0,0 +1 @@ + diff --git a/templates/display/results/multi_row_operations_form.twig b/templates/display/results/multi_row_operations_form.twig new file mode 100644 index 0000000000..bf87c7e0d0 --- /dev/null +++ b/templates/display/results/multi_row_operations_form.twig @@ -0,0 +1,12 @@ +{% if delete_link == delete_row or delete_link == kill_process %} + + {{ Url_getHiddenInputs(db, table, 1) }} + +{% endif %} + +
+
' . $value . 'NULL
diff --git a/templates/display/results/null_display.twig b/templates/display/results/null_display.twig new file mode 100644 index 0000000000..f2ea2e5f2f --- /dev/null +++ b/templates/display/results/null_display.twig @@ -0,0 +1,7 @@ + diff --git a/templates/display/results/options_block.twig b/templates/display/results/options_block.twig new file mode 100644 index 0000000000..b713616ccb --- /dev/null +++ b/templates/display/results/options_block.twig @@ -0,0 +1,99 @@ + + {{ Url_getHiddenInputs({ + 'db': db, + 'table': table, + 'sql_query': sql_query, + 'goto': goto, + 'display_options_form': 1 + }) }} + + {{ Util_getDivForSliderEffect('', 'Options'|trans) }} +
+
+ {# pftext means "partial or full texts" (done to reduce line lengths #} + {{ Util_getRadioFields( + 'pftext', + { + 'P': 'Partial texts'|trans, + 'F': 'Full texts'|trans + }, + pftext, + true, + true, + '', + 'pftext_' ~ unique_id + ) }} +
+ + {% if relwork and displaywork %} +
+ {{ Util_getRadioFields( + 'relational_display', + { + 'K': 'Relational key'|trans, + 'D': 'Display column for relationships'|trans + }, + relational_display, + true, + true, + '', + 'relational_display_' ~ unique_id + ) }} +
+ {% endif %} + +
+ {% include 'checkbox.twig' with { + 'html_field_name': 'display_binary', + 'label': 'Show binary contents'|trans, + 'checked': display_binary is not empty, + 'onclick': false, + 'html_field_id': 'display_binary_' ~ unique_id + } only %} + {% include 'checkbox.twig' with { + 'html_field_name': 'display_blob', + 'label': 'Show BLOB contents'|trans, + 'checked': display_blob is not empty, + 'onclick': false, + 'html_field_id': 'display_blob_' ~ unique_id + } only %} +
+ + {# I would have preferred to name this "display_transformation". + This is the only way I found to be able to keep this setting sticky + per SQL query, and at the same time have a default that displays + the transformations. #} +
+ {% include 'checkbox.twig' with { + 'html_field_name': 'hide_transformation', + 'label': 'Hide browser transformation'|trans, + 'checked': hide_transformation is not empty, + 'onclick': false, + 'html_field_id': 'hide_transformation_' ~ unique_id + } only %} +
+ +
+ {{ Util_getRadioFields( + 'geoOption', + { + 'GEOM': 'Geometry'|trans, + 'WKT': 'Well Known Text'|trans, + 'WKB': 'Well Known Binary'|trans + }, + geo_option, + true, + true, + '', + 'geoOption_' ~ unique_id + ) }} +
+ +
+
+ +
+ +
+ {# slider effect div #} + diff --git a/templates/display/results/show_all_checkbox.twig b/templates/display/results/show_all_checkbox.twig new file mode 100644 index 0000000000..b2674d3893 --- /dev/null +++ b/templates/display/results/show_all_checkbox.twig @@ -0,0 +1,13 @@ + diff --git a/templates/display/results/table_navigation_button.twig b/templates/display/results/table_navigation_button.twig new file mode 100644 index 0000000000..eb4fa42e64 --- /dev/null +++ b/templates/display/results/table_navigation_button.twig @@ -0,0 +1,12 @@ + diff --git a/templates/display/results/value_display.twig b/templates/display/results/value_display.twig new file mode 100644 index 0000000000..35640b91ca --- /dev/null +++ b/templates/display/results/value_display.twig @@ -0,0 +1,3 @@ + diff --git a/test/classes/Display/ResultsTest.php b/test/classes/Display/ResultsTest.php index ed0d820019..f620c358d7 100644 --- a/test/classes/Display/ResultsTest.php +++ b/test/classes/Display/ResultsTest.php @@ -111,25 +111,37 @@ class ResultsTest extends PmaTestCase * @param string $title text for button * @param integer $pos position for next query * @param string $html_sql_query query ready for display - * @param string $output output from the _getTableNavigationButton - * method * * @return void * * @dataProvider providerForTestGetTableNavigationButton */ public function testGetTableNavigationButton( - $caption, $title, $pos, $html_sql_query, $output + $caption, $title, $pos, $html_sql_query ) { $GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons'; $_SESSION[' PMA_token '] = 'token'; - $this->assertEquals( - $output, - $this->_callPrivateFunction( - '_getTableNavigationButton', - array(&$caption, $title, $pos, $html_sql_query, true) - ) + $actual = $this->_callPrivateFunction( + '_getTableNavigationButton', + array(&$caption, $title, $pos, $html_sql_query, true) + ); + + $this->assertContains( + '', + $actual + ); + $this->assertContains( + 'name="sql_query" value="SELECT * FROM `pma_bookmark` WHERE 1"', + $actual + ); + $this->assertContains( + 'name="pos" value="1"', + $actual + ); + $this->assertContains( + 'value="btn" title="Submit"', + $actual ); } @@ -146,18 +158,6 @@ class ResultsTest extends PmaTestCase 'Submit', 1, 'SELECT * FROM `pma_bookmark` WHERE 1', - '' ) ); } @@ -1197,12 +1197,30 @@ class ResultsTest extends PmaTestCase $this->object->__set('goto', $goto); $this->object->__set('unique_id', $unique_id); - $this->assertEquals( - $output, - $this->_callPrivateFunction( - '_getShowAllCheckboxForTableNavigation', - array(false, $html_sql_query) - ) + $result = $this->_callPrivateFunction( + '_getShowAllCheckboxForTableNavigation', + array(false, $html_sql_query) + ); + + $this->assertContains( + 'name="db" value="' . $db . '"', + $result + ); + $this->assertContains( + 'name="table" value="' . $table . '"', + $result + ); + $this->assertContains( + 'name="sql_query" value="' . $html_sql_query . '"', + $result + ); + $this->assertContains( + 'name="goto" value="' . $goto . '"', + $result + ); + $this->assertContains( + '', + $result ); } @@ -1473,11 +1491,13 @@ class ResultsTest extends PmaTestCase array(), 0, 'binary', - '' + . 'class="disableAjax">[BLOB - 4 B]' . PHP_EOL + . '' . PHP_EOL ), array( 'noblob', @@ -1494,8 +1514,9 @@ class ResultsTest extends PmaTestCase array(), 0, 'binary', - '' + '' . PHP_EOL ), array( 'noblob', @@ -1512,8 +1533,12 @@ class ResultsTest extends PmaTestCase array(), 0, 0, - '' + '' . PHP_EOL ), array( 'all',
+ NULL + +
+ {{ Url_getHiddenInputs(db, table) }} + + + + + + + +
+
+
+ {{ Url_getHiddenInputs(db, table) }} + + + + + {{ input_for_real_end|raw }} + +
+
+ {{ value|raw }} +
' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' . PHP_EOL + . ' [BLOB - 4 B]' - . '1001' . PHP_EOL + . ' 1001' . PHP_EOL + . 'NULL' . PHP_EOL + . ' NULL' . PHP_EOL + . '