Skip to content
Snippets Groups Projects
Commit d88290bc authored by Alexander Purr's avatar Alexander Purr Committed by Robert Lange
Browse files

refs #22511 [finc-accessibility] usability date range slider

* add cluster for extracting possible year ranges
* set up possible ranges and by user chosen filtered years at the beginning of template to provide fitting variables for inputs and date range slider
* adjust configuration for loading complete range of years
parent 11152cd1
No related merge requests found
...@@ -310,6 +310,12 @@ hide_facets = "genre_facet,era_facet,geographic_facet" ...@@ -310,6 +310,12 @@ hide_facets = "genre_facet,era_facet,geographic_facet"
[SortedByIndex] [SortedByIndex]
;index[] = format ;index[] = format
[Results_Settings]
; By default, how many values should we show for each facet? (-1 for no limit)
;facet_limit = 30
; Override facet_limit on a per-field basis using this array:
facet_limit_by_field[publishDateSort] = -1
; Special terms (key), which can't / shouldn't be translated but marked as other language (value) for BARF reasons ; Special terms (key), which can't / shouldn't be translated but marked as other language (value) for BARF reasons
[LanguageTags] [LanguageTags]
en[] = "American Museum of Natural History" en[] = "American Museum of Natural History"
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
$facet = $this->facet; $facet = $this->facet;
?> ?>
<?php if (isset($rangeFacets[$facet])): // special display for ranges ?> <?php if (isset($rangeFacets[$facet])): // special display for ranges ?>
<?php /* finc: usability date range slider #22511: add cluster for extracting possible year ranges */ ?>
<?=$this->context($this)->renderInContext( <?=$this->context($this)->renderInContext(
'Recommend/SideFacets/range-slider.phtml', 'Recommend/SideFacets/range-slider.phtml',
['title' => $facet, 'facet' => $rangeFacets[$facet]] ['title' => $facet, 'facet' => $rangeFacets[$facet], 'cluster' => $cluster]
); ?> ); ?>
<?php else: ?> <?php else: ?>
<?php <?php
......
...@@ -4,6 +4,22 @@ ...@@ -4,6 +4,22 @@
* slider-container element * slider-container element
*/ */
?> ?>
<?php
/** finc: usability date range slider #22511:
* set boundary values for daterange input and slider
* min & max values of handles and inputs are defined by search results
* if date range filter is applied additionaly: lowest and highest record years can be within filter values
*/
foreach ($cluster['list'] as $facet) {
$years[] = $facet['value'];
}
$facetmin = min($years);
$facetmax = max($years);
$low = $facetmin;
$min = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $facetmin;
$high = $facetmax;
$max = !empty($this->facet['values'][1]) ? $this->facet['values'][1] : $facetmax;
?>
<?php /* finc changes div into li for compatibility with facet list structure */ ?> <?php /* finc changes div into li for compatibility with facet list structure */ ?>
<li class="facet"> <li class="facet">
<?php /* finc adds landmarks for active facets */ ?> <?php /* finc adds landmarks for active facets */ ?>
...@@ -17,22 +33,24 @@ ...@@ -17,22 +33,24 @@
<?=$results->getUrlQuery()->asHiddenFields(['page' => "/./", 'filter' => "/^{$this->title}:.*/"])?> <?=$results->getUrlQuery()->asHiddenFields(['page' => "/./", 'filter' => "/^{$this->title}:.*/"])?>
<input type="hidden" name="<?=$this->escapeHtmlAttr($this->facet['type'])?>range[]" value="<?=$this->escapeHtmlAttr($this->title)?>"/> <input type="hidden" name="<?=$this->escapeHtmlAttr($this->facet['type'])?>range[]" value="<?=$this->escapeHtmlAttr($this->title)?>"/>
<div class="date-fields"> <div class="date-fields">
<?php /* finc adds 'max="'.(date('Y')+1).' to prevent dates beyond the year + 1 to be entered; maxlength was causing w3c issues */ ?> <?php /* finc: usability date range slider #22511:
<?php $extraInputAttribs = ($this->facet['type'] == 'date') ? 'max="'.(date('Y')+1).'" ' : ''; ?> prefill min & max attributes by possible date range (given by search results or chosen date range filter)
*/ ?>
<?php $extraInputAttribs = ($this->facet['type'] == 'date') ? " min=\"{$min}\" max=\"{$max}\" " : ''; ?>
<div class="date-from"> <div class="date-from">
<?php /* finc adds label ids */ ?> <?php /* finc adds label ids */ ?>
<label id="from-label" for="<?=$this->escapeHtmlAttr($this->title)?>from"> <label id="from-label" for="<?=$this->escapeHtmlAttr($this->title)?>from">
<?=$this->transEsc('date_from')?>: <?=$this->transEsc('date_from')?>:
</label> </label>
<?php /* finc changes this to number for consistency with adv search */ ?> <?php /* finc: usability date range slider #22135, #22511: change input type and value */ ?>
<input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>from" id="<?=$this->escapeHtmlAttr($this->title)?>from" value="<?=isset($this->facet['values'][0]) ? $this->escapeHtmlAttr($this->facet['values'][0]) : ''?>" <?=$extraInputAttribs?>/> <input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>from" id="<?=$this->escapeHtmlAttr($this->title)?>from" value="<?=!empty($this->facet['values'][0]) ? $this->escapeHtmlAttr($low) : ''?>" <?=$extraInputAttribs?>/>
</div> </div>
<div class="date-to"> <div class="date-to">
<label id="to-label" for="<?=$this->escapeHtmlAttr($this->title)?>to"> <label id="to-label" for="<?=$this->escapeHtmlAttr($this->title)?>to">
<?=$this->transEsc('date_to')?>: <?=$this->transEsc('date_to')?>:
</label> </label>
<?php /* finc changes this to number for consistency with adv search */ ?> <?php /* finc: usability date range slider #22135, #22511: change input type and value input */ ?>
<input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>to" id="<?=$this->escapeHtmlAttr($this->title)?>to" value="<?=isset($this->facet['values'][1]) ? $this->escapeHtmlAttr($this->facet['values'][1]) : ''?>" <?=$extraInputAttribs?>/> <input type="number" class="form-control" name="<?=$this->escapeHtmlAttr($this->title)?>to" id="<?=$this->escapeHtmlAttr($this->title)?>to" value="<?=!empty($this->facet['values'][1]) ? $this->escapeHtmlAttr($high) : ''?>" <?=$extraInputAttribs?>/>
</div> </div>
</div> </div>
<?php if ($this->facet['type'] == 'date'): ?> <?php if ($this->facet['type'] == 'date'): ?>
...@@ -49,11 +67,7 @@ ...@@ -49,11 +67,7 @@
<?php $this->headScript()->appendFile('vendor/bootstrap-slider.min.js'); ?> <?php $this->headScript()->appendFile('vendor/bootstrap-slider.min.js'); ?>
<?php $this->headLink()->appendStylesheet('vendor/bootstrap-slider.min.css'); ?> <?php $this->headLink()->appendStylesheet('vendor/bootstrap-slider.min.css'); ?>
<?php <?php
$min = !empty($this->facet['values'][0]) ? min($this->facet['values'][0], 1400) : 1400; /* finc: usability date range slider #22511: variables moved to top */
$future = date('Y', time() + 31536000); // next year
$max = !empty($this->facet['values'][1]) ? max($future, $this->facet['values'][1]) : $future;
$low = !empty($this->facet['values'][0]) ? $this->facet['values'][0] : $min;
$high = !empty($this->facet['values'][1]) ? $this->facet['values'][1] : $max;
$script = <<<JS $script = <<<JS
$(document).ready(function() { $(document).ready(function() {
var fillTexts = function() { var fillTexts = function() {
......
...@@ -2,8 +2,15 @@ ...@@ -2,8 +2,15 @@
<?php if (isset($this->ranges) && !empty($this->ranges)): ?> <?php if (isset($this->ranges) && !empty($this->ranges)): ?>
<?php $params = $this->searchParams($this->searchClassId); ?> <?php $params = $this->searchParams($this->searchClassId); ?>
<?php foreach ($this->ranges as $current): $escField = $this->escapeHtmlAttr($current['field']); ?> <?php foreach ($this->ranges as $current): $escField = $this->escapeHtmlAttr($current['field']); ?>
<?php /* finc adds 'max="'.(date('Y')+1).' to prevent dates beyond the year + 1 to be entered; maxlength was causing w3c issues */ ?> <?php /* finc: usability date range slider #22511:: calculate variables at the beginning */
<?php $extraInputAttribs = ($current['type'] == 'date') ? 'max="'.(date('Y')+1).'" ' : ''; ?> $min = !empty($current['values'][0]) ? min($current['values'][0], 1400) : 1400;
$future = date('Y', time() + 31536000);
$max = !empty($current['values'][1]) ? max($future, $current['values'][1]) : $future;
$low = !empty($current['values'][0]) ? $current['values'][0] : $min;
$high = !empty($current['values'][1]) ? $current['values'][1] : $max;
?>
<?php /* finc: usability date range slider #22511: use previously calculated min-/max-values to limit inputs */ ?>
<?php $extraInputAttribs = ($current['type'] == 'date') ? " min=\"{$min}\" max=\"{$max}\" " : ''; ?>
<fieldset class="range"> <fieldset class="range">
<legend><?=$this->transEsc($params->getFacetLabel($current['field']))?></legend> <legend><?=$this->transEsc($params->getFacetLabel($current['field']))?></legend>
<input type="hidden" name="<?=$this->escapeHtmlAttr($current['type'])?>range[]" value="<?=$escField?>"/> <input type="hidden" name="<?=$this->escapeHtmlAttr($current['type'])?>range[]" value="<?=$escField?>"/>
...@@ -27,11 +34,7 @@ ...@@ -27,11 +34,7 @@
<?php <?php
$this->headScript()->appendFile('vendor/bootstrap-slider.min.js'); $this->headScript()->appendFile('vendor/bootstrap-slider.min.js');
$this->headLink()->appendStylesheet('vendor/bootstrap-slider.min.css'); $this->headLink()->appendStylesheet('vendor/bootstrap-slider.min.css');
$min = !empty($current['values'][0]) ? min($current['values'][0], 1400) : 1400; /* finc: usability date range slider #22511: moving variables to the beginning */
$future = date('Y', time() + 31536000);
$max = !empty($current['values'][1]) ? max($future, $current['values'][1]) : $future;
$low = !empty($current['values'][0]) ? $current['values'][0] : $min;
$high = !empty($current['values'][1]) ? $current['values'][1] : $max;
$min = intval($min); $min = intval($min);
$max = intval($max); $max = intval($max);
$low = intval($low); $low = intval($low);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment