Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Matchgrid Records: implement filtering/search on index view (CO-1871)
Showing
8 changed files
with
431 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<?php | ||
/** | ||
* COmanage Match Search Element | ||
* | ||
* 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 http://www.internet2.edu/comanage COmanage Project | ||
* @package match | ||
* @since COmanage Match v1.0.0 | ||
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
*/ | ||
|
||
use \Cake\Utility\Inflector; | ||
|
||
// Globals | ||
global $cm_lang, $cm_texts; | ||
|
||
// Get a pointer to our controller | ||
$controller = $this->request->getParam('controller'); | ||
$req = Inflector::singularize($controller); | ||
|
||
// Get the query string and separate the search params from the non-search params | ||
$query = $this->request->getQueryParams(); | ||
$non_search_params = array_diff_key($query, $vv_search_fields); | ||
$search_params = array_intersect_key($query, $vv_search_fields); | ||
|
||
// Begin the form | ||
print $this->Form->create($req, [ | ||
'id' => 'top-search-form', | ||
'type' => 'get', | ||
'url' => ['action' => $this->request->action] | ||
]); | ||
|
||
// Pass back the non-search params as hidden fields, but always exclude the page parameter | ||
// because we need to start new searches on page one (or we're likely to end up with a 404). | ||
if(!empty($non_search_params)) { | ||
foreach ($non_search_params as $param => $value) { | ||
if($param != 'page') { | ||
print $this->Form->hidden(filter_var($param, FILTER_SANITIZE_SPECIAL_CHARS), array('default' => filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS))) . "\n"; | ||
} | ||
} | ||
} | ||
|
||
// Boolean to distinguish between search filters and sort parameters | ||
// XXX may no longer need this | ||
$hasActiveFilters = false; | ||
?> | ||
|
||
<div id="<?php print $req . ucfirst($this->request->action); ?>Search" class="top-search"> | ||
<fieldset onclick="event.stopPropagation();"> | ||
<legend id="top-search-toggle"> | ||
<em class="material-icons">search</em> | ||
<?= __('match.op.filter');?> | ||
|
||
<?php if(!empty($search_params)):?> | ||
<span id="top-search-active-filters"> | ||
<?php foreach($search_params as $key => $params): ?> | ||
<?php | ||
// Construct aria-controls string | ||
$key_fields = explode('.', $key); | ||
$aria_controls = $key_fields[0] . ucfirst($key_fields[1]); | ||
|
||
// We have active filters - not just a sort. | ||
$hasActiveFilters = true; | ||
?> | ||
<button class="top-search-active-filter deletebutton spin" type="button" aria-controls="<?php print $aria_controls; ?>" title="<?= __('match.op.clear.filters',[1]);?>"> | ||
<span class="top-search-active-filter-title"><?php print $vv_search_fields[$key]['label']; ?></span> | ||
<span class="top-search-active-filter-value"> | ||
<?php | ||
$value = $params; | ||
// Get user friendly name from an Enumerator Class - XXX will need updating for Match if it becomes used | ||
// XXX How should we handle dynamic Enumerator lists? | ||
if(isset($vv_search_fields[$key]['enum']) | ||
&& isset($cm_texts[ $cm_lang ][$vv_search_fields[$key]['enum']][$params])) { | ||
$value = $cm_texts[ $cm_lang ][$vv_search_fields[$key]['enum']][$params]; | ||
print filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); | ||
continue; | ||
} | ||
// Get user friendly name from the dropdown Select List | ||
// XXX Currently we do not have a use case where the grouping name would create a namespace | ||
if (isset($vv_search_fields[$key]['options'])) { | ||
// Outside of any groups | ||
if (isset($vv_search_fields[$key]['options'][$value])) { | ||
print filter_var($vv_search_fields[$key]['options'][$value], FILTER_SANITIZE_SPECIAL_CHARS); | ||
} else { | ||
// Inside a group | ||
foreach(array_keys($vv_search_fields[$key]['options']) as $optgroup) { | ||
if( is_array($vv_search_fields[$key]['options'][$optgroup]) | ||
&& isset($vv_search_fields[$key]['options'][$optgroup][$value]) ) { | ||
print filter_var($vv_search_fields[$key]['options'][$optgroup][$value], FILTER_SANITIZE_SPECIAL_CHARS); | ||
print $this->Html->tag('span','(' . $optgroup . ')', array('class' => 'ml-1') ); | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
print filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); | ||
} | ||
?> | ||
</span> | ||
</button> | ||
<?php endforeach; ?> | ||
<?php if($hasActiveFilters): ?> | ||
<button id="top-search-clear-all-button" class="filter-clear-all-button spin btn" type="button" aria-controls="top-search-clear" onclick="event.stopPropagation()"> | ||
<?= __('match.op.clear.filters',[2]);?> | ||
</button> | ||
<?php endif; ?> | ||
</span> | ||
<?php endif; ?> | ||
<button class="cm-toggle" aria-expanded="false" aria-controls="top-search-fields" type="button"><em class="material-icons drop-arrow">arrow_drop_down</em></button> | ||
</legend> | ||
<div id="top-search-fields"> | ||
<div id="top-search-fields-subgroups"> | ||
<?php | ||
$i = 0; | ||
$field_subgroup_columns = array(); | ||
$skippedFields = 0; | ||
foreach($vv_search_fields as $key => $options) { | ||
// Exclude explicitly skipped fields | ||
if(array_key_exists('searchSkip',$options)) { | ||
$skippedFields++; | ||
continue; | ||
} | ||
$formParams = array( | ||
'label' => !empty($options['searchLabel']) ? $options['searchLabel'] : $options['label'], | ||
'type' => !empty($options['searchType']) ? $options['searchType'] : 'text', | ||
'value' => (!empty($query[$key]) ? $query[$key] : ''), | ||
'required' => false, | ||
); | ||
if(isset($options['searchEmpty'])) { | ||
$formParams['empty'] = $options['searchEmpty']; | ||
} | ||
if(isset($options['searchOptions'])) { | ||
$formParams['options'] = $options['searchOptions']; | ||
} | ||
|
||
print $this->Form->input($key, $formParams); | ||
} | ||
?> | ||
</div> | ||
<?php $rebalanceColumns = ((count($vv_search_fields)-$skippedFields) % 2 != 0) ? ' class="tss-rebalance"' : ''; ?> | ||
<div id="top-search-submit"<?php print $rebalanceColumns ?>> | ||
<?php | ||
$args = array(); | ||
// search button (submit) | ||
$args['id'] = 'top-search-filter-button'; | ||
$args['aria-label'] = __('match.op.filter'); | ||
$args['class'] = 'submit-button spin btn btn-primary'; | ||
print $this->Form->submit(__('match.op.filter'),$args); | ||
|
||
// clear button | ||
$args['id'] = 'top-search-clear'; | ||
$args['class'] = 'clear-button spin btn btn-default'; | ||
$args['aria-label'] = __('match.op.clear'); | ||
$args['onclick'] = 'clearTopSearch(this.form)'; | ||
print $this->Form->button(__('match.op.clear'),$args); | ||
?> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> | ||
|
||
<?php print $this->Form->end();?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters