diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/reasons/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/reasons/customproperties/translate4log/property.js index ae7a4a855253f880b0d6a9ae26530a6644fa8c6e..80b52d4b33c56c395ebc8f7f85f6fe43e6ddfc98 100644 --- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/reasons/customproperties/translate4log/property.js +++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/salesproject/entityfields/reasons/customproperties/translate4log/property.js @@ -1,30 +1,31 @@ -import("system.result"); -import("Keyword_lib"); -import("system.text"); -import("Loghistory_lib"); -import("KeywordRegistry_basic") - -var params = Translate4LogParams.load(); -var reasons = params.value; -if (reasons) -{ - reasons = text.decodeMS(reasons); - if (reasons.length) - { - var keywordMap = {}; - KeywordUtils.getEntryNamesAndIdsByContainer( - $KeywordRegistry.salesprojectWonLost(), - params.locale - ).forEach(function (keyword) - { - this[keyword[0]] = keyword[1]; - }, keywordMap); - reasons = reasons.map(function (reasonId) - { - return this[reasonId]; - }, keywordMap).join(", "); - } - else - reasons = ""; -} -result.string(reasons); \ No newline at end of file +import("system.result"); +import("Keyword_lib"); +import("system.text"); +import("Loghistory_lib"); +import("KeywordRegistry_basic") +import("KeywordData_lib") + +var params = Translate4LogParams.load(); +var res = ""; +var reasons = params.value; +if (reasons) +{ + reasons = text.decodeMS(reasons); + if (reasons.length) + { + var keywordMap = KeywordData.getKeyIdMap($KeywordRegistry.salesprojectWonLost(), params.locale); + //translate and join all keyIds to titles, if not found the value is discarded + res = reasons.reduce(function (accumulator, currentVal){ + if (keywordMap[currentVal]) + { + if (accumulator != "") + return accumulator + ", " + keywordMap[currentVal]; + else + return keywordMap[currentVal]; + } + else + return accumulator; + }, ""); + } +} +result.string(res); \ No newline at end of file diff --git a/entity/Activity_entity/entityfields/direction_icon/valueProcess.js b/entity/Activity_entity/entityfields/direction_icon/valueProcess.js index e85335e068c6fbcbc078e01a4a361663c2089a55..93b7fb473ae54e68aa2cd0a1f85c5cd1228e4718 100644 --- a/entity/Activity_entity/entityfields/direction_icon/valueProcess.js +++ b/entity/Activity_entity/entityfields/direction_icon/valueProcess.js @@ -1,31 +1,10 @@ -import("system.vars"); -import("system.result"); -import("system.neon"); -import("KeywordRegistry_basic"); -import("Keyword_lib"); - -var direction = vars.getString("$field.DIRECTION"); - -if (direction) -{ - // cache to prevent multiple loading of the same icon-names - if (vars.exists("$context.cache_activity_dir-icon_" + direction) && vars.get("$context.cache_activity_dir-icon_" + direction)) - { - result.string(vars.get("$context.cache_activity_dir-icon_" + direction)); - } - else - { - var res = KeywordUtils.getAttributeRelationsByKey(direction, $KeywordRegistry.activityDirection())["icon"]; - - if (res) - { - result.string(res); - vars.set("$context.cache_activity_dir-icon_" + direction, res); - } - else - { - result.string(""); - vars.set("$context.cache_activity_dir-icon_" + direction, ""); - } - } -} \ No newline at end of file +import("system.vars"); +import("system.result"); +import("system.neon"); +import("KeywordRegistry_basic"); +import("Keyword_lib"); + +var direction = vars.getString("$field.DIRECTION"); + +var icon = KeywordUtils.getAttributeRelationsByKey(direction, $KeywordRegistry.activityDirection())["icon"]; +result.string(icon || ""); \ No newline at end of file diff --git a/process/KeywordData_lib/process.js b/process/KeywordData_lib/process.js index dc4ad29070aa5ef975edfede9808cf37cdede3a6..f782c9e6b2f7bad4b97a04bd090fce0b5663f149 100644 --- a/process/KeywordData_lib/process.js +++ b/process/KeywordData_lib/process.js @@ -1,6 +1,7 @@ import("system.translate"); import("system.db"); import("DataCaching_lib"); +import("Sql_lib"); function KeywordData(){} @@ -9,7 +10,8 @@ KeywordData.getSimpleData = function (pKeywordContainer, pLocale) var cache = new CachedData("KeywordSimpleData_" + pKeywordContainer, true, pLocale); return cache.load(function (pTranslationNecessary, pLocale){ var cond = SqlCondition.begin().andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer); - var keywordData = db.table(cond.buildSql(("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY"))); + 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")); for (var i = 0, l = keywordData.length; i < l; i++) { @@ -35,6 +37,54 @@ KeywordData.getKeyIdMap = function (pKeywordContainer, pLocale) }); }; +KeywordData.getKeywordAttributeRelations = function (pKeywordContainer) +{ + var data = CachedData.make("KeywordAttributeRelationObj_" + pKeywordContainer, false, function(){ + var cond = SqlCondition.begin() + .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer); + + var sql = cond.buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.TYPE, \n\ + AB_KEYWORD_ATTRIBUTERELATION.CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.NUMBER_VALUE, AB_KEYWORD_ATTRIBUTERELATION.BOOL_VALUE \n\ + from AB_KEYWORD_ENTRY \n\ + join AB_KEYWORD_ATTRIBUTE on (AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER) \n\ + left join AB_KEYWORD_ATTRIBUTERELATION \n\ + on (AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID = AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID\n\ + and AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID)"); + + var data = db.table(sql); + var res = {}; + var keyId, name, type, charVal, numVal, boolVal; + + for (var i = 0, l = data.length; i < l; i++) + { + [keyId, name, type, charVal, numVal, boolVal] = data[i]; + name = name.trim(); + type = type.trim(); + if (res[keyId] == undefined) + res[keyId] = {}; + + var parsedValue = null; + switch(type) + { + case "NUMBER_VALUE": + parsedValue = numVal == "" ? null : Number(numVal); + break; + case "BOOL_VALUE": + parsedValue = boolVal == "" ? null : (boolVal == "1"); + break; + case "CHAR_VALUE": + parsedValue = charVal == "" ? null : charVal; + break; + } + + res[keyId][name] = parsedValue; + } + return res; + }); + + return data; +} + function LanguageData(){} LanguageData.getData = function() diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js index 95d93c4caf30899be797424e26016ed02bc581fa..12e4083b349d6f5aa5d14f18eacf803987962141 100644 --- a/process/Keyword_lib/process.js +++ b/process/Keyword_lib/process.js @@ -54,22 +54,6 @@ KeywordUtils.getViewValue = function(keywordContainer, key, locale) return data[key]; }; - -/** - * collects possible and defined keyword-attributes per keyword entry and returns them - * - * @param {String} pEntryId id that identifies the keyword-entry whoes attributes are collected - * @return {Object} key-value-pair of the keyword-attributes; contains all attribute-keys for the keywords-entries container; - * if there is no value set for a key the null-value is given - */ -KeywordUtils.getAttributeRelationsByEntryId = function(pEntryId) -{ - var cond = SqlCondition.begin() - .andPrepare("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", pEntryId); - - return KeywordUtils._getKeywordAttributeRelations(cond); -}; - /** * collects possible and defined keyword-attributes per keyword entry and returns them * @@ -81,56 +65,15 @@ KeywordUtils.getAttributeRelationsByEntryId = function(pEntryId) */ KeywordUtils.getAttributeRelationsByKey = function(pKeyId, pContainerName) { - var cond = SqlCondition.begin() - .andPrepare("AB_KEYWORD_ENTRY.KEYID", pKeyId) - .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName); - - return KeywordUtils._getKeywordAttributeRelations(cond); -}; - -/** - * internal function that collects possible and defined keyword-attributes per keyword entry and returns them - * - * @param {SqlCondition} pSqlCondition condition that shrinks a resultset to one AB_KEYWORD_ENTRY - * @return {Object} SQL-Condition object that filters - */ -KeywordUtils._getKeywordAttributeRelations = function (pSqlCondition) -{ - var cond = pSqlCondition; - var sql = cond.buildSql("select AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.TYPE, \n\ - AB_KEYWORD_ATTRIBUTERELATION.CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.NUMBER_VALUE, AB_KEYWORD_ATTRIBUTERELATION.BOOL_VALUE \n\ - from AB_KEYWORD_ENTRY \n\ - join AB_KEYWORD_ATTRIBUTE on (AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER) \n\ - left join AB_KEYWORD_ATTRIBUTERELATION \n\ - on (AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID = AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID\n\ - and AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID)"); - - var data = db.table(sql); - var res = {}; - var name, type, charVal, numVal, boolVal; + if (!pKeyId) + return ""; - for (var i = 0, l = data.length; i < l; i++) - { - [name, type, charVal, numVal, boolVal] = data[i]; - name = name.trim(); - type = type.trim(); - var parsedValue = null; - switch(type) - { - case "NUMBER_VALUE": - parsedValue = numVal == "" ? null : Number(numVal); - break; - case "BOOL_VALUE": - parsedValue = boolVal == "" ? null : (boolVal == "1"); - break; - case "CHAR_VALUE": - parsedValue = charVal == "" ? null : charVal; - break; - } + var data = KeywordData.getKeywordAttributeRelations(pContainerName); - res[name] = parsedValue; - } - return res; + if (data[pKeyId] == undefined) + return {}; + else + return data[pKeyId]; }; /** @@ -155,13 +98,11 @@ KeywordUtils.getContainerNames = function() */ KeywordUtils.getEntryNamesByContainer = function(pContainerName, pLocale) { - var sql = SqlCondition.begin() - .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName) - .buildSql("select AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", null, "order by AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc") - var list = db.array(db.COLUMN, sql).map(function (v){ - return pLocale ? translate.text(v, pLocale) : translate.text(v); + var data = KeywordData.getSimpleData(pContainerName, pLocale); + data = data.map(function (v){ + return v[1]; }); - return list; + return data; };