fix: [brood:preview] Restored searching capability on browsing

develop-unstable
Sami Mokaddem 2022-11-29 11:51:03 +01:00
parent 9ad328d962
commit e5080e6fda
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 38 additions and 12 deletions

View File

@ -14,6 +14,18 @@ class BroodsController extends AppController
public $quickFilterFields = [['Broods.name' => true], 'Broods.uuid', ['Broods.description' => true]];
public $containFields = ['Organisations'];
protected $previewScopes = [
'organisations' => [
'quickFilterFields' => ['uuid', ['name' => true], ],
],
'individuals' => [
'quickFilterFields' => ['uuid', ['email' => true], ['first_name' => true], ['last_name' => true], ],
],
'sharingGroups' => [
'quickFilterFields' => ['uuid', ['name' => true], ],
],
];
public function index()
{
$this->CRUD->index([
@ -96,8 +108,9 @@ class BroodsController extends AppController
public function previewIndex($id, $scope)
{
if (!in_array($scope, ['organisations', 'individuals', 'sharingGroups'])) {
throw new MethodNotAllowedException(__('Invalid scope. Valid options are: organisations, individuals, sharing_groups'));
$validScopes = array_keys($this->previewScopes);
if (!in_array($scope, $validScopes)) {
throw new MethodNotAllowedException(__('Invalid scope. Valid options are: {0}', implode(', ', $validScopes)));
}
$filter = $this->request->getQuery('quickFilter');
$data = $this->Broods->queryIndex($id, $scope, $filter);
@ -108,6 +121,12 @@ class BroodsController extends AppController
return $this->RestResponse->viewData($data, 'json');
} else {
$data = $this->CustomPagination->paginate($data);
$optionFilters = ['quickFilter'];
$CRUDParams = $this->ParamHandler->harvestParams($optionFilters);
$CRUDOptions = [
'quickFilters' => $this->previewScopes[$scope]['quickFilterFields'],
];
$this->CRUD->setQuickFilterForView($CRUDParams, $CRUDOptions);
$this->set('data', $data);
$this->set('brood_id', $id);
if ($this->request->is('ajax')) {

View File

@ -1119,17 +1119,9 @@ class CRUDComponent extends Component
public function setQuickFilters(array $params, \Cake\ORM\Query $query, array $options): \Cake\ORM\Query
{
$this->setQuickFilterForView($params, $options);
$quickFilterFields = $options['quickFilters'];
$queryConditions = [];
$this->Controller->set('quickFilter', empty($quickFilterFields) ? [] : $quickFilterFields);
if ($this->metaFieldsSupported() && !empty($options['quickFilterForMetaField']['enabled'])) {
$this->Controller->set('quickFilterForMetaField', [
'enabled' => $options['quickFilterForMetaField']['enabled'] ?? false,
'wildcard_search' => $options['quickFilterForMetaField']['enabled'] ?? false,
]);
}
if (!empty($params['quickFilter']) && !empty($quickFilterFields)) {
$this->Controller->set('quickFilterValue', $params['quickFilter']);
$queryConditions = $this->genQuickFilterConditions($params, $quickFilterFields);
if ($this->metaFieldsSupported() && !empty($options['quickFilterForMetaField']['enabled'])) {
@ -1139,10 +1131,25 @@ class CRUDComponent extends Component
}
$query->where(['OR' => $queryConditions]);
}
return $query;
}
public function setQuickFilterForView(array $params, array $options): void
{
$quickFilterFields = $options['quickFilters'];
$this->Controller->set('quickFilter', empty($quickFilterFields) ? [] : $quickFilterFields);
if ($this->metaFieldsSupported() && !empty($options['quickFilterForMetaField']['enabled'])) {
$this->Controller->set('quickFilterForMetaField', [
'enabled' => $options['quickFilterForMetaField']['enabled'] ?? false,
'wildcard_search' => $options['quickFilterForMetaField']['enabled'] ?? false,
]);
}
if (!empty($params['quickFilter']) && !empty($quickFilterFields)) {
$this->Controller->set('quickFilterValue', $params['quickFilter']);
} else {
$this->Controller->set('quickFilterValue', '');
}
return $query;
}
public function genQuickFilterConditions(array $params, array $quickFilterFields): array