Skip to content

Commit

Permalink
Merge branch 'QA_5_0' and sync Search controllers
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jul 7, 2020
2 parents 5129e48 + a355869 commit 06ffb87
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -82,6 +82,8 @@ phpMyAdmin - ChangeLog
- issue #16076 Fixed cannot edit or export TIMESTAMP column with default CURRENT_TIMESTAMP in MySQL >= 8.0.13
- issue #16226 Fix error 500 after copying a table
- issue #16222 Fixed can't use the search page when the table name has special characters
- issue #16248 Fix zoom search is not performing input validation on INT columns
- issue #16248 Fix javascript error when typing in INT fields on zoom search page

5.0.2 (2020-03-20)
- issue Fixed deprecation warning "implode(): Passing glue string after array is deprecated." function on export page
Expand Down
7 changes: 4 additions & 3 deletions js/table/change.js
Expand Up @@ -150,16 +150,17 @@ function checkForCheckbox (multiEdit) {

// used in Search page mostly for INT fields
// eslint-disable-next-line no-unused-vars
function verifyAfterSearchFieldChange (index) {
function verifyAfterSearchFieldChange (index, searchFormId) {
var $thisInput = $('input[name=\'criteriaValues[' + index + ']\']');
// validation for integer type
if ($thisInput.data('type') === 'INT') {
// Trim spaces if it's an integer
$thisInput.val($thisInput.val().trim());

var hasMultiple = $thisInput.prop('multiple');

if (hasMultiple) {
$('#tbl_search_form').validate();
$(searchFormId).validate();
// validator method for IN(...), NOT IN(...)
// BETWEEN and NOT BETWEEN
jQuery.validator.addMethod('validationFunctionForMultipleInt', function (value) {
Expand All @@ -169,7 +170,7 @@ function verifyAfterSearchFieldChange (index) {
);
validateMultipleIntField($thisInput, true);
} else {
$('#tbl_search_form').validate();
$(searchFormId).validate();
validateIntField($thisInput, true);
}
}
Expand Down
15 changes: 15 additions & 0 deletions js/table/zoom_plot_jqplot.js
Expand Up @@ -128,6 +128,17 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () {
searchedData = null;
}

// adding event listener on select after AJAX request
var comparisonOperatorOnChange = function () {
var tableRows = $('#inputSection select.column-operator');
$.each(tableRows, function (index, item) {
$(item).on('change', function () {
// eslint-disable-next-line no-undef
changeValueFieldType(this, index);
});
});
};

/**
** Input form submit on field change
**/
Expand All @@ -152,6 +163,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () {
$('#types_0').val(data.field_type);
xType = data.field_type;
$('#collations_0').val(data.field_collations);
comparisonOperatorOnChange();
Functions.addDateTimePicker();
});
});
Expand All @@ -176,6 +188,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () {
$('#types_1').val(data.field_type);
yType = data.field_type;
$('#collations_1').val(data.field_collations);
comparisonOperatorOnChange();
Functions.addDateTimePicker();
});
});
Expand All @@ -197,6 +210,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () {
$('#tableFieldsId').find('tr').eq(4).find('td').eq(3).html(data.field_value);
$('#types_2').val(data.field_type);
$('#collations_2').val(data.field_collations);
comparisonOperatorOnChange();
Functions.addDateTimePicker();
});
});
Expand All @@ -218,6 +232,7 @@ AJAX.registerOnload('table/zoom_plot_jqplot.js', function () {
$('#tableFieldsId').find('tr').eq(5).find('td').eq(3).html(data.field_value);
$('#types_3').val(data.field_type);
$('#collations_3').val(data.field_collations);
comparisonOperatorOnChange();
Functions.addDateTimePicker();
});
});
Expand Down
9 changes: 4 additions & 5 deletions libraries/classes/Controllers/Table/SearchController.php
Expand Up @@ -109,10 +109,10 @@ public function __construct(
$this->search = $search;
$this->relation = $relation;
$this->_columnNames = [];
$this->_columnNullFlags = [];
$this->_columnTypes = [];
$this->_originalColumnTypes = [];
$this->_columnCollations = [];
$this->_columnNullFlags = [];
$this->_geomColumnFlag = false;
$this->_foreigners = [];
$this->loadTableInfo();
Expand All @@ -121,10 +121,8 @@ public function __construct(
/**
* Gets all the columns of a table along with their types, collations
* and whether null or not.
*
* @return void
*/
private function loadTableInfo()
private function loadTableInfo(): void
{
// Gets the list and number of columns
$columns = $this->dbi->getColumns(
Expand Down Expand Up @@ -396,7 +394,8 @@ public function getColumnProperties($search_index, $column_index)
$type = 'INT';
}

$htmlAttributes .= " onchange= 'return verifyAfterSearchFieldChange(" . $column_index . ")'";
$htmlAttributes .= ' onchange="return '
. 'verifyAfterSearchFieldChange(' . $column_index . ', \'#tbl_search_form\')"';

$value = $this->template->render('table/search/input_box', [
'str' => '',
Expand Down
32 changes: 29 additions & 3 deletions libraries/classes/Controllers/Table/ZoomSearchController.php
Expand Up @@ -46,6 +46,9 @@ class ZoomSearchController extends AbstractController
/** @var array */
private $_columnTypes;

/** @var array */
private $_originalColumnTypes;

/** @var array */
private $_columnCollations;

Expand Down Expand Up @@ -74,6 +77,7 @@ public function __construct($response, $dbi, Template $template, $db, $table, Se
$this->relation = $relation;
$this->_columnNames = [];
$this->_columnTypes = [];
$this->_originalColumnTypes = [];
$this->_columnCollations = [];
$this->_columnNullFlags = [];
$this->_geomColumnFlag = false;
Expand Down Expand Up @@ -177,6 +181,8 @@ private function loadTableInfo(): void
$this->_columnNames[] = $row['Field'];

$type = $row['Type'];
// before any replacement
$this->_originalColumnTypes[] = mb_strtolower($type);
// check whether table contains geometric columns
if (in_array($type, $geom_types)) {
$this->_geomColumnFlag = true;
Expand Down Expand Up @@ -269,8 +275,8 @@ public function displaySelectionFormAction($dataLabel = null)
public function getDataRowAction()
{
$extra_data = [];
$row_info_query = 'SELECT * FROM `' . $_POST['db'] . '`.`'
. $_POST['table'] . '` WHERE ' . $_POST['where_clause'];
$row_info_query = 'SELECT * FROM ' . Util::backquote($_POST['db']) . '.'
. Util::backquote($_POST['table']) . ' WHERE ' . $_POST['where_clause'];
$result = $this->dbi->query(
$row_info_query . ';',
DatabaseInterface::CONNECT_USER,
Expand Down Expand Up @@ -429,9 +435,10 @@ public function getColumnProperties($search_index, $column_index)
//Gets column's type and collation
$type = $this->_columnTypes[$column_index];
$collation = $this->_columnCollations[$column_index];
$cleanType = preg_replace('@\(.*@s', '', $type);
//Gets column's comparison operators depending on column type
$typeOperators = $this->dbi->types->getTypeOperatorsHtml(
preg_replace('@\(.*@s', '', $this->_columnTypes[$column_index]),
$cleanType,
$this->_columnNullFlags[$column_index],
$selected_operator
);
Expand All @@ -447,9 +454,28 @@ public function getColumnProperties($search_index, $column_index)
'',
''
);
$htmlAttributes = '';
if (in_array($cleanType, $this->dbi->types->getIntegerTypes())) {
$extractedColumnspec = Util::extractColumnSpec(
$this->_originalColumnTypes[$column_index]
);
$is_unsigned = $extractedColumnspec['unsigned'];
$minMaxValues = $this->dbi->types->getIntegerRange(
$cleanType,
! $is_unsigned
);
$htmlAttributes = 'data-min="' . $minMaxValues[0] . '" '
. 'data-max="' . $minMaxValues[1] . '"';
$type = 'INT';
}

$htmlAttributes .= ' onchange="return '
. 'verifyAfterSearchFieldChange(' . $column_index . ', \'#zoom_search_form\')"';

$value = $this->template->render('table/search/input_box', [
'str' => '',
'column_type' => (string) $type,
'html_attributes' => $htmlAttributes,
'column_id' => 'fieldID_',
'in_zoom_search_edit' => false,
'foreigners' => $this->_foreigners,
Expand Down

0 comments on commit 06ffb87

Please sign in to comment.