Skip to content

CFM-291_fix_group_filtering #162

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions app/src/Lib/Util/ArrayUtilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* COmanage Registry Array Utilities
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\Lib\Util;

use Cake\ORM\TableRegistry;
use \Cake\Utility\Inflector;

class ArrayUtilities {
/**
* Sort the associative array alphabetically
*
* @param array $assocArray
*
* @return array
* @since COmanage Registry v5.0.0
*/

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

return $assocArray;
}

}
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