diff --git a/entity/AttributeRelation_entity/entityfields/value/dropDownProcess.js b/entity/AttributeRelation_entity/entityfields/value/dropDownProcess.js index 58bd23d66bf9e0120f1743d51de6686b050bcbe9..c1890064bbc9928717ae61b978c26e8d0407c29e 100644 --- a/entity/AttributeRelation_entity/entityfields/value/dropDownProcess.js +++ b/entity/AttributeRelation_entity/entityfields/value/dropDownProcess.js @@ -9,56 +9,5 @@ import("Sql_lib"); var attributeId = vars.get("$field.AB_ATTRIBUTE_ID"); var attrType = AttributeUtil.getAttributeType(attributeId); -if (attrType == $AttributeTypes.COMBO) -{ - 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) -{ - 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) -{ - 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) -{ - 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 res = AttributeUtil.getPossibleListValues(attributeId, attrType); +result.object(res); \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js index d74496a97c6722e71e00a96b70234c30f5e76b89..7297d0af27dbe96df4118f266659031a73236049 100644 --- a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js +++ b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterConditionProcess.js @@ -1,30 +1,10 @@ -import("AttributeFilter_lib"); -import("system.db"); -import("Context_lib"); -import("Sql_lib"); -import("Attribute_lib"); import("system.vars"); +import("Context_lib"); import("system.result"); +import("AttributeFilter_lib"); -var name = vars.get("$local.name"); -name = AttributeSearchNameCoder.decode(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]); - +var objectType = ContextUtils.getCurrentContextId(); +var filterName = vars.get("$local.name"); +var filterCond = vars.get("$local.condition"); +var resSql = AttributeFilterExtensionMaker.getFilterCondition(objectType, filterName, filterCond); result.string(resSql); \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js index 8dfefc2b1b721b1c1bed7aebe16d0f0a77447800..73d0e5b681ee6bb1378607205846107673b63957 100644 --- a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js +++ b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterFieldsProcess.js @@ -1,35 +1,8 @@ -import("AttributeFilter_lib"); -import("system.util"); import("Context_lib"); -import("Attribute_lib"); -import("system.entities"); +import("AttributeFilter_lib"); import("system.result"); -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 name = AttributeSearchNameCoder.encode(row["UID"], attributeType); - res.push({ - name: name, - 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); +var objectType = ContextUtils.getCurrentContextId(); +var res = AttributeFilterExtensionMaker.getFilterFields(objectType); result.string(res); diff --git a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js index 32fa0526046d7ac0a50deecde885f5ef08beab50..071eda0778b083dde2e81c1e4d714f53e4454eb7 100644 --- a/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js +++ b/entity/Person_entity/recordcontainers/db/filterextensions/attribute_filter/filterValuesProcess.js @@ -1,68 +1,7 @@ -import("AttributeFilter_lib"); -import("Context_lib"); -import("system.translate"); -import("system.db"); -import("system.result"); import("system.vars"); -import("Attribute_lib"); -import("Sql_lib"); - -var filter = JSON.parse(vars.getString("$local.filter")); -var name = name = AttributeSearchNameCoder.decode(filter.name); - -var attributeId = name.id; -var attrType = name.type; - -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")] - ]); -} +import("system.result"); +import("AttributeFilter_lib"); -//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 filter = vars.getString("$local.filter"); +var values = AttributeFilterExtensionMaker.getFilterValues(filter); +result.object(values); \ No newline at end of file diff --git a/neonView/PersonAttributeRestriction_view/PersonAttributeRestriction_view.aod b/neonView/PersonAttributeRestriction_view/PersonAttributeRestriction_view.aod index c1e84b0caa51196b42b3afae514917e6e551b0c6..4ae99a71b66ac2d4b044a16890773c5b2783ef47 100644 --- a/neonView/PersonAttributeRestriction_view/PersonAttributeRestriction_view.aod +++ b/neonView/PersonAttributeRestriction_view/PersonAttributeRestriction_view.aod @@ -11,7 +11,7 @@ <children> <neonViewReference> <name>0398cc40-98f9-42a5-a2ed-938a5e8945e0</name> - <entityField>Attributes</entityField> + <entityField>AttributeTree</entityField> <view>AttributeRelationTree_view</view> </neonViewReference> <neonViewReference> diff --git a/process/AttributeFilter_lib/process.js b/process/AttributeFilter_lib/process.js index 51cfbb2887c32e1377cfbb4efad921610aac96c2..93288644a582cdd162b89591a5d569795ced5257 100644 --- a/process/AttributeFilter_lib/process.js +++ b/process/AttributeFilter_lib/process.js @@ -1,3 +1,7 @@ +import("system.db"); +import("Sql_lib"); +import("Attribute_lib"); +import("system.entities"); import("system.util"); function AttributeSearchNameCoder(){} @@ -20,3 +24,77 @@ AttributeSearchNameCoder.decode = function (pEncodedString) res = JSON.parse(res); return res }; + +function AttributeFilterExtensionMaker() {} + +AttributeFilterExtensionMaker.getFilterFields = function(pObjectType) +{ + var res = []; + + var loadingConfig = entities.createConfigForLoadingRows().entity("Attribute_entity") + .provider("SpecificAttribute") + .fields(["UID", "FULL_ATTRIBUTE_NAME", "ATTRIBUTE_TYPE"]) + .addParameter("ObjectType_param", pObjectType); + + var attributeRows = entities.getRows(loadingConfig); + + attributeRows.forEach(function(row){ + var attributeType = row["ATTRIBUTE_TYPE"]; + var contentType = AttributeTypeUtil.getContentType(attributeType); + + if (contentType) + { + var name = AttributeSearchNameCoder.encode(row["UID"], attributeType); + res.push({ + name: name, + title: row["FULL_ATTRIBUTE_NAME"], + //TODO: comment why this workaround is necessary + contentType: contentType == "UNKNOWN" ? "TEXT" : contentType, + hasDropDownValues: contentType == "UNKNOWN" || contentType == "BOOLEAN" ? true : false + }); + } + }); + + res = JSON.stringify(res); + return res; +}; + +AttributeFilterExtensionMaker.getFilterValues = function(pFilter) +{ + var filter = JSON.parse(pFilter); + var name = name = AttributeSearchNameCoder.decode(filter.name); + + var attributeId = name.id; + var attrType = name.type; + + var res = AttributeUtil.getPossibleListValues(attributeId, attrType); + if (res == null) + res = []; + return res; +}; + +AttributeFilterExtensionMaker.getFilterCondition = function(pObjectType, pFilterName, pCondition) +{ + var name = pFilterName; + name = AttributeSearchNameCoder.decode(name); + var attributeId = name.id; + var dbField = AttributeTypeUtil.getDatabaseField(name.type); + + var condition = pCondition; + condition = condition.replace("{'table.column'}", dbField, "g"); + + var preparedValues = [ + [pObjectType, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.OBJECT_TYPE")], + [attributeId, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")] + ]; + //TODO: dynmic mapping of UID and TABLE + 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]); + return resSql; +}; \ No newline at end of file diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js index 243d815a99d35ae9d757fda96cb552a184f4b330..aa14cfb5aea047d7488bd3ce81640b0a056e709e 100644 --- a/process/Attribute_lib/process.js +++ b/process/Attribute_lib/process.js @@ -1,3 +1,4 @@ +import("KeywordData_lib"); import("Context_lib"); import("system.util"); import("system.datetime"); @@ -73,6 +74,62 @@ AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFi return attributes; } +//TODO: comment function +AttributeUtil.getPossibleListValues = function (pAttributeId, pAttributeType, pIncludeInactives) +{ + var attributeId = pAttributeId; + var attrType = pAttributeType.trim(); + var onlyActives = (pIncludeInactives == undefined ? false : pIncludeInactives); + if (attrType == $AttributeTypes.COMBO.toString()) + { + var valueSql = SqlCondition.begin() + .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId) + .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE); + + if (onlyActives) + valueSql.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1"); + + valueSql = valueSql.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]); + } + return valueList; + } + else if (attrType == $AttributeTypes.BOOLEAN.toString()) + { + return [ + ["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 attrKeyword = db.cell(attrKeywordSelect); + var keywords = KeywordData.getSimpleData(attrKeyword, null, onlyActives); + return keywords; + } + else if (attrType == $AttributeTypes.OBJECTSELECTION) + { + 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)); + + return objects; + } + else + return null; +} + /** * returns the name of an attribute with all parent attribute names * diff --git a/process/DataCaching_lib/process.js b/process/DataCaching_lib/process.js index 97c01f7ee15dbe7b1fdbd7678b1d521499f0d094..967f3fe35dc6ff0d672e080312e771a3aa4e3062 100644 --- a/process/DataCaching_lib/process.js +++ b/process/DataCaching_lib/process.js @@ -7,12 +7,12 @@ import("system.project"); * * on client side it's done with the helb of a $global.***-variable * - * @class * * @param {String} pIdentifiyingName name to identify the DataCache. This MUST be unique for one data representation (e.g. key-value pair for all Languages with key ISO2-code and value the ISO3-Code). this will affect the storage-name (=name of the global variable on the client for example) * @param {bool} [pKeepPerLanguage=false] if true the data is kept per locale (different storing for each requested language), false when not (every language is sharing the same stoarge because only untranslated data is kept) * @param {String} [pLocaleOverride=current language] sometimes a special locale is required, use this parameter to specify it * + * @class */ function CachedData(pIdentifiyingName, pKeepPerLanguage, pLocaleOverride) { diff --git a/process/KeywordData_lib/process.js b/process/KeywordData_lib/process.js index c246fabf138954f52f1f37daba850f4bf8a99f07..1b256b9fd5076b89b11f1660a481f36464c9b447 100644 --- a/process/KeywordData_lib/process.js +++ b/process/KeywordData_lib/process.js @@ -13,11 +13,18 @@ The idea behind this is to maintain data in cached form (client-context-side)) f function KeywordData(){} -KeywordData.getSimpleData = function (pKeywordContainer, pLocale) +KeywordData.getSimpleData = function (pKeywordContainer, pLocale, pOnlyActives) { - var cache = new CachedData("KeywordSimpleData_" + pKeywordContainer, true, pLocale); + var onlyActives = (pOnlyActives == undefined ? true : pOnlyActives); + var flags = "#" + (onlyActives ? "1" : "0"); + var identifier = "KeywordSimpleData_" + pKeywordContainer + flags; + var cache = new CachedData(identifier, true, pLocale); return cache.load(function (pTranslationNecessary, pLocale){ var cond = SqlCondition.begin().andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer); + + if (onlyActives) + cond.andPrepare("AB_KEYWORD_ENTRY.ISACTIVE", "1"); + var keywordData = db.table(cond.buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", null, "order by AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc"));