diff --git a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js index c4a6ddac89829a46dc0bf86b8ab943090f6af753..65d6b67c6e0affc794a04043f264fa103f4c2ba0 100644 --- a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js +++ b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js @@ -1,30 +1,5 @@ -import("system.db"); -import("Context_lib"); -import("Sql_lib"); -import("Attribute_lib"); -import("system.vars"); import("system.result"); +import("AttributeFilter_lib"); -var name = vars.get("$local.name"); -name = name.substr(name.lastIndexOf(".")+1); -name = JSON.parse(name); -var attributeId = name.id; -var dbField = AttributeTypeUtil.getDatabaseField(name.type); - -var condition = vars.get("$local.condition"); -condition = condition.replace("{'table.column'}", dbField, "g"); - -var preparedValues = [ - [ContextUtils.getCurrentContextId(), SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.OBJECT_TYPE")], - [attributeId, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")] -]; -var resSql = "CONTACTID in (select CONTACT.CONTACTID \n\ - from CONTACT \n\ - left join AB_ATTRIBUTERELATION on (AB_ATTRIBUTERELATION.OBJECT_ROWID = CONTACT.CONTACTID \n\ - and AB_ATTRIBUTERELATION.OBJECT_TYPE = ? \n\ - and AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = ?) \n\ - where " + condition + " )"; - -resSql = db.translateCondition([resSql, preparedValues]); - -result.string(resSql); \ No newline at end of file +var sqlCond = AttributeFilterExtensionMaker.makeFilterConditionSql(); +result.string(sqlCond); \ No newline at end of file diff --git a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js index 9568f5e59030d2e884de8daa7c4cb736663311ac..209ddd39ef4a15b1190ef2bd4955ccdc78f5808b 100644 --- a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js +++ b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js @@ -1,33 +1,5 @@ -import("Context_lib"); -import("Attribute_lib"); -import("system.entities"); import("system.result"); +import("AttributeFilter_lib"); -var res = []; - -var loadingConfig = entities.createConfigForLoadingRows().entity("Attribute_entity") - .provider("SpecificAttribute") - .fields(["UID", "FULL_ATTRIBUTE_NAME", "ATTRIBUTE_TYPE"]) - .addParameter("ObjectType_param", ContextUtils.getCurrentContextId()); - -var attributeRows = entities.getRows(loadingConfig); - -attributeRows.forEach(function(row){ - var attributeType = row["ATTRIBUTE_TYPE"]; - var contentType = AttributeTypeUtil.getContentType(attributeType); - - if (contentType) - { - var id = {id: row["UID"], type: attributeType}; - id = JSON.stringify(id); - res.push({ - name: id, - title: row["FULL_ATTRIBUTE_NAME"], - contentType: contentType == "UNKNOWN" ? "TEXT" : contentType, //TODO: temporary test - hasDropDownValues: contentType == "UNKNOWN" || contentType == "BOOLEAN" ? true : false//TODO: temporary test - }); - } -}); - -res = JSON.stringify(res); -result.string(res); \ No newline at end of file +var fields = AttributeFilterExtensionMaker.makeFilterFields(); +result.string(fields); \ No newline at end of file diff --git a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js index 91a48d820e677ac2e1d6161a88c07092253c1522..942b0a0495a179f9c25d19330bb8cd59c5563ec0 100644 --- a/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js +++ b/entity/Organisation_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js @@ -1,66 +1,5 @@ -import("Context_lib"); -import("system.translate"); -import("system.db"); import("system.result"); -import("system.vars"); -import("Attribute_lib"); -import("Sql_lib"); +import("AttributeFilter_lib"); -var filter = JSON.parse(vars.getString("$local.filter")); -var name = JSON.parse(filter.name); -var attributeId = name.id; -var attrType = name.type.trim(); - -if (attrType == $AttributeTypes.COMBO.toString()) -{ - var valueSql = SqlCondition.begin() - .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1") - .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId) - .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE) - .buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2", "order by SORTING asc"); - var valueList = db.table(valueSql); - for (let i = 0; i < valueList.length; i++) - { - valueList[i][1] = translate.text(valueList[i][1]); - } - result.object(valueList); -} -else if (attrType == $AttributeTypes.BOOLEAN.toString()) -{ - result.object([ - ["1", translate.text("Yes")], - ["0", translate.text("No")] - ]); -} - -//TODO this is a workaround for keywords, when it's possible to use the consumer remove this -else if (attrType == $AttributeTypes.KEYWORD.toString()) -{ - var attrKeywordSelect = "select DROPDOWNDEFINITION from AB_ATTRIBUTE"; - attrKeywordSelect = SqlCondition.begin() - .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId) - .buildSql(attrKeywordSelect); - - var sql = SqlCondition.begin() - .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", db.cell(attrKeywordSelect)) - .buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", "1=2", "order by SORTING asc"); - - var keywords = db.table(sql).map(function (row) - { - return [row[0], translate.text(row[1])]; - }); - result.object(keywords); -} -else if (attrType == $AttributeTypes.OBJECTSELECTION.toString()) -{ - var module = db.cell(SqlCondition.begin() - .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId) - .buildSql("select DROPDOWNDEFINITION from AB_ATTRIBUTE") - ); - var objects = []; - objects = db.table(ContextUtils.getContextDataSql(module)); - - result.object(objects); -} -else - result.object(null) \ No newline at end of file +var values = AttributeFilterExtensionMaker.makeFilterValues(); +result.object(values); \ No newline at end of file