Can remove filter entries

This commit is contained in:
Laurent Destailleur
2024-02-16 01:50:03 +01:00
parent 7107b5feb3
commit b48455c9d7
3 changed files with 57 additions and 4 deletions

View File

@@ -10731,7 +10731,7 @@ class Form
$ret .= '<input type="hidden" name="show_search_component_params_hidden" value="1">';
}
$ret .= "<!-- We store the full Universal Search String into this field. For example: (t.ref:like:'SO-%') AND ((t.ref:like:'CO-%') OR (t.ref:like:'AA%')) -->";
$ret .= '<input type="hidden" name="search_component_params_hidden" value="' . dol_escape_htmltag($search_component_params_hidden) . '">';
$ret .= '<input type="hidden" id="search_component_params_hidden" name="search_component_params_hidden" value="' . dol_escape_htmltag($search_component_params_hidden) . '">';
// $ret .= "<!-- sql= ".forgeSQLFromUniversalSearchCriteria($search_component_params_hidden, $errormessage)." -->";
// For compatibility with forms that show themself the search criteria in addition of this component, we output these fields
@@ -10761,7 +10761,7 @@ class Form
$ret .= '</div>';
$ret .= "<!-- Field to enter a generic filter string: t.ref:like:'SO-%', t.date_creation:<:'20160101', t.date_creation:<:'2016-01-01 12:30:00', t.nature:is:NULL, t.field2:isnot:NULL -->\n";
$ret .= '<input type="text" placeholder="' . $langs->trans("Filters") . '" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
$ret .= '<input type="text" placeholder="' . $langs->trans("Filters") . '" id="search_component_params_input" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
$ret .= '</div>';
$ret .= '</div>';
@@ -10774,7 +10774,6 @@ class Form
// Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page
var newparamstring = \'\';
$(\'.tagsearch\').each(function(index, element) {
console.log(element);
tmpfilterid = $(this).attr("data-ufilterid");
if (tmpfilterid != filterid) {
// We keep this criteria
@@ -10785,7 +10784,9 @@ class Form
}
}
});
console.log(newparamstring);
console.log("newparamstring = "+newparamstring);
jQuery("#search_component_params_hidden").val(newparamstring);
// We repost the form
$(this).closest(\'form\').submit();

View File

@@ -12573,6 +12573,16 @@ function dolForgeExplodeAnd($sqlfilters)
$arrayofandtags = array();
$nbofchars = dol_strlen($sqlfilters);
$error = '';
$parenthesislevel = 0;
$result = dolCheckFilters($sqlfilters, $error, $parenthesislevel);
if (!$result) {
return array();
}
if ($parenthesislevel >= 1) {
$sqlfilters = preg_replace('/^\(/', '', preg_replace('/\)$/', '', $sqlfilters));
}
$i = 0;
$s = '';
$countparenthesis = 0;

View File

@@ -232,6 +232,48 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
$result = dolCheckFilters($sql, $error, $parenthesislevel);
$this->assertEquals(0, $parenthesislevel);
$this->assertFalse($result);
return true;
}
/**
* testDolForgeExplodeAnd
*
* @return boolean
*/
public function testDolForgeExplodeAnd()
{
$tmp = dolForgeExplodeAnd('');
$this->assertEquals(0, count($tmp));
$tmp = dolForgeExplodeAnd('(a:=:1)');
$this->assertEquals('(a:=:1)', $tmp[0]);
$tmp = dolForgeExplodeAnd('(a:=:1) AND (b:=:2)');
$this->assertEquals('(a:=:1)', $tmp[0]);
$this->assertEquals('(b:=:2)', $tmp[1]);
$tmp = dolForgeExplodeAnd('(a:=:1) AND ((b:=:2) OR (c:=:3))');
$this->assertEquals('(a:=:1)', $tmp[0]);
$this->assertEquals('((b:=:2) OR (c:=:3))', $tmp[1]);
$tmp = dolForgeExplodeAnd('(a:=:1) AND (b:=:2) OR (c:=:3)');
$this->assertEquals('(a:=:1)', $tmp[0]);
$this->assertEquals('(b:=:2) OR (c:=:3)', $tmp[1]);
$tmp = dolForgeExplodeAnd('(a:=:1) OR (b:=:2) AND (c:=:3)');
$this->assertEquals('(a:=:1) OR (b:=:2)', $tmp[0]);
$this->assertEquals('(c:=:3)', $tmp[1]);
$tmp = dolForgeExplodeAnd('(a:=:1) OR ((b:=:2) AND (c:=:3))');
$this->assertEquals('(a:=:1) OR ((b:=:2) AND (c:=:3))', $tmp[0]);
$tmp = dolForgeExplodeAnd('((y:=:1) AND (p:=:8))');
$this->assertEquals('(y:=:1)', $tmp[0]);
$this->assertEquals('(p:=:8)', $tmp[1]);
return true;
}
/**