Skip to content
Snippets Groups Projects
Commit a84f39cd authored by S.Listl's avatar S.Listl
Browse files

JditoFilter support for user-property selectionIgnoreCase

parent 2945588f
No related branches found
No related tags found
No related merge requests found
import("system.tools");
import("system.logging");
import("Sql_lib");
......@@ -44,6 +45,8 @@ JditoFilterHelper.prototype.checkRecord = function (pRow)
if (this.filter.length == 0)
return true;
var regexFlags = JditoFilterUtils.isUserIgnoreCase() ? "i" : undefined;
return _testRecord.call(this, this.filter);
/**
......@@ -74,17 +77,17 @@ JditoFilterHelper.prototype.checkRecord = function (pRow)
switch (pOperator)
{
case "CONTAINS":
return (new RegExp(pFilterValue)).test(pRowValue);
return (new RegExp(pFilterValue, regexFlags)).test(pRowValue);
case "CONTAINSNOT":
return !(new RegExp(pFilterValue)).test(pRowValue);
return !(new RegExp(pFilterValue, regexFlags)).test(pRowValue);
case "STARTSWITH":
return (new RegExp("^" + pFilterValue)).test(pRowValue);
return (new RegExp("^" + pFilterValue, regexFlags)).test(pRowValue);
case "ENDSWITH":
return (new RegExp(pFilterValue + "$")).test(pRowValue);
return (new RegExp(pFilterValue + "$", regexFlags)).test(pRowValue);
case "EQUAL":
return (new RegExp("^" + pFilterValue + "$")).test(pRowValue);
return (new RegExp("^" + pFilterValue + "$", regexFlags)).test(pRowValue);
case "NOT_EQUAL":
return !(new RegExp("^" + pFilterValue + "$")).test(pRowValue);
return !(new RegExp("^" + pFilterValue + "$", regexFlags)).test(pRowValue);
case "LESS":
return pRowValue < pFilterValue;
case "LESS_OR_EQUAL":
......@@ -192,7 +195,9 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter, pCustomC
*/
JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColumnOrFnMap)
{
var condition = newWhere();
var condition = newWhere();
var ignoreCase = JditoFilterUtils.isUserIgnoreCase();
if (!pFilter)
return condition;
......@@ -229,11 +234,15 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu
}
else
{
condition = _getCondition.call(pFilter, pFilter.value, pFilter.operator);
let isStringType, filterValue;
[condition, filterValue, isStringType] = _getCondition(pFilter.value, pFilter.operator);
if (isStringType && ignoreCase)
condition = condition.replace("#", "UPPER(#)").replace("?", "UPPER(?)");
if (pOperator == "AND")
this.andIfSet(pFilter.name, pFilter.value, condition);
this.andIfSet(pFilter.name, filterValue, condition);
else if (pOperator == "OR")
this.orIfSet(pFilter.name, pFilter.value, condition);
this.orIfSet(pFilter.name, filterValue, condition);
}
}
else if (pFilter.type == "group")
......@@ -251,43 +260,49 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu
}
}
//returns the condition depending on the operator and
//adds wildcards to the value if necessary
//returns [condition, value with wildcards, is a string type] depending on the operator
function _getCondition (pValue, pOperator)
{
switch (pOperator)
{
case "CONTAINS":
this.value = "%" + pValue + "%";
return SqlBuilder.LIKE();
return [SqlBuilder.LIKE(), "%" + pValue + "%", true];
case "CONTAINSNOT":
this.value = "%" + pValue + "%";
return SqlBuilder.NOT_LIKE();
return [SqlBuilder.NOT_LIKE(), "%" + pValue + "%", true];
case "STARTSWITH":
this.value = pValue + "%";
return SqlBuilder.LIKE();
return [SqlBuilder.LIKE(), pValue + "%", true];
case "ENDSWITH":
this.value = "%" + pValue;
return SqlBuilder.LIKE();
return [SqlBuilder.LIKE(), "%" + pValue, true];
case "EQUAL":
return SqlBuilder.EQUAL();
return [SqlBuilder.EQUAL(), pValue, true];
case "NOT_EQUAL":
return SqlBuilder.NOT_EQUAL();
return [SqlBuilder.NOT_EQUAL(), pValue, true];
case "LESS":
return SqlBuilder.LESS();
return [SqlBuilder.LESS(), pValue, false];
case "LESS_OR_EQUAL":
return SqlBuilder.LESS_OR_EQUAL();
return [SqlBuilder.LESS_OR_EQUAL(), pValue, false];
case "GREATER":
return SqlBuilder.GREATER();
return [SqlBuilder.GREATER(), pValue, false];
case "GREATER_OR_EQUAL":
return SqlBuilder.GREATER_OR_EQUAL();
return [SqlBuilder.GREATER_OR_EQUAL(), pValue, false];
case "ISNULL":
return "# is null";
return ["# is null", pValue, false];
case "ISNOTNULL":
return "# is not null";
return ["# is not null", pValue, false];
}
}
}
/**
* @return {boolean} the selectionIgnoreCase property of the current user, defaults to true
*/
JditoFilterUtils.isUserIgnoreCase = function ()
{
var user = tools.getCurrentUser();
var ignoreCase = user ? user[tools.PARAMS][tools.SELECTION_IGNORECASE] : "";
return ignoreCase == "" || /true/i.test(ignoreCase);
}
return JditoFilterUtils; //return only functions that should be public
})();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment