Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-06-24 14:41:06 +02:00
commit e3c023ce43
7 changed files with 226 additions and 0 deletions

View File

@ -1937,6 +1937,23 @@ Using :config:option:`$cfg['NumFavoriteTables']` in your :file:`config.inc.php`
file, you can define the maximum number of favorite tables shown in the
navigation panel. Its default value is `10`.
.. _faq6_35:
6.35 How can I use the Range search feature?
---------------------------------------------------------
With the help of range search feature, one can specify a range of values for
particular column(s) while performing search operation on a table from the `Search`
tab.
To use this feature simply click on the `BETWEEN` or `NOT BETWEEN` operators
from the operator select list in front of the column name. On choosing one of the
above options, a dialog box will show up asking for the `Minimum` and `Maximum`
value for that column. Only the specified range of values will be included
in case of `BETWEEN` and excluded in case of `NOT BETWEEN` from the final results.
Note: The Range search feature will work only `Numeric` and `Date` data type columns.
.. _faqproject:
phpMyAdmin project

View File

@ -299,6 +299,11 @@ $js_messages['strSave'] = __('Save');
/* For tbl_select.js */
$js_messages['strHideSearchCriteria'] = __('Hide search criteria');
$js_messages['strShowSearchCriteria'] = __('Show search criteria');
$js_messages['strRangeSearch'] = __('Range search');
$js_messages['strColumnMax'] = __('Column maximum:');
$js_messages['strColumnMin'] = __('Column minimum:');
$js_messages['strMinValue'] = __('Minimum value:');
$js_messages['strMaxValue'] = __('Maximum value:');
/* For tbl_find_replace.js */
$js_messages['strHideFindNReplaceCriteria'] = __('Hide find and replace criteria');

View File

