From 8ce9bba3b0ddc02bf50cbc0b8be58ea958e44123 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Tue, 30 Apr 2019 09:16:11 +0200
Subject: [PATCH] Employee filter

---
 entity/Employee_entity/Employee_entity.aod    |  6 ++++--
 .../recordcontainers/jdito/contentProcess.js  |  2 +-
 process/JditoFilter_lib/process.js            | 20 ++++++++++---------
 process/Organisation_lib/process.js           |  7 ++++---
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/entity/Employee_entity/Employee_entity.aod b/entity/Employee_entity/Employee_entity.aod
index 69043649be7..f7904d74a5f 100644
--- a/entity/Employee_entity/Employee_entity.aod
+++ b/entity/Employee_entity/Employee_entity.aod
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.2">
   <name>Employee_entity</name>
-  <title>Employee</title>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <title>Employee</title>
   <afterUiInit>%aditoprj%/entity/Employee_entity/afterUiInit.js</afterUiInit>
   <onValidation>%aditoprj%/entity/Employee_entity/onValidation.js</onValidation>
   <afterOperatingState>%aditoprj%/entity/Employee_entity/afterOperatingState.js</afterOperatingState>
-  <iconId>VAADIN:GROUP</iconId>
+  <iconId>VAADIN:USER</iconId>
   <titleProcess>%aditoprj%/entity/Employee_entity/titleProcess.js</titleProcess>
   <recordContainer>jdito</recordContainer>
   <entityFields>
@@ -277,9 +277,11 @@
     </entityConsumer>
     <entityField>
       <name>USERID</name>
+      <searchable v="false" />
     </entityField>
     <entityField>
       <name>USERID_SMALL</name>
+      <searchable v="false" />
     </entityField>
   </entityFields>
   <recordContainers>
diff --git a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
index 95997876508..5013833de46 100644
--- a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
@@ -40,7 +40,7 @@ users = users.map(function (user)
 var filter = vars.exists("$local.filter") && vars.get("$local.filter"); 
 
 //TODO: this is a workaround that filters the records manually, it should be possible to filter the users with a tools.* method
-users = JditoFilterUtils.filterRecords(["UID", "TITLE", "ISACTIVE", "FIRSTNAME", "LASTNAME", "EMAIL_ADDRESS", "DESCRIPTION", "CONTACT_ID", "", "DEPARTMENT"], users, filter);
+users = JditoFilterUtils.filterRecords(["UID", "TITLE", "ISACTIVE", "FIRSTNAME", "LASTNAME", "EMAIL_ADDRESS", "", "DESCRIPTION", "CONTACT_ID", "", "DEPARTMENT"], users, filter);
 
 
 ArrayUtils.sort2d(users, 0, true, false); //sort by username
diff --git a/process/JditoFilter_lib/process.js b/process/JditoFilter_lib/process.js
index a0da9e16d8b..7513c9b881d 100644
--- a/process/JditoFilter_lib/process.js
+++ b/process/JditoFilter_lib/process.js
@@ -6,12 +6,13 @@ import("Sql_lib");
  * @param {Array} pColumns the column names
  * @param {String|Object} pFilter the filter object
  */
-function JditoFilter (pColumns, pFilter) 
+function JditoFilterHelper (pColumns, pFilter) 
 {
     var columnMap = {};
     pColumns.forEach(function (row, i)
     {
-        columnMap[row] = i;
+        if (row)
+            columnMap[row] = i;
     });
     this._columnMap = columnMap;
     
@@ -29,7 +30,7 @@ function JditoFilter (pColumns, pFilter)
  * 
  * @return {boolean} true, if it matches the condition
  */
-JditoFilter.prototype.checkRecord = function (pRow)
+JditoFilterHelper.prototype.checkRecord = function (pRow)
 {
     if (this._filters.length == 0)
         return true;
@@ -49,7 +50,7 @@ JditoFilter.prototype.checkRecord = function (pRow)
 /**
  * compares two values with the given operator
  */
-JditoFilter.prototype._testValue = function (pRowValue, pFilterValue, pOperator)
+JditoFilterHelper.prototype._testValue = function (pRowValue, pFilterValue, pOperator)
 {
     switch (pOperator)
     {
@@ -81,8 +82,7 @@ JditoFilter.prototype._testValue = function (pRowValue, pFilterValue, pOperator)
 }
 
 /**
- * Provides functions for using the filter with jdito recordcontainers. You should only use this
- * if there is no other, faster way to filter the records
+ * Provides functions for using the filter with jdito recordcontainers
  * 
  * Do not instanciate this!
  * 
@@ -91,9 +91,11 @@ JditoFilter.prototype._testValue = function (pRowValue, pFilterValue, pOperator)
 function JditoFilterUtils () {}
 
 /**
- * Filters the given records
+ * Filters the given records manually. If you get the records using a sql query, you might consider using
+ * JditoFilterUtils.getSqlCondition instead for better performance.
  * 
- * @param {Array} pColumns one dimensional array with all column names, the order has to match the columns of pRecords
+ * @param {Array} pColumns one dimensional array with all column names (only the columns with the idValue, displayValue columns should be null or ""), 
+ *                          the order has to match the columns of the recordFields property in the recordcontainer
  * @param {Array} pRecords two dimensional array with all records
  * @param {String|Object} pFilter the value of $local.filter
  * 
@@ -104,7 +106,7 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter)
     if (!pFilter)
         return pRecords;
     
-    var filter = new JditoFilter(pColumns, pFilter);
+    var filter = new JditoFilterHelper(pColumns, pFilter);
     
     return pRecords.filter(function (row)
         {
diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js
index e661ac0b184..ba6c5b3c1d7 100644
--- a/process/Organisation_lib/process.js
+++ b/process/Organisation_lib/process.js
@@ -1,3 +1,4 @@
+import("Util_lib");
 import("system.datetime");
 import("system.translate");
 import("system.db");
@@ -173,8 +174,8 @@ OrgUtils.openOrgReport = function(pOrgId)
     {
         if (pJoinSeparator == undefined)
             pJoinSeparator = " ";
-        pArr.splice(pIndex, pHowMany, 
-            pArr.slice(pIndex, pIndex + pHowMany)
-                .filter(function (val) {return val;}).join(pJoinSeparator));
+        pArr.splice(pIndex, pHowMany, ArrayUtils.joinNonEmptyFields(
+            pArr.slice(pIndex, pIndex + pHowMany), pJoinSeparator)
+        );
     }
 }
\ No newline at end of file
-- 
GitLab