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
filter the active GroupMembers
Ioannis committed Mar 16, 2024
commit 04a8bb2a01d49d2b98e8606fc350647b88c8d57b
13 changes: 9 additions & 4 deletions app/src/Controller/ApiV2Controller.php
@@ -305,13 +305,18 @@ public function index() {
// $table = the actual table object
$table = $this->$modelsName;

$reqParameters = [];
$pickerMode = false;
if($this->request->getQuery('picker') !== null
&& $this->request->is('ajax')) {
$pickerMode = filter_var($this->request->getQuery('picker'), FILTER_VALIDATE_BOOLEAN);
if($this->request->is('ajax')) {
$reqParameters = [...$this->request->getQuery()];
if($this->request->getQuery('picker') !== null) {
$pickerMode = filter_var($this->request->getQuery('picker'), FILTER_VALIDATE_BOOLEAN);
}
}


// Construct the Query
$query = $this->getIndexQuery($pickerMode);
$query = $this->getIndexQuery($pickerMode, $reqParameters);

if(method_exists($table, 'findIndexed')) {
$query = $table->findIndexed($query);
35 changes: 24 additions & 11 deletions app/src/Lib/Traits/IndexQueryTrait.php
@@ -30,6 +30,7 @@
namespace App\Lib\Traits;

use App\Lib\Enum\StatusEnum;
use App\Lib\Util\StringUtilities;
use Cake\Database\Expression\QueryExpression;
use Cake\ORM\Query;

@@ -100,12 +101,13 @@ public function constructGetIndexContains(Query $query): object {
/**
* Build the Index Query
*
* @params boolean $picker_mode True for OR and False for AND. AND is the default behavior
* @params boolean $pickerMode True for OR and False for AND. AND is the default behavior
* @params array $requestParams
*
* @return object Cake ORM Query object
* @since COmanage Registry v5.0.0
*/
public function getIndexQuery(bool $picker_mode = false): object {
public function getIndexQuery(bool $pickerMode = false, array $requestParams = []): object {
// $this->name = Models
$modelsName = $this->name;
// $table = the actual table object
@@ -118,7 +120,7 @@ public function getIndexQuery(bool $picker_mode = false): object {
$newexp = $query->newExpr();
// The searchable attributes can have an AND or an OR conjunction. The first one is used from the filtering block
// while the second one from the picker vue module.
$newexp = $newexp->setConjunction($picker_mode ? 'OR' : 'AND');
$newexp = $newexp->setConjunction($pickerMode ? 'OR' : 'AND');

if(!empty($link->attr) && !empty($link->value)) {
// If a link attribute is defined but no value is provided, then query
@@ -131,7 +133,7 @@ public function getIndexQuery(bool $picker_mode = false): object {
// Get Associated Model Data
$query = $this->constructGetIndexContains($query);

// SearchFilterTrait
// Attributes to search for
if(method_exists($table, 'getSearchableAttributes')) {
$searchableAttributes = $table->getSearchableAttributes($this->name,
$this->viewBuilder()->getVar('vv_tz'));
@@ -157,17 +159,28 @@ public function getIndexQuery(bool $picker_mode = false): object {
}
}

if($picker_mode) {
// Get only the active People
// XXX Perhaps we need to make this a configuration
$query = $query->where(fn(QueryExpression $exp, Query $query) => $exp->in($table->getAlias().'.status', [StatusEnum::Active, StatusEnum::GracePeriod]));
}

// Append the new conditions
$query = $query->where($newexp);
}
}

// Filter results that will occur from the searchable attributes
if($pickerMode) {
// Get only the active People
// XXX Perhaps we need to make this a configuration
$query = $query->where(fn(QueryExpression $exp, Query $query) => $exp->in($table->getAlias().'.status', [StatusEnum::Active, StatusEnum::GracePeriod]));

// Specific expressions per view
$query = match($requestParams['for'] ?? '') {
// GroupMembers Add view: We need to filter the active members
'GroupMembers' => $query->leftJoinWith('GroupMembers', fn($q) => $q->where(['GroupMembers.group_id' => (int)$requestParams['groupid'] ?? -1]))
->where($this->getTableLocator()->get('GroupMembers')->checkValidity($query))
->where(fn(QueryExpression $exp, Query $query) => $exp->isNull('GroupMembers.' . StringUtilities::classNameToForeignKey($table->getAlias()))),
// Just return the query
default => $query
};
}

// Special Authenticated Identifier filtering
if($modelsName == 'AuthenticationEvents') {
// Special case for filtering on authenticated identifier. There is a
@@ -177,7 +190,7 @@ public function getIndexQuery(bool $picker_mode = false): object {
// populated by the table (or something similar).

if($this->getRequest()->getQuery('authenticated_identifier')) {
$query = $query->where(['authenticated_identifier' => \App\Lib\Util\StringUtilities::urlbase64decode($this->getRequest()->getQuery('authenticated_identifier'))]);
$query = $query->where(['authenticated_identifier' => StringUtilities::urlbase64decode($this->getRequest()->getQuery('authenticated_identifier'))]);
} else {
// We only allow unfiltered queries for platform users

32 changes: 31 additions & 1 deletion app/src/Lib/Traits/QueryModificationTrait.php
@@ -29,6 +29,10 @@

namespace App\Lib\Traits;

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

trait QueryModificationTrait {
// Array of associated models to copy during a duplicate
private $duplicateContains = false;
@@ -47,7 +51,33 @@ trait QueryModificationTrait {

// Array of associated models to pull during a view
private $viewContains = false;



/**
* Construct the checkValidity for the fields valid_from and valid_through
*
* @param Query $query
*
* @return QueryExpression
* @since COmanage Registry v5.0.0
*/
public function checkValidity(Query $query): QueryExpression {
$fieldModelPrefix = Inflector::pluralize(substr($this->getEntityClass(), strrpos($this->getEntityClass(), '\\')+1));

$exp = $query->newExpr();
$orValidFromConditions = $exp->or(
fn(QueryExpression $or) => $or->isNull($fieldModelPrefix . '.valid_from')
->lt($fieldModelPrefix . '.valid_from', date('Y-m-d H:i:s'))
);
$orValidThroughConditions = $exp->or(
fn(QueryExpression $or) => $or->isNull($fieldModelPrefix . '.valid_through')
->gt($fieldModelPrefix . '.valid_through', date('Y-m-d H:i:s'))
);

return $exp->add($orValidFromConditions)
->add($orValidThroughConditions);
}

/**
* Obtain the set of associated models to copy during a duplicate.
*
7 changes: 4 additions & 3 deletions app/src/Lib/Traits/SearchFilterTrait.php
@@ -40,18 +40,19 @@ trait SearchFilterTrait {
private array $searchFilters = [];
// Optional filter configuration that dictates display state and allows for related models
private array $filterConfig = [];

/**
* Build the query join associations
*
* @param Query $query
* @param string $attribute
* @param ServerRequest $request
* @param string $joinType
*
* @return object Cake ORM Query object
* @since COmanage Registry v5.0.0
*/
public function addJoins(Query $query, string $attribute, ServerRequest $request): object {
public function addJoins(Query $query, string $attribute, ServerRequest $request, string $joinType = 'INNER'): object {
// not a permitted attribute
if(empty($this->searchFilters[$attribute])
|| $request->getQuery($attribute) === null
@@ -72,7 +73,7 @@ public function addJoins(Query $query, string $attribute, ServerRequest $request
// $mtable_alias . '.' . 'deleted IS NOT TRUE',
// $mtable_alias . '.' . $changelog_fk . ' IS NULL'
],
'type' => 'INNER'
'type' => $joinType
]]);
}

35 changes: 14 additions & 21 deletions app/src/Model/Table/GroupMembersTable.php
@@ -29,9 +29,12 @@

namespace App\Model\Table;

use App\Model\Entity\GroupMember;
use Cake\Database\Expression\QueryExpression;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Utility\Inflector;
use Cake\Validation\Validator;
use \App\Lib\Enum\ActionEnum;
use \App\Lib\Enum\GroupTypeEnum;
@@ -138,7 +141,7 @@ public function buildRules(RulesChecker $rules): RulesChecker {
* @return string Display field
*/

public function generateDisplayField(\App\Model\Entity\GroupMember $entity): string {
public function generateDisplayField(GroupMember $entity): string {
// Pull the group and person information to build a more useful display string

return __d('field', 'group_membership', [$entity->person->primary_name->full_name, $entity->group->name]);
@@ -166,30 +169,20 @@ public function isMember(int $groupId,
'group_id' => $groupId,
'person_id' => $personId
];

if($checkValidity) {
// Only pull currently valid group memberships

$conditions['AND'][] = [
'OR' => [
'valid_from IS NULL',
'valid_from < ' => date('Y-m-d H:i:s', time())
]
];
$conditions['AND'][] = [
'OR' => [
'valid_through IS NULL',
'valid_through > ' => date('Y-m-d H:i:s', time())
]
];
}


if($direct) {
// XXX need to add pipelines here eventually
$conditions[] = 'group_nesting_id IS NULL';
}

$count = $this->find()->where($conditions)->count();

$query = $this->find()->where($conditions);

if($checkValidity) {
$queryExp = $this->checkValidity($query);
$query = $query->where($queryExp);
}

$count = $query->count();

// When !$direct, we could get more than one row back
return ($count > 0);
14 changes: 9 additions & 5 deletions app/src/View/Helper/FieldHelper.php
@@ -588,13 +588,16 @@ protected function formNameDiv(string $fieldName,
/**
* Emit a People Autocomplete (PrimeVue) control for selecting a person
*
* @since COmanage Registry v5.0.0
* @param string $fieldName Field name of input field
* @param string $type Type of person autocomplete to use (XXX should be an enum, and a default should be set)
* @param string $fieldName Field name of input field
* @param array $viewConfigParameters
* @param string $type Type of person autocomplete to use (XXX should be an enum, and a default should be set)
*
* @return string Source HTML
* @since COmanage Registry v5.0.0
*
*/

public function peopleAutocompleteControl(string $fieldName, string $type = 'coperson'): string {
public function peopleAutocompleteControl(string $fieldName, array $viewConfigParameters = [], string $type = 'coperson'): string {
if($this->action == 'view') {
// return the member name value as plaintext
$coptions = ['type' => 'text'];
@@ -631,7 +634,8 @@ public function peopleAutocompleteControl(string $fieldName, string $type = 'cop
$autocompleteArgs = [
'fieldName' => $fieldName,
'type' => $type,
'htmlId' => $autoCompleteFieldName
'htmlId' => $autoCompleteFieldName,
'viewConfigParameters' => $viewConfigParameters
];

// Create a hidden field to hold our value and emit the autocomplete widget
6 changes: 5 additions & 1 deletion app/templates/GroupMembers/fields.inc
@@ -27,7 +27,11 @@

if($vv_action == 'add') {
// Produce the autocomplete people selector on 'add'
print $this->Field->peopleAutocompleteControl('person_id');
print $this->Field->peopleAutocompleteControl('person_id', [
'for' => 'GroupMembers',
'action' => $vv_action,
'groupId' => $this->getRequest()?->getQuery('group_id')
]);

// XXX As a temporary hack for development, we accept a manually entered Person ID
// XXX leave here temporarily.
6 changes: 4 additions & 2 deletions app/templates/element/autocompletePeople.php
@@ -29,7 +29,8 @@
$fieldName = $fieldName ?? '';
$type = $type ?? '';
$htmlId = $htmlId ?? '';

$viewConfigParameters = $viewConfigParameters ?? [];

// Get the CSRF Token in JavaScript
$token = $this->request->getAttribute('csrfToken');
// Load my helper functions
@@ -54,8 +55,9 @@
cosettings: <?= json_encode($cosettings) ?>
},
api: {
viewConfigParameters: <?= json_encode($viewConfigParameters) ?>,
webroot: '<?= $this->request->getAttribute('webroot') ?>',
searchPeople: `<?= $this->request->getAttribute('webroot') ?>api/ajax/v2/people?co_id=<?= $vv_cur_co->id ?>&extended=PrimaryName,Identifiers,EmailAddresses&picker=on`
searchPeople: `<?= $this->request->getAttribute('webroot') ?>api/ajax/v2/people?co_id=<?= $vv_cur_co->id ?>&picker=on&for=<?= $viewConfigParameters['for'] ?>`
}
}

@@ -63,10 +63,17 @@ export default {
const url = new URL(urlString);
let queryParams = url.searchParams;
// Query parameters
queryParams.append('extended', 'PrimaryName,Identifiers,EmailAddresses')
queryParams.append('identifier', query)
queryParams.append('mail', query)
queryParams.append('given', query)
queryParams.append('family', query)
if(this.api.viewConfigParameters.groupId != undefined) {
queryParams.append('groupid', this.api.viewConfigParameters.groupId)
}
if(this.api.viewConfigParameters.action != undefined) {
queryParams.append('action', this.api.viewConfigParameters.action)
}
// Pagination
// XXX Move this to configuration
queryParams.append('limit', this.limit)