|
|
@ -1,159 +1,180 @@
|
|
|
|
export function customTableFilterFunction(data: any, filter: any) {
|
|
|
|
export function customTableFilterFunction(data: any, filter: any) {
|
|
|
|
if (data.newObject) {
|
|
|
|
if (data.newObject) {
|
|
|
|
return true; // always show new objects
|
|
|
|
return true; // always show newly created objects
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filter.onlyUnsaved && !data.isLockedByMe) {
|
|
|
|
if (filter.onlyUnsaved && !data.isLockedByMe) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const filterElementName of Object.keys(filter.columnFilters)) {
|
|
|
|
for (const filterElementName of Object.keys(filter.columnFilters)) {
|
|
|
|
const filterElement = filter.columnFilters[filterElementName];
|
|
|
|
const filterElement = filter.columnFilters[filterElementName];
|
|
|
|
// String Filter
|
|
|
|
// List Filter - ignore types if column is list
|
|
|
|
if (filterElement.value) {
|
|
|
|
if (filterElement.list && filterElement.values?.length > 0) {
|
|
|
|
if (filterElement.type === 'String' || filterElement.type === 'Id') {
|
|
|
|
let dataElement: Array<any> = data[filterElementName];
|
|
|
|
let searchString = filterElement.value.trim();
|
|
|
|
if (dataElement.length !== filterElement.values.length) {
|
|
|
|
let dataElement = data[filterElementName]?.trim();
|
|
|
|
return false;
|
|
|
|
if (dataElement == null) {
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const element of filterElement.values) {
|
|
|
|
|
|
|
|
if (!dataElement.includes(element)) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!filterElement.options.caseSensitive) {
|
|
|
|
}
|
|
|
|
searchString = searchString.toLowerCase();
|
|
|
|
} else {
|
|
|
|
dataElement = dataElement.toLowerCase();
|
|
|
|
// String Filter
|
|
|
|
|
|
|
|
if (filterElement.value) {
|
|
|
|
|
|
|
|
if (filterElement.type === 'String' || filterElement.type === 'Id') {
|
|
|
|
|
|
|
|
let searchString = filterElement.value.trim();
|
|
|
|
|
|
|
|
let dataElement = data[filterElementName]?.trim();
|
|
|
|
|
|
|
|
if (dataElement == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filterElement.options.caseSensitive) {
|
|
|
|
|
|
|
|
searchString = searchString.toLowerCase();
|
|
|
|
|
|
|
|
dataElement = dataElement.toLowerCase();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
(filterElement.options.exact && dataElement !== searchString) ||
|
|
|
|
|
|
|
|
!dataElement.includes(searchString)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number Filter
|
|
|
|
|
|
|
|
if (filterElement.min != null || filterElement.max != null) {
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
(filterElement.options.exact && dataElement !== searchString) ||
|
|
|
|
filterElement.type === 'Float' ||
|
|
|
|
!dataElement.includes(searchString)
|
|
|
|
filterElement.type === 'Int' ||
|
|
|
|
|
|
|
|
filterElement.type === 'Money'
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
let dataElement = data[filterElementName];
|
|
|
|
|
|
|
|
if (dataElement == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filterElement.min != null && dataElement < filterElement.min) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filterElement.max != null && dataElement > filterElement.max) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// NumberRange Filter
|
|
|
|
// Number Filter
|
|
|
|
if (filterElement.type === 'NumRange') {
|
|
|
|
if (filterElement.min != null || filterElement.max != null) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.minValue.min != null ||
|
|
|
|
|
|
|
|
filterElement.minValue.max != null ||
|
|
|
|
|
|
|
|
filterElement.maxValue.min != null ||
|
|
|
|
|
|
|
|
filterElement.maxValue.max != null
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let dataElementMin = data[filterElementName + '.min'];
|
|
|
|
|
|
|
|
let dataElementMax = data[filterElementName + '.max'];
|
|
|
|
|
|
|
|
if (dataElementMin == null && dataElementMax == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.minValue.min != null &&
|
|
|
|
|
|
|
|
dataElementMin < filterElement.minValue.min
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.minValue.max != null &&
|
|
|
|
|
|
|
|
dataElementMin > filterElement.minValue.max
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.maxValue.min != null &&
|
|
|
|
|
|
|
|
dataElementMax < filterElement.maxValue.min
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.maxValue.max != null &&
|
|
|
|
|
|
|
|
dataElementMax > filterElement.maxValue.max
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Date Filter
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.type === 'Float' ||
|
|
|
|
filterElement.type === 'Date' &&
|
|
|
|
filterElement.type === 'Int' ||
|
|
|
|
(filterElement.from != null || filterElement.to != null)
|
|
|
|
filterElement.type === 'Money'
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let dataElement = data[filterElementName];
|
|
|
|
let dataElement = data[filterElementName];
|
|
|
|
if (dataElement == null) {
|
|
|
|
if (dataElement == null) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filterElement.min != null && dataElement < filterElement.min) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.from != null &&
|
|
|
|
|
|
|
|
new Date(dataElement) < new Date(filterElement.from)
|
|
|
|
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filterElement.max != null && dataElement > filterElement.max) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.to != null &&
|
|
|
|
|
|
|
|
new Date(dataElement) > new Date(filterElement.to)
|
|
|
|
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// DateRange Filter
|
|
|
|
// NumberRange Filter
|
|
|
|
|
|
|
|
if (filterElement.type === 'NumRange') {
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.minValue.min != null ||
|
|
|
|
filterElement.type === 'DateRange' &&
|
|
|
|
filterElement.minValue.max != null ||
|
|
|
|
(filterElement.fromValue.from != null ||
|
|
|
|
filterElement.maxValue.min != null ||
|
|
|
|
filterElement.fromValue.to != null ||
|
|
|
|
filterElement.maxValue.max != null
|
|
|
|
filterElement.toValue.from != null ||
|
|
|
|
|
|
|
|
filterElement.toValue.to != null)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let dataElementMin = data[filterElementName + '.min'];
|
|
|
|
let dataElementFrom = data[filterElementName + '.from'];
|
|
|
|
let dataElementMax = data[filterElementName + '.max'];
|
|
|
|
let dataElementTo = data[filterElementName + '.to'];
|
|
|
|
if (dataElementMin == null && dataElementMax == null) {
|
|
|
|
if (!dataElementFrom && !dataElementTo) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.minValue.min != null &&
|
|
|
|
filterElement.fromValue.from != null &&
|
|
|
|
dataElementMin < filterElement.minValue.min
|
|
|
|
(!dataElementFrom ||
|
|
|
|
|
|
|
|
new Date(dataElementFrom) < new Date(filterElement.fromValue.from))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.minValue.max != null &&
|
|
|
|
filterElement.fromValue.to != null &&
|
|
|
|
dataElementMin > filterElement.minValue.max
|
|
|
|
new Date(dataElementFrom) > new Date(filterElement.fromValue.to)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.maxValue.min != null &&
|
|
|
|
filterElement.toValue.from != null &&
|
|
|
|
dataElementMax < filterElement.maxValue.min
|
|
|
|
new Date(dataElementTo) < new Date(filterElement.toValue.from)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.maxValue.max != null &&
|
|
|
|
filterElement.toValue.to != null &&
|
|
|
|
dataElementMax > filterElement.maxValue.max
|
|
|
|
(!dataElementTo ||
|
|
|
|
|
|
|
|
new Date(dataElementTo) > new Date(filterElement.toValue.to))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Enum Filter
|
|
|
|
// Date Filter
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.type === 'Date' &&
|
|
|
|
|
|
|
|
(filterElement.from != null || filterElement.to != null)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let dataElement = data[filterElementName];
|
|
|
|
|
|
|
|
if (dataElement == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.from != null &&
|
|
|
|
|
|
|
|
new Date(dataElement) < new Date(filterElement.from)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.to != null &&
|
|
|
|
filterElement.type.startsWith('Enum') &&
|
|
|
|
new Date(dataElement) > new Date(filterElement.to)
|
|
|
|
filterElement.value != null &&
|
|
|
|
|
|
|
|
filterElement.value !== data[filterElementName]
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Boolean Filter
|
|
|
|
// DateRange Filter
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.type === 'DateRange' &&
|
|
|
|
|
|
|
|
(filterElement.fromValue.from != null ||
|
|
|
|
|
|
|
|
filterElement.fromValue.to != null ||
|
|
|
|
|
|
|
|
filterElement.toValue.from != null ||
|
|
|
|
|
|
|
|
filterElement.toValue.to != null)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let dataElementFrom = data[filterElementName + '.from'];
|
|
|
|
|
|
|
|
let dataElementTo = data[filterElementName + '.to'];
|
|
|
|
|
|
|
|
if (!dataElementFrom && !dataElementTo) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
filterElement.fromValue.from != null &&
|
|
|
|
filterElement.type === 'Boolean' &&
|
|
|
|
(!dataElementFrom ||
|
|
|
|
((filterElement.value === 'Ja' && !data[filterElementName]) ||
|
|
|
|
new Date(dataElementFrom) < new Date(filterElement.fromValue.from))
|
|
|
|
(filterElement.value === 'Nein' && data[filterElementName]))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.fromValue.to != null &&
|
|
|
|
|
|
|
|
new Date(dataElementFrom) > new Date(filterElement.fromValue.to)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.toValue.from != null &&
|
|
|
|
|
|
|
|
new Date(dataElementTo) < new Date(filterElement.toValue.from)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
filterElement.toValue.to != null &&
|
|
|
|
|
|
|
|
(!dataElementTo ||
|
|
|
|
|
|
|
|
new Date(dataElementTo) > new Date(filterElement.toValue.to))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enum Filter
|
|
|
|
|
|
|
|
if (filterElement.type.startsWith('Enum') && filterElement.value != null && filterElement.value !== data[filterElementName]) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Boolean Filter
|
|
|
|
|
|
|
|
if (filterElement.type === "Boolean" && ((filterElement.value === "Ja" && !data[filterElementName])||(filterElement.value === "Nein" && data[filterElementName]))) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*const b =
|
|
|
|
/*const b =
|
|
|
|