Skip to content

Feature cfm150 autocomplete #167

merged 38 commits into from Mar 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1999c79
Autocomplete widget added for selecting a Group member (CFM-150) (#164)
arlen Mar 6, 2024
fc0fdc4
add primevue autocomplete library dependency
Ioannis Mar 10, 2024
b0068fe
Improve/cleanup backend block search functionality
Ioannis Mar 10, 2024
66839d8
Decloupe where clause construction from join clause construction
Ioannis Mar 10, 2024
2dbc1a2
Improve filtering.Dynamically construct where clause using QueryExpre…
Ioannis Mar 10, 2024
060dfe6
Introduce IndexQueryTrait
Ioannis Mar 10, 2024
aa73e23
fix broken mveaType query.Improve Changelog.
Ioannis Mar 10, 2024
1311315
first get request
Ioannis Mar 10, 2024
a8ba9c9
add CoSettings PeoplePicker Configuration
Ioannis Mar 11, 2024
c0305b9
fix condition
Ioannis Mar 12, 2024
8b061f1
Improve FieldHelper
Ioannis Mar 12, 2024
17f32c7
Properly align grouped html controls
Ioannis Mar 12, 2024
4a805f8
Add type to emails and identifiers
Ioannis Mar 12, 2024
72171d4
Add loader.Improve fetch response handling
Ioannis Mar 13, 2024
bf41aa5
Added loader. Fixed duplicates.
Ioannis Mar 13, 2024
0d06b3d
typo fix
Ioannis Mar 13, 2024
a18c993
add filtering with given and family name. Fetch only active users.
Ioannis Mar 13, 2024
0954ba4
refactor frontend error handling
Ioannis Mar 13, 2024
941ffd2
add subfield-col css rule
Ioannis Mar 13, 2024
86fe75b
Peoplepikcer enum
Ioannis Mar 14, 2024
c8a0104
Provide access to configurations locally and globally.Improve fetch i…
Ioannis Mar 15, 2024
238de1a
fix url string
Ioannis Mar 15, 2024
0b3dec0
fix provide/inject functionality
Ioannis Mar 15, 2024
4acb787
Add a subcomponent for item-with-type and style things for easier vis…
arlen Mar 15, 2024
567d656
highlight query string
Ioannis Mar 15, 2024
f4009bb
highlighting fix
Ioannis Mar 15, 2024
a0ab929
sort methods by name
Ioannis Mar 15, 2024
af96643
Add item-id to autocomplete label and update color file (CFM-150)
arlen Mar 15, 2024
f885ca9
Add pager link "show more" to autocomplete (CFM-150)
arlen Mar 15, 2024
f02eaee
Fix label id reference for autocomplete field (CFM-150)
arlen Mar 15, 2024
134c18f
Implement pagination
Ioannis Mar 15, 2024
04a8bb2
filter the active GroupMembers
Ioannis Mar 16, 2024
e5f710a
Refactor GroupMembersTable::isMember Query construction
Ioannis Mar 16, 2024
d8eae4f
Update Group Member listing to expose add / edit / view in a modal wi…
arlen Mar 19, 2024
a8c32b0
Move the person picker to the index of the Group Member list and laun…
arlen Mar 21, 2024
123702d
Add scrolling to the autocomplete people picker (CFM-150)
arlen Mar 21, 2024
2ee562c
removed trailing semi colon
Ioannis Mar 21, 2024
c1c0f69
Change default modal title (CFM-150)
arlen Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve/cleanup backend block search functionality
Ioannis committed Mar 13, 2024
commit b0068fe5cd92ca93b1c16a3718cecca26488848c
21 changes: 9 additions & 12 deletions app/src/Controller/StandardController.php
@@ -572,40 +572,37 @@ public function index() {

// AutoViewVarsTrait
$this->populateAutoViewVars();


$query = $table->find($this->paginate['finder'] ?? 'all');
if(!empty($link->attr)) {
// If a link attribute is defined but no value is provided, then query
// where the link attribute is NULL
// "all" is the default finder. But since we are utilizing the paginator here, we will check the configuration
// for any custom finder.
$query = $table->find(
$this->paginate['finder'] ?? "all"
)->where([$table->getAlias().'.'.$link->attr => $link->value]);
} else {
$query = $table->find($this->paginate['finder'] ?? "all");
$query = $query->where([$table->getAlias().'.'.$link->attr => $link->value]);
}

// QueryModificationTrait
if(method_exists($table, "getIndexContains")
if(method_exists($table, 'getIndexContains')
&& $table->getIndexContains()) {
$query->contain($table->getIndexContains());
}

// SearchFilterTrait
if(method_exists($table, "getSearchableAttributes")) {
if(method_exists($table, 'getSearchableAttributes')) {
$searchableAttributes = $table->getSearchableAttributes($this->name, $this->viewBuilder()->getVar('vv_tz'));

if(!empty($searchableAttributes)) {
// Here we iterate over the attributes, and we add a new where clause for each one
foreach($searchableAttributes as $attribute => $options) {
if(!empty($this->request->getQuery($attribute))) {
$query = $table->whereFilter($query, $attribute, $this->request->getQuery($attribute));
} elseif (!empty($this->request->getQuery($attribute . "_starts_at"))
|| !empty($this->request->getQuery($attribute . "_ends_at"))) {
} elseif (!empty($this->request->getQuery($attribute . '_starts_at'))
|| !empty($this->request->getQuery($attribute . '_ends_at'))) {
$search_date = [];
// We allow empty for dates since we might refer to infinity (from whenever or to always)
$search_date[] = $this->request->getQuery($attribute . "_starts_at") ?? "";
$search_date[] = $this->request->getQuery($attribute . "_ends_at") ?? "";
$search_date[] = $this->request->getQuery($attribute . '_starts_at') ?? '';
$search_date[] = $this->request->getQuery($attribute . '_ends_at') ?? '';
$query = $table->whereFilter($query, $attribute, $search_date);
}
}
49 changes: 25 additions & 24 deletions app/src/Lib/Traits/SearchFilterTrait.php
@@ -29,6 +29,8 @@

namespace App\Lib\Traits;

use Cake\Database\Expression\QueryExpression;
use Cake\ORM\Query;
use Cake\Utility\Inflector;
use Cake\I18n\FrozenTime;

@@ -136,15 +138,15 @@ public function setFilterConfig(array $filterConfig): void {
/**
* Build a query where() clause for the configured attribute.
*
* @param \Cake\ORM\Query $query Cake ORM Query object
* @param Query $query Cake ORM Query object
* @param string $attribute Attribute to filter on (database name)
* @param string|array $q Value to filter on
*
* @return \Cake\ORM\Query Cake ORM Query object
* @return Query Cake ORM Query object
* @since COmanage Registry v5.0.0
*/

public function whereFilter(\Cake\ORM\Query $query, string $attribute, string|array $q): object {
public function whereFilter(Query $query, string $attribute, string|array $q): object {
// not a permitted attribute
if(empty($this->searchFilters[$attribute])) {
return $query;
@@ -175,48 +177,47 @@ public function whereFilter(\Cake\ORM\Query $query, string $attribute, string|ar
$sub = false;
// Primitive types
$search_types = ['integer', 'boolean'];
if( $this->searchFilters[$attribute]['type'] == "string") {
$search = "%" . $search . "%";
if( $this->searchFilters[$attribute]['type'] === 'string') {
$search = '%' . $search . '%';
$sub = true;
// Search type
} elseif(in_array($this->searchFilters[$attribute]['type'], $search_types, true)) {
return $query->where([$attributeWithModelPrefix => $search]);
// Date
} elseif($this->searchFilters[$attribute]['type'] == "date") {
} elseif($this->searchFilters[$attribute]['type'] === 'date') {
// Parse the date string with FrozenTime to improve error handling
return $query->where([$attributeWithModelPrefix => FrozenTime::parseDate($search, 'y-M-d')]);
// Timestamp
} elseif( $this->searchFilters[$attribute]['type'] == "timestamp") {
} elseif( $this->searchFilters[$attribute]['type'] === 'timestamp') {
// Date between dates
if(!empty($search[0])
&& !empty($search[1])) {
return $query->where(function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) use ($attributeWithModelPrefix, $search) {
return $exp->between($attributeWithModelPrefix, "'" . $search[0] . "'", "'" . $search[1] . "'");
});
// The starts at is non-empty. So the data should be greater than the starts_at date
return $query->where(fn(QueryExpression $exp, Query $query) => $exp->between($attributeWithModelPrefix, "'" . $search[0] . "'", "'" . $search[1] . "'"));
// The starts_at is non-empty. So the data should be greater than the starts_at date
} elseif(!empty($search[0])
&& empty($search[1])) {
return $query->where(function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) use ($attributeWithModelPrefix, $search) {
return $exp->gte("'" . FrozenTime::parse($search[0]) . "'", $attributeWithModelPrefix);
});
// The ends at is non-empty. So the data should be less than the ends at date
return $query->where(fn(QueryExpression $exp, Query $query) => $exp->gte("'" . FrozenTime::parse($search[0]) . "'", $attributeWithModelPrefix));
// The ends_at is non-empty. So the data should be less than the ends_at date
} elseif(!empty($search[1])
&& empty($search[0])) {
return $query->where(function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) use ($attributeWithModelPrefix, $search) {
return $exp->lte("'" . FrozenTime::parse($search[1]) . "'", $attributeWithModelPrefix);
});
return $query->where(fn(QueryExpression $exp, Query $query) => $exp->lte("'" . FrozenTime::parse($search[1]) . "'", $attributeWithModelPrefix));
} else {
// We return everything
return $query;
}

}

// Use the `lower` function to apply uniformity for the search globally
$lower = $query->func()->lower([$attributeWithModelPrefix => 'identifier']);

// This is the case of the filtering block. We are `and`-ing the conditions
// The like function applies to all string searches
// The eq function applies to everything else
$conditionsCallback = static fn(QueryExpression $exp, Query $query) =>
($sub) ? $exp->like($lower, strtolower($search))
: $exp->eq($lower, strtolower($search));

// String values
return $query->where(function (\Cake\Database\Expression\QueryExpression $exp, \Cake\ORM\Query $query) use ($attributeWithModelPrefix, $search, $sub) {
$lower = $query->func()->lower([$attributeWithModelPrefix => 'identifier']);
return ($sub) ? $exp->like($lower, strtolower($search))
: $exp->eq($lower, strtolower($search));
});
return $query->where($conditionsCallback);
}
}