From 03205c5cda30c043174638990477520fe449615e Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Fri, 17 May 2019 16:36:24 +0200 Subject: [PATCH] Jdito entities filter fix --- .../recordcontainers/jdito/contentProcess.js | 4 +- entity/Attribute_entity/Attribute_entity.aod | 1 + .../recordcontainers/jdito/contentProcess.js | 4 +- entity/Employee_entity/Employee_entity.aod | 1 + .../recordcontainers/jdito/contentProcess.js | 92 +++++++++---------- .../recordcontainers/jdito/contentProcess.js | 4 +- .../recordcontainers/jdito/contentProcess.js | 2 +- process/JditoFilter_lib/process.js | 22 +++-- 8 files changed, 68 insertions(+), 62 deletions(-) diff --git a/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js b/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js index 545b0cad0f..b1d24bc530 100644 --- a/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js @@ -12,9 +12,9 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param" var active; var selectMap = ContextUtils.getSelectMap () - if(vars.exists("$local.filter") && vars.get("$local.filter") ) + if(vars.exists("$local.userfilter") && vars.get("$local.userfilter") ) { - var filter = JSON.parse(vars.getString("$local.filter")); + var filter = JSON.parse(vars.getString("$local.userfilter")); if(filter.childs != null && filter.childs.length > 0) { filter.childs.forEach(function(child) diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod index 0159ec31d7..9cad18c9b6 100644 --- a/entity/Attribute_entity/Attribute_entity.aod +++ b/entity/Attribute_entity/Attribute_entity.aod @@ -320,6 +320,7 @@ <jDitoRecordContainer> <name>jdito</name> <jDitoRecordAlias>Data_alias</jDitoRecordAlias> + <isFilterable v="true" /> <isSortable v="true" /> <contentProcess>%aditoprj%/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js</contentProcess> <onInsert>%aditoprj%/entity/Attribute_entity/recordcontainers/jdito/onInsert.js</onInsert> diff --git a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js index 43b6453431..bdc684d998 100644 --- a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js @@ -69,9 +69,9 @@ else if (parentType) } //when there are filters selected, add them to the conditon -if (vars.exists("$local.filter") && vars.get("$local.filter")) +if (vars.exists("$local.userfilter") && vars.get("$local.userfilter")) { - var filter = vars.get("$local.filter"); + var filter = vars.get("$local.userfilter"); condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE", uidTableAlias)); } diff --git a/entity/Employee_entity/Employee_entity.aod b/entity/Employee_entity/Employee_entity.aod index 84dfd7afd6..9dcc179921 100644 --- a/entity/Employee_entity/Employee_entity.aod +++ b/entity/Employee_entity/Employee_entity.aod @@ -276,6 +276,7 @@ <jDitoRecordContainer> <name>jdito</name> <jDitoRecordAlias>Data_alias</jDitoRecordAlias> + <isFilterable v="true" /> <contentProcess>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/contentProcess.js</contentProcess> <onInsert>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/onInsert.js</onInsert> <onUpdate>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/onUpdate.js</onUpdate> diff --git a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js index 80ce5b73b0..64059e4ae1 100644 --- a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js @@ -1,46 +1,46 @@ -import("Attribute_lib"); -import("system.vars"); -import("system.result"); -import("system.tools"); -import("Util_lib"); -import("Contact_lib"); -import("JditoFilter_lib"); -import("Employee_lib"); - -var users; -if (vars.exists("$local.idvalues") && vars.get("$local.idvalues")) - users = [tools.getUserByAttribute(tools.NAME, vars.get("$local.idvalues"), tools.PROFILE_FULL)]; -else -{ - var values = ["true", "false"]; - if (vars.exists("$param.OnlyActives_param") && vars.get("$param.OnlyActives_param") == "true") - values = ["true"]; - users = tools.getUsersByAttribute(tools.ISACTIVE, values, tools.PROFILE_FULL); -} - -users = users.map(function (user) -{ - return [ - user[tools.NAME], - user[tools.TITLE], - user[tools.PARAMS][tools.ISACTIVE], - user[tools.PARAMS][tools.FIRSTNAME], - user[tools.PARAMS][tools.LASTNAME], - user[tools.PARAMS][tools.EMAIL], - user[tools.PARAMS][tools.EMAIL], - user[tools.DESCRIPTION], - user[tools.PARAMS][tools.CONTACTID], - ContactUtils.getTitleByContactId(user[tools.PARAMS][tools.CONTACTID]), //TODO: get the names more efficiently - user[tools.PARAMS].department - ]; -}); - -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); - - -ArrayUtils.sort2d(users, 0, true, false); //sort by username - -result.object(users); +import("Attribute_lib"); +import("system.vars"); +import("system.result"); +import("system.tools"); +import("Util_lib"); +import("Contact_lib"); +import("JditoFilter_lib"); +import("Employee_lib"); + +var users; +if (vars.exists("$local.idvalues") && vars.get("$local.idvalues")) + users = [tools.getUserByAttribute(tools.NAME, vars.get("$local.idvalues"), tools.PROFILE_FULL)]; +else +{ + var values = ["true", "false"]; + if (vars.exists("$param.OnlyActives_param") && vars.get("$param.OnlyActives_param") == "true") + values = ["true"]; + users = tools.getUsersByAttribute(tools.ISACTIVE, values, tools.PROFILE_FULL); +} + +users = users.map(function (user) +{ + return [ + user[tools.NAME], + user[tools.TITLE], + user[tools.PARAMS][tools.ISACTIVE], + user[tools.PARAMS][tools.FIRSTNAME], + user[tools.PARAMS][tools.LASTNAME], + user[tools.PARAMS][tools.EMAIL], + user[tools.PARAMS][tools.EMAIL], + user[tools.DESCRIPTION], + user[tools.PARAMS][tools.CONTACTID], + ContactUtils.getTitleByContactId(user[tools.PARAMS][tools.CONTACTID]), //TODO: get the names more efficiently + user[tools.PARAMS].department + ]; +}); + +var filter = vars.exists("$local.userfilter") && vars.get("$local.userfilter"); + +//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); + + +ArrayUtils.sort2d(users, 0, true, false); //sort by username + +result.object(users); diff --git a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js index 523c016b47..73d3aecdff 100644 --- a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js @@ -31,9 +31,9 @@ var tableNameCond = _getTableNameCondition(); recordCond.andSqlCondition(tableNameCond); //user defined filter -if (vars.exists("$local.filter") && vars.get("$local.filter")) +if (vars.exists("$local.userfilter") && vars.get("$local.userfilter")) { - var filter = vars.get("$local.filter"); + var filter = vars.get("$local.userfilter"); recordCond.andSqlCondition((JditoFilterUtils.getSqlCondition(filter, "AB_LOGHISTORY"))); } diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js index ede1d023d2..d94c0ac96e 100644 --- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js @@ -33,7 +33,7 @@ if (uidParam) } else { - var filter = vars.get("$local.filter") + var filter = vars.get("$local.userfilter") var selectedRelationType = null; if (filter) diff --git a/process/JditoFilter_lib/process.js b/process/JditoFilter_lib/process.js index b0d8729036..0213e4a5e6 100644 --- a/process/JditoFilter_lib/process.js +++ b/process/JditoFilter_lib/process.js @@ -97,7 +97,7 @@ function JditoFilterUtils () {} * @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 + * @param {String|Object} pFilter the value of $local.userfilter * * @return {Array} the filtered records */ @@ -117,19 +117,25 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter) /** * builds an sql condition from the given filter * - * @param {String|Object} pFilter the filter as JSON + * @param {Object} pFilter the filter object * @param {String} pTable the database table * @param {String} [pTableAlias=null] the database table alias - * @param {Object} [pColumnMap=null] custom mapping for the fields to the DB columns, this is necessary - * if the fields are from different tables + * @param {Object} [pColumnMap=null] Custom mapping for the fields to the DB columns, this is necessary + * if the fields are from different tables. Structure has to be like this: + * { + * FIELD1 : "TABLE1.COLUMN1", + * FIELD2 : ["TABLE2", "COLUMN2", "TABLE2ALIAS"] //do it like this if the table has an alias + * } * * @example - * if (vars.exists("$local.filter") && vars.get("$local.filter")) + * var condition = SqlCondition.begin(); + * if (vars.exists("$local.userfilter") && vars.get("$local.userfilter")) * { - * var filter = vars.get("$local.filter"); + * var filter = vars.get("$local.userfilter"); * condition.andSqlCondition((JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE"))); * } - * + * var attributeSql = condition.buildSql("select AB_ATTRIBUTEID from AB_ATTRIBUTE"); + * * @return {SqlCondition} the SqlCondition object */ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColumnMap) @@ -138,8 +144,6 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu if (!pFilter) return condition; - if (pFilter.length) //check if pFilter is a string - pFilter = pFilter; if (!pColumnMap) pColumnMap = {}; -- GitLab