Skip to content

Commit

Permalink
fix group filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Mar 4, 2024
1 parent 3492f1f commit ed63183
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
19 changes: 17 additions & 2 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,29 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null):
$fieldIsActive = $filterConfig[$column]['active'];
}
}
$this->searchFilters[$column] = [

$attribute = [
'type' => $type,
'label' => \App\Lib\Util\StringUtilities::columnKey($modelname, $column, $vv_tz, true),
'active' => $fieldIsActive,
'order' => 99 // this is the default
];

// The column name should always go first, then the description will follow.
if($column == 'name') {
$this->searchFilters = [ $column => $attribute, ...$this->searchFilters];
} else if ($column == 'description') {
if(isset($this->searchFilters['name'])) {
$this->searchFilters = array_slice($this->searchFilters, 0, 1)
+ [ $column => $attribute ]
+ array_slice($this->searchFilters, 1);
} else {
$this->searchFilters = [ $column => $attribute, ...$this->searchFilters];
}
} else {
$this->searchFilters[$column] = $attribute;
}

// For the date fields we search ranges
if($type === 'timestamp') {
$this->searchFilters[$column]['alias'][] = $column . '_starts_at';
Expand Down
3 changes: 2 additions & 1 deletion app/src/Lib/Traits/TableMetaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected function filterMetadataFields() {
'source_name_id',
'source_pronoun_id',
'source_telephone_number_id',
'source_url_id'
'source_url_id',
'owners_group_id'
];

$newa = array();
Expand Down
9 changes: 9 additions & 0 deletions app/src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ public function initialize(array $config): void {
'class' => 'GroupTypeEnum'
]
]);

$this->setFilterConfig([
'identifier' => [
'type' => 'relatedModel',
'model' => 'Identifier',
'active' => true,
'order' => 4
]
]);

$this->setPermissions([
// XXX update for couAdmins, etc
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public function recalculateStatus(int $id): ?string {
// Locked status cannot be recalculated. This isn't an error, per se.
if($person->status == StatusEnum::Locked) {
$this->llog('trace', 'Not recalculating Person " . $person->id . " status since the record is locked');
return $curStatus;
return $person->status;
}

// Update the Person status
Expand Down
14 changes: 2 additions & 12 deletions app/templates/element/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

// The populated variables are in plural while the column names are singular
// Convention: It is a prerequisite that the vvar should be the plural of the column name
$populated_vvar = Inflector::pluralize($key);
$populated_vvar = lcfirst(Inflector::pluralize(Inflector::camelize($key)));
$button_label = isset($$populated_vvar) ?
$$populated_vvar[ $search_params[$key] ] :
(is_array($search_params[$key]) ? 'Range' : $search_params[$key]);
Expand Down Expand Up @@ -146,16 +146,6 @@
$field_datetime_columns = [];

$inactiveFiltersCount = 0; // for re-balancing the columns and submit buttons

if(!empty($columns)) {
// The searchable attributes will be sorted first alphabetically
asort($vv_searchable_attributes);
// Sort the order attribute
uasort($vv_searchable_attributes, function ($item1, $item2) {
if ($item1['order'] == $item2['order']) return 0;
return $item1['order'] < $item2['order'] ? -1 : 1;
});
}

foreach($vv_searchable_attributes as $key => $options) {
if($options['type'] == 'boolean') {
Expand Down Expand Up @@ -226,7 +216,7 @@

// The populated variables are in plural while the column names are singular
// Convention: It is a prerequisite that the vvar should be the plural of the column name
$populated_vvar = Inflector::pluralize($key);
$populated_vvar = lcfirst(Inflector::pluralize(Inflector::camelize($key)));
if(isset($$populated_vvar)) {
// If we have an AutoViewVar matching the name of this key,
// convert to a select
Expand Down

0 comments on commit ed63183

Please sign in to comment.