From 699710ca14d5e92a2cfbcb458085776ac08bd7fb Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Thu, 22 Jun 2023 13:01:16 -0400 Subject: [PATCH] Allow columns.inc $indexColumns labels to override filter labels, and hide values from boolean fields in exposed filter buttons (CFM-295) (#101) --- app/resources/locales/en_US/field.po | 6 ++++ app/templates/Standard/index.php | 4 +-- app/templates/element/filter.php | 44 ++++++++++++++++------------ app/webroot/css/co-base.css | 4 +-- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/app/resources/locales/en_US/field.po b/app/resources/locales/en_US/field.po index 0f88b28e3..cf47654fd 100644 --- a/app/resources/locales/en_US/field.po +++ b/app/resources/locales/en_US/field.po @@ -95,6 +95,9 @@ msgstr "Display Name" msgid "edupersonaffiliation" msgstr "eduPersonAffiliation" +msgid "ends_at" +msgstr "Ends at:" + msgid "extension" msgstr "Extension" @@ -198,6 +201,9 @@ msgstr "Search..." msgid "sponsor" msgstr "Sponsor" +msgid "starts_at" +msgstr "Starts at:" + msgid "state" msgstr "State" diff --git a/app/templates/Standard/index.php b/app/templates/Standard/index.php index 5408b0e6e..ac931a4db 100644 --- a/app/templates/Standard/index.php +++ b/app/templates/Standard/index.php @@ -156,8 +156,8 @@ element('filter', $filterArgs); ?> diff --git a/app/templates/element/filter.php b/app/templates/element/filter.php index 88aedc239..c719fc2cb 100644 --- a/app/templates/element/filter.php +++ b/app/templates/element/filter.php @@ -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(); @@ -115,13 +117,15 @@ (is_array($search_params[$key]) ? 'Range' : $search_params[$key]); ?> @@ -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) { @@ -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] : ''), @@ -184,7 +188,7 @@ $options): ?>
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', @@ -204,7 +208,9 @@
$options): ?>
-
+
+ +
@@ -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'; @@ -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); ?>
@@ -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 = ''; @@ -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); ?>
diff --git a/app/webroot/css/co-base.css b/app/webroot/css/co-base.css index 96f2b7902..42df17a9c 100644 --- a/app/webroot/css/co-base.css +++ b/app/webroot/css/co-base.css @@ -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;