@ -13,6 +13,39 @@
* Table Search
*/
/**
* Checks if given data-type is numeric or date.
*
* @param string data_type Column data-type
*
* @return bool|string
*/
function PMA_checkIfDataTypeNumericOrDate(data_type)
{
// To test for numeric data-types.
var numeric_re = new RegExp(
'TINYINT|SMALLINT|MEDIUMINT|INT|BIGINT|DECIMAL|FLOAT|DOUBLE|REAL',
'i'
);
// To test for date data-types.
var date_re = new RegExp(
'DATETIME|DATE|TIMESTAMP|TIME|YEAR',
'i'
);
// Return matched data-type
if (numeric_re.test(data_type)) {
return numeric_re.exec(data_type)[0];
}
if (date_re.test(data_type)) {
return date_re.exec(data_type)[0];
}
return false;
}
/**
* Unbind all event handlers before tearing down a page
*/
@ -21,6 +54,7 @@ AJAX.registerTeardown('tbl_select.js', function () {
$("#tbl_search_form.ajax").die('submit');
$('select.geom_func').unbind('change');
$('span.open_search_gis_editor').die('click');
$('body').off('click', 'select[name*="criteriaColumnOperators"]');
});
AJAX.registerOnload('tbl_select.js', function () {
@ -224,4 +258,139 @@ AJAX.registerOnload('tbl_select.js', function () {
}
});
/**
* Ajax event handler for Range-Search.
*/
$('body').on('click', 'select[name*="criteriaColumnOperators"]', function () {
$source_select = $(this);
// Get the column name.
var column_name = $(this)
.closest('tr')
.find('th:first')
.text();
// Get the data-type of column excluding size.
var data_type = $(this)
.closest('tr')
.find('td[data-type]')
.attr('data-type');
data_type = PMA_checkIfDataTypeNumericOrDate(data_type);
// Get the operator.
var operator = $(this).val();
if ((operator == 'BETWEEN' || operator == 'NOT BETWEEN')
&& data_type
) {
var $msgbox = PMA_ajaxShowMessage();
$.ajax({
url: 'tbl_select.php',
type: 'POST',
data: {
token: $('input[name="token"]').val(),
ajax_request: 1,
db: $('input[name="db"]').val(),
table: $('input[name="table"]').val(),
column: column_name,
range_search: 1
},
success: function (response) {
PMA_ajaxRemoveMessage($msgbox);
if (response.success) {
// Get the column min value.
var min = response.column_data.min
? '(' + PMA_messages.strColumnMin +
' ' + response.column_data.min + ')'
: '';
// Get the column max value.
var max = response.column_data.max
? '(' + PMA_messages.strColumnMax +
' ' + response.column_data.max + ')'
: '';
var button_options = {};
button_options[PMA_messages.strGo] = function () {
var min_value = $('#min_value').val();
var max_value = $('#max_value').val();
if (min_value.length && max_value.length) {
var final_value = min_value + ', ' +
max_value;
} else {
final_value = '';
}
var $target_field = $source_select.closest('tr')
.find('[name*="criteriaValues"]');
// If target field is a select list.
if ($target_field.is('select')) {
$target_field.attr('value', final_value);
var $options = $target_field.find('option');
var $closest_min = null;
var $closest_max = null;
// Find closest min and max value.
$options.each(function () {
if (
$closest_min === null
|| Math.abs($(this).val() - min_value) < Math.abs($closest_min.val() - min_value)
) {
$closest_min = $(this);
}
if (
$closest_max === null
|| Math.abs($(this).val() - max_value) < Math.abs($closest_max.val() - max_value)
) {
$closest_max = $(this);
}
});
$closest_min.attr('selected', 'selected');
$closest_max.attr('selected', 'selected');
} else {
$target_field.val(final_value);
}
$(this).dialog("close");
};
button_options[PMA_messages.strCancel] = function () {
$(this).dialog("close");
};
// Display dialog box.
$('<div/>').append(
'<fieldset>' +
'<legend>' + operator + '</legend>' +
'<lablel for="min_value">' + PMA_messages.strMinValue +
'</label>' +
'<input type="text" id="min_value" />' + '<br>' +
'<span class="small_font">' + min + '</span>' + '<br>' +
'<lablel for="max_value">' + PMA_messages.strMaxValue +
'</label>' +
'<input type="text" id="max_value" />' + '<br>' +
'<span class="small_font">' + max + '</span>' +
'</fieldset>'
).dialog({
minWidth: 500,
maxHeight: 400,
modal: true,
buttons: button_options,
title: PMA_messages.strRangeSearch,
open: function () {
// Add datepicker wherever required.
PMA_addDatepicker($('#min_value'), data_type);
PMA_addDatepicker($('#max_value'), data_type);
},
close: function () {
$(this).remove();
}
});
} else {
PMA_ajaxShowMessage(response.error);
}
},
error: function (response) {
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest);
}
});
}
});
});

View File

@ -1469,5 +1469,24 @@ EOT;
);
$GLOBALS['sql_query'] = $sql_query;
}
/**
* Finds minimum and maximum value of a given column.
*
* @param string $column Column name
*
* @return array
*/
public function getColumnMinMax($column)
{
$sql_query = 'SELECT MIN(' . PMA_Util::backquote($column) . ') AS `min`, '
. 'MAX(' . PMA_Util::backquote($column) . ') AS `max` '
. 'FROM ' . PMA_Util::backquote($this->_db) . '.'
. PMA_Util::backquote($this->_table);
$result = $GLOBALS['dbi']->fetchSingleRow($sql_query);
return $result;
}
}
?>

View File

@ -31,6 +31,14 @@ $scripts->addFile('gis_data_editor.js');
$table_search = new PMA_TableSearch($db, $table, "normal");
// Request to column min-max value.
if (isset($_REQUEST['range_search'])) {
$response = PMA_Response::getInstance();
$min_max = $table_search->getColumnMinMax($_REQUEST['column']);
$response->addJSON('column_data', $min_max);
exit;
}
/**
* No selection criteria received -> display the selection form
*/

View File

@ -2693,3 +2693,7 @@ table.show_create td {
.ui-dialog {
position: fixed;
}
.small_font {
font-size: smaller;
}

View File

@ -2989,3 +2989,7 @@ table.show_create td {
.ui-dialog {
position: fixed;
}
.small_font {
font-size: smaller;
}