Skip to content

Commit

Permalink
add field ordering. Fix labeling lexicals.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed Oct 5, 2023
1 parent e30366a commit 532235f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
6 changes: 4 additions & 2 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null):
'type' => 'string', // XXX for now - this needs to be looked up.
'label' => \App\Lib\Util\StringUtilities::columnKey($fieldName, $field, $vv_tz, true),
'active' => isset($f['active']) ? $f['active'] : true,
'model' => $f['model']
'model' => $f['model'],
'order' => $f['order']
];
}
}
Expand All @@ -93,7 +94,8 @@ public function getSearchableAttributes(string $controller, string $vv_tz=null):
$this->searchFilters[$column] = [
'type' => $type,
'label' => \App\Lib\Util\StringUtilities::columnKey($modelname, $column, $vv_tz, true),
'active' => $fieldIsActive
'active' => $fieldIsActive,
'order' => 99 // this is the default
];

// For the date fields we search ranges
Expand Down
8 changes: 7 additions & 1 deletion app/src/Lib/Util/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ public static function classNameToForeignKey(string $className): string {

public static function columnKey($modelsName, $c, $tz=null, $useCustomClMdlLabel=false): string {
if(strpos($c, "_id", strlen($c)-3)) {
$postfix = "";
if($c == "parent_id") {
// This means we are working with a model that implements a Tree behavior
$postfix = " ({$modelsName})";
}

// Key is of the form field_id, use .ct label instead
$k = self::foreignKeyToClassName($c);

return __d('controller', $k, [1]);
return __d('controller', $k, [1]) . $postfix;
}

// Look for a model specific key first
Expand Down
27 changes: 16 additions & 11 deletions app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,31 @@ public function initialize(array $config): void {
'family' => [
'type' => 'relatedModel',
'model' => 'Name',
'active' => true
'active' => true,
'order' => 2
],
'given' => [
'type' => 'relatedModel',
'model' => 'Name',
'active' => true
'active' => true,
'order' => 1
],
'mail' => [
'type' => 'relatedModel',
'model' => 'EmailAddress',
'active' => true
'active' => true,
'order' => 3
],
'identifier' => [
'type' => 'relatedModel',
'model' => 'Identifier',
'active' => true
'active' => true,
'order' => 4
],
'timezone' => [
'type' => 'field',
'active' => false
'active' => false,
'order' => 99
]
]);

Expand Down Expand Up @@ -437,9 +442,9 @@ public function marshalProvisioningData(int $id): array {

$identifiers = [];

foreach($ret['data']->identifiers as $id) {
if($id->status == SuspendableStatusEnum::Active) {
$identifiers[] = $id;
foreach($ret['data']->identifiers as $ident) {
if($ident->status == SuspendableStatusEnum::Active) {
$identifiers[] = $ident;
}
}

Expand All @@ -462,9 +467,9 @@ public function marshalProvisioningData(int $id): array {

$identifiers = [];

foreach($ret['data']->identifiers as $id) {
if($id->status == SuspendableStatusEnum::Active) {
$identifiers[] = $id;
foreach($ret['data']->identifiers as $ident) {
if($ident->status == SuspendableStatusEnum::Active) {
$identifiers[] = $ident;
}
}

Expand Down
31 changes: 18 additions & 13 deletions app/templates/element/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<button class="top-filters-active-filter deletebutton spin btn btn-default btn-sm" data-identifier="<?= $data_identifier ?>" type="button" aria-controls="<?php print $aria_controls; ?>" title="<?= __d('operation', 'clear.filters',[2]); ?>">
<em class="material-icons" aria-hidden="true">cancel</em>
<span class="top-filters-active-filter-title">
<?= !empty($columns[$key]['label']) ? $columns[$key]['label'] : $vv_searchable_attributes[$key]['label'] ?>
<?= Inflector::humanize(Inflector::underscore($vv_searchable_attributes[$key]['label'] ?? $columns[$key]['label'])) ?>
</span>
<?php if($vv_searchable_attributes[$key]['type'] != 'boolean'): ?>
<span class="top-filters-active-filter-value">
Expand All @@ -148,16 +148,15 @@
$inactiveFiltersCount = 0; // for re-balancing the columns and submit buttons

if(!empty($columns)) {
// To make our filters consistently ordered with the index columns, sort the $vv_searchable_attributes
// by the keys of columns.inc $indexColumns (passed in to this View element as $indexColumns and referenced
// as "$columns"). The fields found in $columns will be placed first in the resulting array.
// The result should only include fields that exist in the original $vv_searchable_attributes array.

// XXX Turn this off. We should have more arbitrary control over the order of the filters, and for the moment
// it is better (at least for now) to let the explicitly defined filters come first.
// $vv_searchable_attributes = array_intersect_key(array_replace(array_flip(array_keys($columns)), $vv_searchable_attributes), $vv_searchable_attributes);
// 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') {
$field_booleans_columns[$key] = $options;
Expand All @@ -166,7 +165,13 @@
$field_datetime_columns[$key] = $options;
continue;
}


$label = Inflector::humanize(
Inflector::underscore(
$options['label'] ?? $columns[$key]['label']
)
);

if($options['type'] == 'date') {
// Date fields use a date picker (e.g. DOB)
// (Note that timestamps are handled specially. See below.)
Expand Down Expand Up @@ -202,15 +207,15 @@

// Create a text field to hold our date value.
print '<div class="top-filters-fields-date ' . $wrapperCssClass . '">';
print $this->Form->label($key, !empty($columns[$key]['label']) ? $columns[$key]['label'] : $options['label']);
print $this->Form->label($key, $label);
print '<div class="d-flex">';
print $this->Form->text($key, $opts) . $this->element('datePicker', $date_args);
print '</div>';
print '</div>';
} else {
// text input
$formParams = [
'label' => !empty($columns[$key]['label']) ? $columns[$key]['label'] : $options['label'],
'label' => $label,
// The default type is text, but we might convert to select below
'type' => 'text',
'value' => (!empty($query[$key]) ? $query[$key] : ''),
Expand Down

0 comments on commit 532235f

Please sign in to comment.