new: [CRUD:Filtering] Added support of options in index filtering modal
parent
d823190624
commit
cadb56eb07
|
@ -51,7 +51,9 @@ class CRUDComponent extends Component
|
||||||
$options['filters'][] = 'filteringTags';
|
$options['filters'][] = 'filteringTags';
|
||||||
}
|
}
|
||||||
$optionFilters = [];
|
$optionFilters = [];
|
||||||
$optionFilters += empty($options['filters']) ? [] : $options['filters'];
|
$optionFilters += array_map(function($filter) {
|
||||||
|
return is_array($filter) ? $filter['name'] : $filter;
|
||||||
|
}, empty($options['filters']) ? [] : $options['filters']);
|
||||||
foreach ($optionFilters as $i => $filter) {
|
foreach ($optionFilters as $i => $filter) {
|
||||||
$optionFilters[] = "{$filter} !=";
|
$optionFilters[] = "{$filter} !=";
|
||||||
$optionFilters[] = "{$filter} >=";
|
$optionFilters[] = "{$filter} >=";
|
||||||
|
@ -259,6 +261,13 @@ class CRUDComponent extends Component
|
||||||
foreach ($filtersConfigRaw as $fieldConfig) {
|
foreach ($filtersConfigRaw as $fieldConfig) {
|
||||||
if (is_array($fieldConfig)) {
|
if (is_array($fieldConfig)) {
|
||||||
$filtersConfig[$fieldConfig['name']] = $fieldConfig;
|
$filtersConfig[$fieldConfig['name']] = $fieldConfig;
|
||||||
|
if (!empty($fieldConfig['options'])) {
|
||||||
|
if (is_string($fieldConfig['options'])) {
|
||||||
|
$filtersConfig[$fieldConfig['name']]['options'] = $this->Table->{$fieldConfig['options']}($this->Controller->ACL->getUser());
|
||||||
|
} else {
|
||||||
|
$filtersConfig[$fieldConfig['name']]['options'] = $fieldConfig['options'];
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
|
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
|
||||||
}
|
}
|
||||||
|
@ -1368,7 +1377,12 @@ class CRUDComponent extends Component
|
||||||
protected function setRelatedCondition($query, $modelName, $fieldName, $filterValue)
|
protected function setRelatedCondition($query, $modelName, $fieldName, $filterValue)
|
||||||
{
|
{
|
||||||
return $query->matching($modelName, function (\Cake\ORM\Query $q) use ($fieldName, $filterValue) {
|
return $query->matching($modelName, function (\Cake\ORM\Query $q) use ($fieldName, $filterValue) {
|
||||||
return $this->setValueCondition($q, $fieldName, $filterValue);
|
if (is_array($filterValue)) {
|
||||||
|
$query = $this->setInCondition($q, $fieldName, $filterValue);
|
||||||
|
} else {
|
||||||
|
$query = $this->setValueCondition($q, $fieldName, $filterValue);
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,22 @@ $filteringForm = $this->Bootstrap->table(
|
||||||
'label' => '',
|
'label' => '',
|
||||||
'class' => 'fieldValue form-control-sm'
|
'class' => 'fieldValue form-control-sm'
|
||||||
];
|
];
|
||||||
if (!empty($filtersConfig[$fieldName]['multiple'])) {
|
if (!empty($filtersConfig[$fieldName])) {
|
||||||
$fieldData['type'] = 'dropdown';
|
if (!empty($filtersConfig[$fieldName]['options'])) {
|
||||||
$fieldData['multiple'] = true;
|
$fieldData['options'] = $filtersConfig[$fieldName]['options'];
|
||||||
$fieldData['select2'] = [
|
}
|
||||||
'tags' => true,
|
if (!empty($filtersConfig[$fieldName]['select2'])) {
|
||||||
'tokenSeparators' => [',', ' '],
|
$fieldData['type'] = 'dropdown';
|
||||||
];
|
$fieldData['select2'] = true;
|
||||||
|
}
|
||||||
|
if (!empty($filtersConfig[$fieldName]['multiple'])) {
|
||||||
|
$fieldData['type'] = 'dropdown';
|
||||||
|
$fieldData['multiple'] = true;
|
||||||
|
$fieldData['select2'] = [
|
||||||
|
'tags' => true,
|
||||||
|
'tokenSeparators' => [',', ' '],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->Form->setTemplates([
|
$this->Form->setTemplates([
|
||||||
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
|
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
|
||||||
|
@ -187,6 +196,7 @@ echo $this->Bootstrap->modal([
|
||||||
$row = $filteringTable.find('td > span.fieldName').filter(function() {
|
$row = $filteringTable.find('td > span.fieldName').filter(function() {
|
||||||
return $(this).data('fieldname') == field
|
return $(this).data('fieldname') == field
|
||||||
}).closest('tr')
|
}).closest('tr')
|
||||||
|
$row.addClass('table-warning')
|
||||||
$row.find('.fieldOperator').val(operator)
|
$row.find('.fieldOperator').val(operator)
|
||||||
const $formElement = $row.find('.fieldValue');
|
const $formElement = $row.find('.fieldValue');
|
||||||
if ($formElement.attr('type') === 'datetime-local') {
|
if ($formElement.attr('type') === 'datetime-local') {
|
||||||
|
@ -195,7 +205,10 @@ echo $this->Bootstrap->modal([
|
||||||
let newOptions = [];
|
let newOptions = [];
|
||||||
value.forEach(aValue => {
|
value.forEach(aValue => {
|
||||||
const existingOption = $formElement.find('option').filter(function() {
|
const existingOption = $formElement.find('option').filter(function() {
|
||||||
return $(this).val() === aValue
|
if ($(this).val() === aValue) {
|
||||||
|
$(this).prop('selected', true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (existingOption.length == 0) {
|
if (existingOption.length == 0) {
|
||||||
newOptions.push(new Option(aValue, aValue, true, true))
|
newOptions.push(new Option(aValue, aValue, true, true))
|
||||||
|
|
Loading…
Reference in New Issue