From 7ae208dcf2b77788d6aa87de831ebd3e330d6162 Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Thu, 16 Jul 2020 09:40:25 +0200 Subject: [PATCH] 1061914 JditoFilter_lib support for timeframe filters --- process/JditoFilter_lib/process.js | 61 ++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/process/JditoFilter_lib/process.js b/process/JditoFilter_lib/process.js index 9e6137b3eb..28657e5cee 100644 --- a/process/JditoFilter_lib/process.js +++ b/process/JditoFilter_lib/process.js @@ -1,6 +1,7 @@ import("system.tools"); import("system.logging"); import("Sql_lib"); +import("system.datetime"); /** * object for filtering records @@ -117,6 +118,8 @@ JditoFilter.prototype.checkRecord = function (pRow) case "TIMEFRAME_EQUAL": case "TIMEFRAME_COMING": case "TIMEFRAME_PAST": + var [start, end] = datetime.resolveRelativeDateExpression(pFilterValue); + return pRowValue >= start && pRowValue <= end; } } } @@ -230,25 +233,26 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu { if (pFilter.type == "row") { + var sqlField; if (pFilter.name in pColumnOrFnMap) { - pFilter.name = pColumnOrFnMap[pFilter.name]; + sqlField = pColumnOrFnMap[pFilter.name]; //possibility to explicitly set the value to null/false so that the field is ignored - if (pFilter.name === null || pFilter.name === false) + if (sqlField === null || sqlField === false) return; } else if (pTable && pTableAlias) - pFilter.name = [pTable, pFilter.name, pTableAlias]; + sqlField = [pTable, pFilter.name, pTableAlias]; else if (pTable) - pFilter.name = pTable + "." + pFilter.name; + sqlField = pTable + "." + pFilter.name; - pFilter.value = (pFilter.key || pFilter.value); + var filterValue = (pFilter.key || pFilter.value); var condition; - if (typeof(pFilter.name) === "function") + if (typeof(sqlField) === "function") { - condition = pFilter.name.call(null, pFilter.value, pFilter.operator); + condition = sqlField.call(null, filterValue, pFilter.operator); if (pOperator == "AND") this.andIfSet(condition); else if (pOperator == "OR") @@ -256,21 +260,32 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu } else { - 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, filterValue, condition); - else if (pOperator == "OR") - this.orIfSet(pFilter.name, filterValue, condition); + var generatedCondition = _getCondition(filterValue, pFilter.operator, sqlField); + if (generatedCondition instanceof SqlBuilder) + { + if (pOperator == "AND") + this.andIfSet(generatedCondition); + else if (pOperator == "OR") + this.orIfSet(generatedCondition); + } + else + { + var isStringType; + [condition, filterValue, isStringType] = generatedCondition; + if (isStringType && ignoreCase) + condition = condition.replace("#", "UPPER(#)").replace("?", "UPPER(?)"); + + if (pOperator == "AND") + this.andIfSet(sqlField, filterValue, condition); + else if (pOperator == "OR") + this.orIfSet(sqlField, filterValue, condition); + } } } else if (pFilter.type == "group") { - let subCondition = newWhere(); - let operator = pFilter.operator; + var subCondition = newWhere(); + var operator = pFilter.operator; pFilter.childs.forEach(function (cond) { _addCondition.call(subCondition, cond, operator); @@ -283,7 +298,7 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu } //returns [condition, value with wildcards, is a string type] depending on the operator - function _getCondition (pValue, pOperator) + function _getCondition (pValue, pOperator, pField) { switch (pOperator) { @@ -311,6 +326,14 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu return ["# is null", pValue, false]; case "ISNOTNULL": return ["# is not null", pValue, false]; + case "TIMEFRAME_EQUAL": + case "TIMEFRAME_COMING": + case "TIMEFRAME_PAST": + var [start, end] = datetime.resolveRelativeDateExpression(pValue); + return newWhere(pField, start, SqlBuilder.GREATER_OR_EQUAL()) + .and(pField, end, SqlBuilder.LESS_OR_EQUAL()); + + } } } -- GitLab