Merge #19352 - [Query Generator] support for BETWEEN and NOT BETWEEN
Pull-request: #19352 Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
commit
1bf55c4d6a
@ -51,6 +51,10 @@ AJAX.registerOnload('database/multi_table_query.js', function () {
|
||||
return ['IN (...)', 'NOT IN (...)'];
|
||||
}
|
||||
|
||||
function opsWithTwoArgs (): string[] {
|
||||
return ['BETWEEN', 'NOT BETWEEN'];
|
||||
}
|
||||
|
||||
$('#update_query_button').on('click', function () {
|
||||
var columns = [];
|
||||
var tableAliases = {};
|
||||
@ -200,10 +204,13 @@ AJAX.registerOnload('database/multi_table_query.js', function () {
|
||||
});
|
||||
|
||||
const acceptsMultipleArgs: string[] = opsWithMultipleArgs();
|
||||
const acceptsTwoArgs: string[] = opsWithTwoArgs();
|
||||
$('.criteria_op').each(function () {
|
||||
$(this).on('change', function () {
|
||||
if (acceptsMultipleArgs.includes($(this).val().toString())) {
|
||||
showMultiFields($(this));
|
||||
} else if (acceptsTwoArgs.includes($(this).val().toString())) {
|
||||
showTwoFields($(this));
|
||||
} else {
|
||||
const options: JQuery<HTMLElement> = $(this).closest('table').find('.options');
|
||||
options.parent().prepend('<input type="text" class="rhs_text_val query-form__input--wide" placeholder="Enter criteria as free text"></input>');
|
||||
@ -212,14 +219,33 @@ AJAX.registerOnload('database/multi_table_query.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
function showMultiFields (opSelect: JQuery<HTMLElement>) {
|
||||
const criteriaInput: JQuery<HTMLElement> = opSelect.closest('table').find('.rhs_text_val');
|
||||
const criteriaInputCol: JQuery<HTMLElement> = criteriaInput.parent();
|
||||
const hasAtLeastOneOption: boolean = criteriaInputCol.find('.option').length > 0;
|
||||
function showTwoFields (opSelect: JQuery<HTMLElement>) {
|
||||
const critetiaRow: JQuery<HTMLElement> = opSelect.closest('table').find('.rhs_text');
|
||||
const critetiaCol: JQuery<HTMLElement> = critetiaRow.find('td').last();
|
||||
const criteriaInput: JQuery<HTMLElement> = critetiaCol.find('input').first();
|
||||
|
||||
if (!hasAtLeastOneOption) {
|
||||
criteriaInputCol.append(`
|
||||
<div class="options">
|
||||
if (critetiaCol.find('.binary').length === 0) {
|
||||
critetiaCol.empty();
|
||||
|
||||
critetiaCol.append(`
|
||||
<div class="options binary">
|
||||
<input type="text" class="val" placeholder="${window.Messages.strFirstValuePlaceholder}" value="${criteriaInput.val()}" />
|
||||
<input type="text" class="val" placeholder="${window.Messages.strSecondValuePlaceholder}" />
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
function showMultiFields (opSelect: JQuery<HTMLElement>) {
|
||||
const critetiaRow: JQuery<HTMLElement> = opSelect.closest('table').find('.rhs_text');
|
||||
const critetiaCol: JQuery<HTMLElement> = critetiaRow.find('td').last();
|
||||
const criteriaInput: JQuery<HTMLElement> = critetiaCol.find('input').first();
|
||||
|
||||
if (critetiaCol.find('.multi').length === 0) {
|
||||
critetiaCol.empty();
|
||||
|
||||
critetiaCol.append(`
|
||||
<div class="options multi">
|
||||
<div class="option">
|
||||
<input type="text" class="val" placeholder="Enter an option" value="${criteriaInput.val()}" />
|
||||
<input type="button" class="btn btn-secondary add-option" value="+" />
|
||||
@ -227,8 +253,6 @@ AJAX.registerOnload('database/multi_table_query.js', function () {
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
criteriaInput.remove();
|
||||
}
|
||||
|
||||
$('body').on('click', 'input.add-option', function () {
|
||||
|
||||
@ -29,8 +29,8 @@ function getFormatsText () {
|
||||
'NOT LIKE %...%': ' NOT LIKE \'%%%s%%\'',
|
||||
'IN (...)': ' IN (%s)',
|
||||
'NOT IN (...)': ' NOT IN (%s)',
|
||||
'BETWEEN': ' BETWEEN \'%s\'',
|
||||
'NOT BETWEEN': ' NOT BETWEEN \'%s\'',
|
||||
'BETWEEN': ' BETWEEN \'%s\' AND \'%s\'',
|
||||
'NOT BETWEEN': ' NOT BETWEEN \'%s\' AND \'%s\'',
|
||||
'REGEXP': ' REGEXP \'%s\'',
|
||||
'REGEXP ^...$': ' REGEXP \'^%s$\'',
|
||||
'NOT REGEXP': ' NOT REGEXP \'%s\''
|
||||
@ -45,6 +45,10 @@ function opsWithMultipleArgs (): string[] {
|
||||
return ['IN (...)', 'NOT IN (...)'];
|
||||
}
|
||||
|
||||
function opsWithTwoArgs (): string[] {
|
||||
return ['BETWEEN', 'NOT BETWEEN'];
|
||||
}
|
||||
|
||||
function isOpWithoutArg (op) {
|
||||
return opsWithoutArg().includes(op);
|
||||
}
|
||||
@ -53,6 +57,10 @@ function acceptsMultipleValues (op: string): boolean {
|
||||
return opsWithMultipleArgs().includes(op);
|
||||
}
|
||||
|
||||
function acceptsTwoValues (op: string): boolean {
|
||||
return opsWithTwoArgs().includes(op);
|
||||
}
|
||||
|
||||
function joinWrappingElementsWith (array: string[], char: string, separator: string = ','): string {
|
||||
let string: string = '';
|
||||
|
||||
@ -94,6 +102,11 @@ function generateCondition (criteriaDiv, table) {
|
||||
criteriaText = joinWrappingElementsWith(critertiaTextArray, '\'');
|
||||
|
||||
query += window.sprintf(formatsText[criteriaOp], criteriaText);
|
||||
} else if (acceptsTwoValues(criteriaOp)) {
|
||||
const formatsText = getFormatsText();
|
||||
const valuesInputs = criteriaDiv.find('input.val');
|
||||
|
||||
query += window.sprintf(formatsText[criteriaOp], valuesInputs[0].value, valuesInputs[1].value);
|
||||
} else {
|
||||
const formatsText = getFormatsText();
|
||||
|
||||
|
||||
@ -451,6 +451,8 @@ final class JavaScriptMessagesController implements InvocableController
|
||||
'strConfirmTd' => __('Confirm transitive dependencies'),
|
||||
'strSelectedTd' => __('Selected dependencies are as follows:'),
|
||||
'strNoTdSelected' => __('No dependencies selected!'),
|
||||
'strFirstValuePlaceholder' => __('Enter first value'),
|
||||
'strSecondValuePlaceholder' => __('Enter second value'),
|
||||
|
||||
/* For server/variables.js */
|
||||
'strSave' => __('Save'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user