Skip to content

Allow columns.inc to override filter labels (CFM-295) #101

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
6 changes: 6 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ msgstr "Display Name"
msgid "edupersonaffiliation"
msgstr "eduPersonAffiliation"

msgid "ends_at"
msgstr "Ends at:"

msgid "extension"
msgstr "Extension"

Expand Down Expand Up @@ -198,6 +201,9 @@ msgstr "Search..."
msgid "sponsor"
msgstr "Sponsor"

msgid "starts_at"
msgstr "Starts at:"

msgid "state"
msgstr "State"

Expand Down
4 changes: 2 additions & 2 deletions app/templates/Standard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
<?php
$filterArgs = array();
if(!empty($indexColumns)) {
// The keys of the $indexColumns are passed to the filters for sorting
$filterArgs['columnKeys'] = array_keys($indexColumns);
// The $indexColumns are passed to the filters for labels and sorting
$filterArgs['indexColumns'] = $indexColumns;
}
?>
<?= $this->element('filter', $filterArgs); ?>
Expand Down
44 changes: 25 additions & 19 deletions app/templates/element/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
$modelsName = $this->name;
// $modelName = Model
$modelName = Inflector::singularize($modelsName);
// $columns = the passed parameter $indexColumns as found in columns.inc; provides overrides for labels and sorting.
$columns = $indexColumns;

// Get the query string and separate the search params from the non-search params
$query = $this->request->getQueryParams();
Expand Down Expand Up @@ -115,13 +117,15 @@
(is_array($search_params[$key]) ? 'Range' : $search_params[$key]);
?>
<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">
<?= $vv_searchable_attributes[$key]['label'] ?>
</span>
<span class="top-filters-active-filter-value">
<?= filter_var($button_label, FILTER_SANITIZE_SPECIAL_CHARS); ?>
</span>
<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'] ?>
</span>
<?php if($vv_searchable_attributes[$key]['type'] != 'boolean'): ?>
<span class="top-filters-active-filter-value">
<?= filter_var($button_label, FILTER_SANITIZE_SPECIAL_CHARS); ?>
</span>
<?php endif; ?>
</button>
<?php endforeach; ?>
<?php if($hasActiveFilters): ?>
Expand All @@ -139,12 +143,12 @@
$field_booleans_columns = [];
$field_datetime_columns = [];

if(!empty($columnKeys)) {
if(!empty($columns)) {
// To make our filters consistently ordered with the index columns, sort the $vv_searchable_attributes
// by the columns.inc $indexColumns keys (passed in to this View element as "$columnKeys"). The fields found
// in columns.inc will be placed first in the resulting array. Throw out any fields from $columnKeys that didn't
// exist in the original $vv_searchable_attributes array.
$vv_searchable_attributes = array_intersect_key(array_replace(array_flip($columnKeys), $vv_searchable_attributes), $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.
$vv_searchable_attributes = array_intersect_key(array_replace(array_flip(array_keys($columns)), $vv_searchable_attributes), $vv_searchable_attributes);
}

foreach($vv_searchable_attributes as $key => $options) {
Expand All @@ -156,7 +160,7 @@
continue;
}
$formParams = [
'label' => $options['label'],
'label' => !empty($columns[$key]['label']) ? $columns[$key]['label'] : $options['label'],
// The default type is text, but we might convert to select below
'type' => 'text',
'value' => (!empty($query[$key]) ? $query[$key] : ''),
Expand Down Expand Up @@ -184,7 +188,7 @@
<?php foreach($field_booleans_columns as $key => $options): ?>
<div class="form-check form-check-inline">
<?php
print $this->Form->label($key);
print $this->Form->label(!empty($columns[$key]['label']) ? $columns[$key]['label'] : $key);
print $this->Form->checkbox($key, [
'id' => str_replace("_", "-", $key),
'class' => 'form-check-input',
Expand All @@ -204,7 +208,9 @@
<div class="top-filters-fields-subgroups">
<?php foreach($field_datetime_columns as $key => $options): ?>
<div class="input">
<div class="top-search-date-label"><?= Inflector::humanize($key) ?></div>
<div class="top-search-date-label">
<?= !empty($columns[$key]['label']) ? $columns[$key]['label'] : Inflector::humanize($key) ?>
</div>
<div class="top-filters-fields-dates">
<!-- Start at -->
<div class="top-search-start-date">
Expand All @@ -216,7 +222,7 @@
$starts_field = $key . "_starts_at";
$coptions = [];
$coptions['class'] = 'form-control datepicker';
$coptions['label'] = 'Starts at:';
$coptions['label'] = __d('field','starts_at');
$coptions['required'] = false;
$coptions['placeholder'] = '';
// $coptions['placeholder'] = 'YYYY-MM-DD HH:MM:SS';
Expand All @@ -235,7 +241,7 @@
'pickerDate' => $pickerDate
];
// Create a text field to hold our value.
print $this->Form->label($starts_field, 'Starts at:', ['class' => 'filter-datepicker-lbl']);
print $this->Form->label($starts_field, __d('field','starts_at'), ['class' => 'filter-datepicker-lbl']);
print $this->Form->text($starts_field, $coptions) . $this->element('datePicker', $date_args);
?>
</div>
Expand All @@ -253,7 +259,7 @@
$coptions['required'] = false;
$coptions['placeholder'] = ''; // todo: Make this configurable
// $coptions['placeholder'] = 'YYYY-MM-DD HH:MM:SS';
$coptions['label'] = 'Ends at:';
$coptions['label'] = __d('field','ends_at');
$coptions['id'] = str_replace("_", "-", $ends_field);

$pickerDate = '';
Expand All @@ -269,7 +275,7 @@
'pickerDate' => $pickerDate
];
// Create a text field to hold our value.
print $this->Form->label($ends_field, 'Ends at:', ['class' => 'filter-datepicker-lbl']);
print $this->Form->label($ends_field, __d('field','ends_at'), ['class' => 'filter-datepicker-lbl']);
print $this->Form->text($ends_field, $coptions) . $this->element('datePicker', $date_args);
?>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/webroot/css/co-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ ul.form-list li.alert-banner .co-alert {
background-color: var(--cmg-color-bg-006);
color: var(--cmg-color-btn-bg-002) !important;
}
.top-filters-active-filter-title::after {
content: ": ";
.top-filters-active-filter-value::before {
content: ":";
}
.top-filters-active-filter-title.no-value::after {
content: none;
Expand Down