Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xrm
basic
Commits
7432c2c7
Commit
7432c2c7
authored
4 years ago
by
S.Listl
Browse files
Options
Downloads
Patches
Plain Diff
JditoFilter_lib and Date_lib improvements
parent
3750b632
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
process/Date_lib/process.js
+165
-1
165 additions, 1 deletion
process/Date_lib/process.js
process/JditoFilter_lib/process.js
+38
-20
38 additions, 20 deletions
process/JditoFilter_lib/process.js
with
203 additions
and
21 deletions
process/Date_lib/process.js
+
165
−
1
View file @
7432c2c7
...
...
@@ -163,4 +163,168 @@ DateUtils.validateNotInFuture = function (pDate)
DateUtils
.
getCurrentYear
=
function
()
{
return
parseInt
(
datetime
.
toDate
(
vars
.
get
(
"
$sys.date
"
),
"
yyyy
"
));
}
\ No newline at end of file
}
/**
* Object for handling durations. It consists of years, months, days and milliseconds. Because hours, minutes and seconds have fixed lengths, these
* are all added to the milliseconds part, but years and months can have different amounts of days, so they are stored separately.
*
* @param {Number} [pYears=0] years
* @param {Number} [pMonths=0] months
* @param {Number} [pDays=0] days
* @param {Number} [pMillis=0] milliseconds
*/
function
Duration
(
pYears
,
pMonths
,
pDays
,
pMillis
)
{
this
.
years
=
pYears
!==
undefined
?
Number
(
pYears
)
:
0
;
this
.
months
=
pMonths
!==
undefined
?
Number
(
pMonths
)
:
0
;
//because of daylight saving time, a day is not always 24h
this
.
days
=
pDays
!==
undefined
?
Number
(
pDays
)
:
0
;
this
.
milliseconds
=
pMillis
!==
undefined
?
Number
(
pMillis
)
:
0
;
}
/**
* creates a new Duration object, this function can also take hours, minutes and seconds (they are automatically converted to milliseconds)
*
* @param {Number} [pYears=0] years
* @param {Number} [pMonths=0] months
* @param {Number} [pDays=0] days
* @param {Number} [pHours=0] hours
* @param {Number} [pMinutes=0] minutes
* @param {Number} [pSeconds=0] seconds
* @return {Duration} a new Duration object
*/
Duration
.
of
=
function
(
pYears
,
pMonths
,
pDays
,
pHours
,
pMinutes
,
pSeconds
)
{
if
(
pHours
==
undefined
)
pHours
=
0
;
if
(
pMinutes
==
undefined
)
pMinutes
=
0
;
if
(
pSeconds
==
undefined
)
pSeconds
=
0
;
pMinutes
+=
pHours
*
60
;
pSeconds
+=
pMinutes
*
60
;
return
new
Duration
(
pYears
,
pMonths
,
pDays
,
pSeconds
*
1000
);
}
/**
* creates a new Duration object only with hours, minutes and seconds
*
* @param {Number} [pHours=0] hours
* @param {Number} [pMinutes=0] minutes
* @param {Number} [pSeconds=0] seconds
* @return {Duration} a new Duration object
*/
Duration
.
ofTime
=
function
(
pHours
,
pMinutes
,
pSeconds
)
{
return
Duration
.
of
(
undefined
,
undefined
,
undefined
,
pHours
,
pMinutes
,
pSeconds
);
}
/**
* parses a ISO-8601 duration string into a Duration object
*
* @param {String} pIso8601Duration string representation of the duration
* @return {Duration} new duration object
*/
Duration
.
parse
=
function
(
pIso8601Duration
)
{
var
iso8601DurationRegex
=
/
([
-+
]?)
P
(?:([
-+
]?[
0-9
]
+
)
Y
)?(?:([
-+
]?[
0-9
]
+
)
M
)?(?:([
-+
]?[
0-9
]
+
)
W
)?(?:([
-+
]?[
0-9
]
+
)
D
)?(?:
T
(?:([
-+
]?[
0-9
]
+
)
H
)?(?:([
-+
]?[
0-9
]
+
)
M
)?(?:([
-+
]?[
0-9
]
+
(?:[
.,
][
0-9
]{0,9})?)
S
)?)?
/
;
var
matches
=
pIso8601Duration
.
match
(
iso8601DurationRegex
);
var
sign
=
matches
[
1
]
===
"
-
"
?
-
1
:
1
;
var
years
=
matches
[
2
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
2
])
*
sign
;
var
months
=
matches
[
3
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
3
])
*
sign
;
var
weeks
=
matches
[
4
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
4
])
*
sign
;
var
days
=
matches
[
5
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
5
])
*
sign
;
if
(
weeks
>
0
)
days
+=
weeks
*
7
;
var
hours
=
matches
[
6
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
6
])
*
sign
;
var
minutes
=
matches
[
7
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
7
])
*
sign
;
var
seconds
=
matches
[
8
]
===
undefined
?
0
:
_toNumberCommaSafe
(
matches
[
8
])
*
sign
;
return
Duration
.
of
(
years
,
months
,
days
,
hours
,
minutes
,
seconds
);
//converts a string to a number, accepting a comma as decimal separator (for example, Number("2,3") would normally return NaN)
function
_toNumberCommaSafe
(
pNumberString
)
{
return
Number
(
pNumberString
.
replace
(
"
,
"
,
"
.
"
));
}
}
/**
* makes a ISO-8601 string representing the duration
*
* @return {String} the duration as string
*/
Duration
.
prototype
.
getIso8601Representation
=
function
()
{
var
iso8601Duration
=
"
P
"
+
(
this
.
years
?
this
.
years
+
"
Y
"
:
""
)
+
(
this
.
months
?
this
.
months
+
"
M
"
:
""
)
+
(
this
.
days
?
this
.
days
+
"
D
"
:
""
);
if
(
this
.
milliseconds
)
{
var
millis
=
this
.
milliseconds
;
var
seconds
=
Math
.
floor
(
millis
/
1000
);
millis
=
millis
%
1000
;
var
minutes
=
Math
.
floor
(
seconds
/
60
);
seconds
=
seconds
%
60
;
var
hours
=
Math
.
floor
(
minutes
/
60
);
minutes
=
minutes
%
60
;
iso8601Duration
+=
"
T
"
+
(
hours
?
hours
+
"
H
"
:
""
)
+
(
minutes
?
minutes
+
"
M
"
:
""
)
+
(
seconds
?
seconds
+
(
millis
?
"
.
"
+
millis
:
""
)
+
"
S
"
:
""
);
}
//there must always be at least one element
if
(
iso8601Duration
===
"
P
"
)
iso8601Duration
+=
"
0D
"
;
return
iso8601Duration
;
}
/**
* inverts the direction of the duration
*
* @return {Duration} current object
*/
Duration
.
prototype
.
invert
=
function
()
{
this
.
years
=
-
this
.
years
;
this
.
months
=
-
this
.
months
;
this
.
days
=
-
this
.
days
;
this
.
milliseconds
=
-
this
.
milliseconds
;
return
this
;
}
/**
* Adds the duration to the given Date object (note that the duration can also be negative). This will alter the given object.
*
* @param {Date} pDate date to change, any value that is not of type "Date" will be converted to a Date
* @return {Date} the Date object
*/
Duration
.
prototype
.
addToDate
=
function
(
pDate
)
{
if
(
!
(
pDate
instanceof
Date
))
pDate
=
new
Date
(
pDate
);
if
(
this
.
years
!==
0
)
pDate
.
setFullYear
(
pDate
.
getFullYear
()
+
this
.
years
);
if
(
this
.
months
!==
0
)
pDate
.
setMonth
(
pDate
.
getMonth
()
+
this
.
months
);
if
(
this
.
days
!==
0
)
pDate
.
setDate
(
pDate
.
getDate
()
+
this
.
days
);
if
(
this
.
milliseconds
!==
0
)
pDate
.
setTime
(
pDate
.
getTime
()
+
this
.
milliseconds
);
return
pDate
;
}
This diff is collapsed.
Click to expand it.
process/JditoFilter_lib/process.js
+
38
−
20
View file @
7432c2c7
...
...
@@ -2,10 +2,6 @@ import("system.tools");
import
(
"
system.logging
"
);
import
(
"
Sql_lib
"
);
//private scope to make only JditoFilterUtils public
var
JditoFilterUtils
=
(
function
()
{
/**
* object for filtering records
*
...
...
@@ -16,7 +12,7 @@ var JditoFilterUtils = (function ()
*
* @private
*/
function
JditoFilter
Helper
(
pColumns
,
pFilter
,
pCustomCheckFns
,
pCheckFnThisArg
)
function
JditoFilter
(
pColumns
,
pFilter
,
pCustomCheckFns
,
pCheckFnThisArg
)
{
var
columnMap
=
{};
for
(
let
i
=
0
,
l
=
pColumns
.
length
;
i
<
l
;
i
++
)
...
...
@@ -25,12 +21,30 @@ function JditoFilterHelper (pColumns, pFilter, pCustomCheckFns, pCheckFnThisArg)
if
(
col
)
columnMap
[
col
]
=
{
index
:
i
,
checkFn
:
pCustomCheckFns
[
col
]
//or nothing when there is no custom function
checkFn
:
(
pCustomCheckFns
?
pCustomCheckFns
[
col
]
:
null
)
};
}
this
.
columnMap
=
columnMap
;
if
(
pFilter
&&
pFilter
.
childs
.
length
!==
0
)
_removeEmptyGroups
(
pFilter
.
childs
);
this
.
filter
=
pFilter
;
this
.
checkFnThisArg
=
pCheckFnThisArg
||
null
;
function
_removeEmptyGroups
(
pCurrentArray
)
{
for
(
let
i
=
0
;
i
<
pCurrentArray
.
length
;
i
++
)
{
let
row
=
pCurrentArray
[
i
];
if
(
row
.
type
==
"
group
"
)
{
_removeEmptyGroups
(
row
.
childs
);
if
(
row
.
childs
.
length
===
0
)
pCurrentArray
.
splice
(
i
--
,
1
);
}
}
}
}
/**
...
...
@@ -40,9 +54,9 @@ function JditoFilterHelper (pColumns, pFilter, pCustomCheckFns, pCheckFnThisArg)
*
* @return {boolean} true, if it matches the condition
*/
JditoFilter
Helper
.
prototype
.
checkRecord
=
function
(
pRow
)
JditoFilter
.
prototype
.
checkRecord
=
function
(
pRow
)
{
if
(
this
.
filter
.
length
==
0
)
if
(
!
this
.
filter
||
this
.
filter
.
childs
.
length
==
=
0
)
return
true
;
var
regexFlags
=
JditoFilterUtils
.
isUserIgnoreCase
()
?
"
i
"
:
undefined
;
...
...
@@ -100,11 +114,17 @@ JditoFilterHelper.prototype.checkRecord = function (pRow)
return
pRowValue
==
""
;
case
"
ISNOTNULL
"
:
return
pRowValue
!=
""
;
case
"
TIMEFRAME_EQUAL
"
:
case
"
TIMEFRAME_COMING
"
:
case
"
TIMEFRAME_PAST
"
:
}
}
}
JditoFilter
.
prototype
.
filterRecords
=
function
(
pRecords
)
{
return
pRecords
.
filter
(
this
.
checkRecord
,
this
);
}
/**
* Provides functions for using the filter with jdito recordcontainers
...
...
@@ -154,12 +174,7 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter, pCustomC
if
(
!
pFilter
)
return
pRecords
;
var
filter
=
new
JditoFilterHelper
(
pColumns
,
pFilter
,
pCustomCheckFns
||
{},
pCheckFnThisArg
);
return
pRecords
.
filter
(
function
(
row
)
{
return
this
.
checkRecord
(
row
);
},
filter
);
return
new
JditoFilter
(
pColumns
,
pFilter
,
pCustomCheckFns
,
pCheckFnThisArg
).
filterRecords
(
pRecords
);
}
/**
...
...
@@ -178,7 +193,8 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter, pCustomC
* var cond = new SqlBuilder();
* ...
* return cond;
* }
* },
* FIELD4 : null //if you set the value here to null of false, the field will be ignored and not added to the condition
* }
*
* @example
...
...
@@ -215,7 +231,13 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu
if
(
pFilter
.
type
==
"
row
"
)
{
if
(
pFilter
.
name
in
pColumnOrFnMap
)
{
pFilter
.
name
=
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
)
return
;
}
else
if
(
pTable
&&
pTableAlias
)
pFilter
.
name
=
[
pTable
,
pFilter
.
name
,
pTableAlias
];
else
if
(
pTable
)
...
...
@@ -302,7 +324,3 @@ JditoFilterUtils.isUserIgnoreCase = function ()
var
ignoreCase
=
user
?
user
[
tools
.
PARAMS
][
tools
.
SELECTION_IGNORECASE
]
:
""
;
return
ignoreCase
==
""
||
/true/i
.
test
(
ignoreCase
);
}
return
JditoFilterUtils
;
//return only functions that should be public
})();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment