Skip to content
Snippets Groups Projects
Commit 28f3a890 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

[Projekt: Entwicklung - Neon][TicketNr.: 1041584][Filter - Attribute]

parent d05018a5
No related branches found
No related tags found
No related merge requests found
......@@ -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
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
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);
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
......@@ -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>
......
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
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
*
......
......@@ -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)
{
......
......@@ -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"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment