add search for integer ranges

This commit is contained in:
Uwe Steinmann 2023-04-24 07:31:20 +02:00
parent 2e6fe1b868
commit a9f88c7191

View File

@ -1031,8 +1031,6 @@ $(document).ready(function() {
$this->formField(getMLText("under_folder"), $this->getFolderChooserHtml("form3", M_READ, -1, $startfolder, 'folderfullsearchid'));
$this->contentContainerEnd();
$this->formSubmit("<i class=\"fa fa-search\"></i> ".getMLText('search'));
echo "<p></p>";
if($facets) {
$menuitems = [];
@ -1044,10 +1042,22 @@ $(document).ready(function() {
/* Create a link to remove the filter */
$allparams = $request->query->all();
if(isset($allparams['attributes'][$facetname])) {
$oldvalue = is_array($allparams['attributes'][$facetname]) ? implode(',', $allparams['attributes'][$facetname]) : $allparams['attributes'][$facetname];
unset($allparams['attributes'][$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>$dispname.' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
if(isset($allparams['attributes'][$facetname]['to']) && isset($allparams['attributes'][$facetname]['from'])) {
$oldvalue = $allparams['attributes'][$facetname];
if(!empty($oldvalue['from']) || !empty($oldvalue['to'])) {
unset($allparams['attributes'][$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>'<i class="fa fa-remove"></i> '.$dispname.' = '.$oldvalue['from'].' TO '.$oldvalue['to'], 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
echo '<input type="hidden" name="attributes['.$facetname.'][from]" value="'.$oldvalue['from'].'" />';
echo '<input type="hidden" name="attributes['.$facetname.'][to]" value="'.$oldvalue['to'].'" />';
}
} else {
$oldvalue = is_array($allparams['attributes'][$facetname]) ? implode(',', $allparams['attributes'][$facetname]) : $allparams['attributes'][$facetname];
unset($allparams['attributes'][$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>'<i class="fa fa-remove"></i> '.$dispname.' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
echo '<input type="hidden" name="attributes['.$facetname.'][]" value="'.$oldvalue.'" />';
}
}
}
} else {
@ -1057,46 +1067,76 @@ $(document).ready(function() {
$oldvalue = is_array($allparams[$facetname]) ? implode(',', $allparams[$facetname]) : $allparams[$facetname];
unset($allparams[$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>getMLText($facetname).' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
$menuitems[] = array('label'=>'<i class="fa fa-remove"></i> '.getMLText($facetname).' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
echo '<input type="hidden" name="'.$facetname.'[]" value="'.$oldvalue.'" />';
}
}
}
if($menuitems) {
ob_start();
// ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion(getMLText('current_filter'), $content, true);
// $content = ob_get_clean();
// $this->printAccordion(getMLText('current_filter'), $content, true);
}
}
echo "<p></p>";
$this->formSubmit("<i class=\"fa fa-search\"></i> ".getMLText('search'));
echo "<p></p>";
if($facets) {
$allparams = $request->query->all();
if(!isset($allparams['fullsearch']))
$allparams['fullsearch'] = 1;
if(!isset($allparams['facetsearch']))
$allparams['facetsearch'] = 1;
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
foreach($facets as $facetname=>$values) {
if(substr($facetname, 0, 5) == 'attr_') {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
$dispname = $attrdef->getName();
/* See below on an explaination for the if statement */
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
arsort($values);
foreach($values as $v=>$c) {
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$request->getRequestUri().'&attributes['.$facetname.'][]='.urlencode($v), 'badge'=>$c, 'attributes'=>array(array('data-href', $request->getRequestUri().'&'.$facetname.'='.$v), array('data-action', "printOpenTasksList")));
switch($attrdef->getType()) {
case SeedDMS_Core_AttributeDefinition::type_int:
/* See below on an explaination for the if statement */
if($values && (count($values) > 1 || reset($values) < $total)) {
if(empty($allparams['attributes'][$facetname]['from']) && empty($allparams['attributes'][$facetname]['to'])) {
$tt = array_keys($values);
$content = '<div class="input-group">';
$content .= '<span class="input-group-text" style="border-left: 0; border-right: 0;"> from </span>';
$content .= '<input type="number" class="form-control" name="attributes['.$facetname.'][from]" value="" placeholder="min is '.min($tt).'" />';
$content .= '<span class="input-group-text" style="border-left: 0; border-right: 0;"> to </span>';
$content .= '<input type="number" class="form-control" name="attributes['.$facetname.'][to]" value="" placeholder="max is '.max($tt).'" />';
$content .= '<button class="btn btn-outline-secondary" type="submit">Set</button>';
$content .= '</div>';
$this->printAccordion($dispname, $content);
}
}
break;
default:
/* See below on an explaination for the if statement */
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
arsort($values);
foreach($values as $v=>$c) {
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$newrequest->getRequestUri().'&attributes['.$facetname.'][]='.urlencode($v), 'badge'=>$c);
}
ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion($dispname, $content);
}
ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion($dispname, $content);
}
}
} else {
/* Further filter makes onle sense if the facet has mor than 1 value
* or in case of 1 value that value has a count < $total. That second
* case will reduce the result set on those objects which the field
/* Further filter makes only sense if the facet has more than 1 value
* or in case of 1 value, if that value has a count < $total. That second
* case will reduce the result set on those objects which have the field
* actually set.
*/
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
arsort($values);
foreach($values as $v=>$c) {
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$request->getRequestUri().'&'.$facetname.'[]='.urlencode($v), 'badge'=>$c, 'attributes'=>array(array('data-href', "#initlist"), array('data-action', "printOpenTasksList")));
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$newrequest->getRequestUri().'&'.$facetname.'[]='.urlencode($v), 'badge'=>$c);
}
ob_start();
self::showNavigationListWithBadges($menuitems);