Skip to content
Snippets Groups Projects
Commit cb393b85 authored by S.Listl's avatar S.Listl
Browse files

AttributeRelation max_count

parent 701e0112
No related branches found
No related tags found
No related merge requests found
......@@ -112,6 +112,10 @@
<valueProcess>%aditoprj%/entity/AttributeRelationTree_entity/entityfields/specificattribute/children/objecttype_param/valueProcess.js</valueProcess>
<triggerRecalculation v="true" />
</entityParameter>
<entityParameter>
<name>AttributeCount_param</name>
<valueProcess>%aditoprj%/entity/AttributeRelationTree_entity/entityfields/specificattribute/children/attributecount_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityActionGroup>
......
import("system.result");
import("system.db");
import("Sql_lib");
import("system.vars");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var rowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param");
if (rowId)
{
var condition = SqlCondition.begin()
.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId);
if (objectType)
condition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
var relationCounts = db.table(condition.buildSql(
"select AB_ATTRIBUTE_ID, count(AB_ATTRIBUTE_ID) from AB_ATTRIBUTERELATION",
"1=2",
"group by AB_ATTRIBUTE_ID"
));
var countObj = {};
relationCounts.forEach(function (row)
{
this[row[0]] = row[1];
}, countObj);
result.object(countObj);
}
\ No newline at end of file
......@@ -95,6 +95,10 @@
<name>AttrParentId_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>AttributeCount_param</name>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
<entityParameter>
......@@ -270,6 +274,10 @@
<name>AttrParentId_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>AttributeCount_param</name>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
<entityConsumer>
......@@ -301,6 +309,11 @@
<title>Sorting</title>
<searchable v="false" />
</entityField>
<entityParameter>
<name>AttributeCount_param</name>
<expose v="true" />
<description>PARAMETER</description>
</entityParameter>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
......
......@@ -43,8 +43,10 @@ else if (objectType) //if there's an objectType, it comes from the AttributeRel
var filteredAttributes = [];
if (vars.exists("$param.FilteredAttributeIds_param") && vars.get("$param.FilteredAttributeIds_param"))
filteredAttributes = JSON.parse(vars.get("$param.FilteredAttributeIds_param"));
var ids = AttributeUtil.getPossibleAttributes(objectType, false, filteredAttributes);
var attributeCount;
if (vars.exists("$param.AttributeCount_param") && vars.get("$param.AttributeCount_param"))
attributeCount = JSON.parse(vars.get("$param.AttributeCount_param"));
var ids = AttributeUtil.getPossibleAttributes(objectType, false, filteredAttributes, attributeCount);
condition.and("A.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
}
else
......
......@@ -23,10 +23,11 @@ function AttributeUtil () {}
* @param {String} pObjectType the object type (= context)
* @param {boolean} [pIncludeGroups=false]
* @param {String[]} [pFilteredAttributeIds=[]] Whitleist of attribute ids
* @param {Object} [pAttributeCount=null] Object with attribute ids and their count
*
* @return {String[]} array of attributeIds
*/
AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFilteredAttributeIds)
AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFilteredAttributeIds, pAttributeCount)
{
if (pObjectType == null)
return [];
......@@ -37,6 +38,18 @@ AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFi
.andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# <> ?")
.and("ATTRIBUTE_ACTIVE = 1");
if (pAttributeCount)
{
for (let attributeId in pAttributeCount)
{
attrCond.andSqlCondition(
SqlCondition.begin()
.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attributeId, "# != ?")
.orPrepare("AB_ATTRIBUTEUSAGE.MAX_COUNT", pAttributeCount[attributeId], "# > ?")
);
}
}
if (pFilteredAttributeIds != undefined && pFilteredAttributeIds.length > 0)
{
......
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