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

AttributeRelation get attribute type

parent ef888154
No related branches found
No related tags found
No related merge requests found
Showing with 224 additions and 212 deletions
......@@ -266,6 +266,10 @@
<name>PROTECTED</name>
<state>READONLY</state>
</entityField>
<entityField>
<name>ATTRIBUTE_TYPE</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/attribute_type/valueProcess.js</valueProcess>
</entityField>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
......@@ -297,6 +301,9 @@
<jDitoRecordFieldMapping>
<name>PROTECTED.value</name>
</jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>ATTRIBUTE_TYPE.value</name>
</jDitoRecordFieldMapping>
</recordFieldMappings>
</jDitoRecordContainer>
</recordContainers>
......
import("Attribute_lib");
import("system.vars");
import("system.result");
result.string(AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID")));
\ No newline at end of file
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID"));
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = vars.get("$field.ATTRIBUTE_TYPE");
result.string(AttributeTypeUtil.getContentType(attributeType));
\ No newline at end of file
......@@ -7,7 +7,7 @@ import("Keyword_lib");
import("system.tools");
import("Sql_lib");
var attrType = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID"));
var attrType = vars.get("$field.ATTRIBUTE_TYPE");
var dropDownDef = db.cell(
SqlCondition.begin()
.andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.AB_ATTRIBUTE_ID")
......
......@@ -7,7 +7,7 @@ import("Attribute_lib");
import("Sql_lib");
var attributeId = vars.get("$field.AB_ATTRIBUTE_ID");
var attrType = AttributeUtil.getAttributeType(attributeId);
var attrType = vars.get("$field.ATTRIBUTE_TYPE");
var res = AttributeUtil.getPossibleListValues(attributeId, attrType);
result.object(res);
\ No newline at end of file
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID"));
var contentType = AttributeTypeUtil.getContentType(attributeType);
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = vars.get("$field.ATTRIBUTE_TYPE");
var contentType = AttributeTypeUtil.getContentType(attributeType);
result.string(contentType != null && contentType != "BOOLEAN");
\ No newline at end of file
import("system.neon");
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID"));
result.string(AttributeTypeUtil.getContentType(attributeType));
var fieldState;
if (AttributeTypeUtil.getContentType(attributeType) != null)
fieldState = neon.COMPONENTSTATE_EDITABLE;
else
fieldState = neon.COMPONENTSTATE_READONLY;
import("system.neon");
import("system.vars");
import("system.result");
import("Attribute_lib");
var attributeType = vars.get("$field.ATTRIBUTE_TYPE");
result.string(AttributeTypeUtil.getContentType(attributeType));
var fieldState;
if (AttributeTypeUtil.getContentType(attributeType) != null)
fieldState = neon.COMPONENTSTATE_EDITABLE;
else
fieldState = neon.COMPONENTSTATE_READONLY;
result.string(fieldState);
\ No newline at end of file
......@@ -3,7 +3,7 @@ import("system.vars");
import("system.result");
var attributeType = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID"));
var attributeType = vars.get("$field.ATTRIBUTE_TYPE");
var contentType = AttributeTypeUtil.getContentType(attributeType);
if (!vars.get("$this.value") && contentType == "BOOLEAN")
result.string("0");
\ No newline at end of file
import("system.translate");
import("system.util");
import("Util_lib");
import("system.vars");
import("system.result");
import("system.db");
import("Attribute_lib");
import("Sql_lib");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var rowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param");
//getTree: if true, the attribute groups are loaded as parents
var getTree = vars.exists("$param.GetTree_param") && vars.getString("$param.GetTree_param") == "true";
//showEmpty: if true, all selectable attributes are loaded as records, even if they don't have a attributeRelation
var showEmpty = vars.exists("$param.ShowEmpty_param") && vars.getString("$param.ShowEmpty_param") == "true";
var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param");
var sqlCondition = new SqlCondition(); //where-condition (condition for the Attribute)
var joinCondition = new SqlCondition(); //condition for the joined values (for AttributeRelation)
//=> these are two distinct conditions because if showEmpty is true, a left join is used for the relations
var possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
{
let idVals = vars.get("$local.idvalues");
let attrId = idVals.length === 1 && idVals[0].split(",")[1];
if (!attrId)
showEmpty = false;
if (showEmpty)
sqlCondition.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId);
else
{
sqlCondition.andIn("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idVals);
rowId = null;
}
getTree = false;
}
else if (showEmpty || rowId)
{
if (showEmpty)
{
let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param");
sqlCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes);
}
if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"))
{
let filteredIds = JSON.parse(vars.getString("$param.FilteredAttributeIds_param"));
let filteredCondition = new SqlCondition();
let filteredIdChildren = AttributeUtil.getAllChildren(filteredIds);
filteredCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredIdChildren);
filteredCondition.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
// return nothing if filteredAttributeIds is an empty array. (--> and 1=2)
sqlCondition.andSqlCondition(filteredCondition, "1=2");
}
}
if (rowId)
{
joinCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId);
if (objectType != null)
joinCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
// add condition to match all returned by joins (override default 1=2 of build)
sqlCondition.and("1=1");
}
joinCondition.and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID");
var defaultFields = [
"AB_ATTRIBUTERELATIONID",
"AB_ATTRIBUTE.AB_ATTRIBUTEID",
"AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID",
"AB_ATTRIBUTE.ATTRIBUTE_TYPE",
"AB_ATTRIBUTE.ATTRIBUTE_NAME",
"AB_ATTRIBUTE.DROPDOWNDEFINITION",
"COMBOVAL.ATTRIBUTE_NAME"
];
//these fields hold the attributeRelation value, depending on the attribute type
var valueFields = AttributeTypeUtil.getAllDatabaseFields();
var attributeSql = SqlBuilder.begin()
.select(defaultFields.concat(valueFields))
.from("AB_ATTRIBUTE")
.where(sqlCondition);
if (showEmpty)
attributeSql.leftJoin("AB_ATTRIBUTERELATION", joinCondition.build("1=2"));
else
attributeSql.join("AB_ATTRIBUTERELATION", joinCondition.build("1=2"));
attributeSql.leftJoin("AB_ATTRIBUTE", "COMBOVAL.AB_ATTRIBUTEID = " + $AttributeTypes.COMBO.databaseField, "COMBOVAL");
var countCheck = {};
if (getTree)
{
let minUsages = db.table(SqlCondition.begin()
.andIn("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes)
.andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", objectType)
.buildSql("select AB_ATTRIBUTE_ID, MIN_COUNT from AB_ATTRIBUTEUSAGE", "1=2")
);
minUsages.forEach(function (usage)
{
this[usage[0]] = {
count : 0,
min : usage[1]
};
}, countCheck);
}
var attributeValues = db.table(attributeSql.build()).map(function (row)
{
var attributeId = row[1];
var attributeName = translate.text(row[4]);
var type = row[3].trim();
if (!getTree && !displaySimpleName && row[2])
{
let parentName = AttributeUtil.getFullAttributeName(row[2]);
attributeName = (parentName ? parentName + " / " : "") + attributeName;
}
var value = row[AttributeTypeUtil.getTypeColumnIndex(row[3]) + defaultFields.length];
var viewValue;
if (type == $AttributeTypes.COMBO)
viewValue = translate.text(row[6]);
else
viewValue = AttributeTypeUtil.getAttributeViewValue(type, value, row[5]);
if (attributeId in countCheck)
countCheck[attributeId].count++;
//TODO: what should be the uid if showEmpty is true?
// V-- set "," to mark this as new generated UUID
return [row[0] || util.getNewUUID() + "," + attributeId, row[2], value, viewValue, attributeId, attributeName, ""];
});
for (let i = 0; i < attributeValues.length; i++)
{
let attrId = attributeValues[i][4];
if (attrId in countCheck && countCheck[attrId].min >= countCheck[attrId].count)
attributeValues[i][6] = "true";
}
var parentAttributes = [];
var attributeObj = {}; //object of attribute ids to avoid duplicates
if (getTree)
_fetchAttributes(attributeValues.map(function (row) {return row[1]}));
allAttributes = TreeUtils.sortArrayForTree(parentAttributes, 0, 1).concat(attributeValues);
result.object(allAttributes);
/*
* recursive function that loads all superordinate attributes for the tree
*/
function _fetchAttributes (pAttributeIds)
{
var sqlCondition = SqlCondition.begin();
var nextIds = [];
pAttributeIds.forEach(function (id)
{
if (!(id in this))
sqlCondition.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
}, attributeObj);
db.table(sqlCondition.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2"))
.forEach(function (row)
{
this[row[0]] = true; //make entry in attributeObj to avoid duplicates
if (row[1])
nextIds.push(row[1]);
else
row[1] = null;
row[2] = translate.text(row[2]); //translate attribute name
parentAttributes.push([row[0], row[1], "", "", "", row[2], "true"]);
}, attributeObj);
if (nextIds.length)
_fetchAttributes(nextIds);
import("system.translate");
import("system.util");
import("Util_lib");
import("system.vars");
import("system.result");
import("system.db");
import("Attribute_lib");
import("Sql_lib");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var rowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param");
//getTree: if true, the attribute groups are loaded as parents
var getTree = vars.exists("$param.GetTree_param") && vars.getString("$param.GetTree_param") == "true";
//showEmpty: if true, all selectable attributes are loaded as records, even if they don't have a attributeRelation
var showEmpty = vars.exists("$param.ShowEmpty_param") && vars.getString("$param.ShowEmpty_param") == "true";
var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param");
var sqlCondition = new SqlCondition(); //where-condition (condition for the Attribute)
var joinCondition = new SqlCondition(); //condition for the joined values (for AttributeRelation)
//=> these are two distinct conditions because if showEmpty is true, a left join is used for the relations
var possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
{
let idVals = vars.get("$local.idvalues");
let attrId = idVals.length === 1 && idVals[0].split(",")[1];
if (!attrId)
showEmpty = false;
if (showEmpty)
sqlCondition.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId);
else
{
sqlCondition.andIn("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idVals);
rowId = null;
}
getTree = false;
}
else if (showEmpty || rowId)
{
if (showEmpty)
{
let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param");
sqlCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes);
}
if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"))
{
let filteredIds = JSON.parse(vars.getString("$param.FilteredAttributeIds_param"));
let filteredCondition = new SqlCondition();
let filteredIdChildren = AttributeUtil.getAllChildren(filteredIds);
filteredCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredIdChildren);
filteredCondition.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
// return nothing if filteredAttributeIds is an empty array. (--> and 1=2)
sqlCondition.andSqlCondition(filteredCondition, "1=2");
}
}
if (rowId)
{
joinCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId);
if (objectType != null)
joinCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
// add condition to match all returned by joins (override default 1=2 of build)
sqlCondition.and("1=1");
}
joinCondition.and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID");
var defaultFields = [
"AB_ATTRIBUTERELATIONID",
"AB_ATTRIBUTE.AB_ATTRIBUTEID",
"AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID",
"AB_ATTRIBUTE.ATTRIBUTE_TYPE",
"AB_ATTRIBUTE.ATTRIBUTE_NAME",
"AB_ATTRIBUTE.DROPDOWNDEFINITION",
"COMBOVAL.ATTRIBUTE_NAME"
];
//these fields hold the attributeRelation value, depending on the attribute type
var valueFields = AttributeTypeUtil.getAllDatabaseFields();
var attributeSql = SqlBuilder.begin()
.select(defaultFields.concat(valueFields))
.from("AB_ATTRIBUTE")
.where(sqlCondition);
if (showEmpty)
attributeSql.leftJoin("AB_ATTRIBUTERELATION", joinCondition.build("1=2"));
else
attributeSql.join("AB_ATTRIBUTERELATION", joinCondition.build("1=2"));
attributeSql.leftJoin("AB_ATTRIBUTE", "COMBOVAL.AB_ATTRIBUTEID = " + $AttributeTypes.COMBO.databaseField, "COMBOVAL");
var countCheck = {};
if (getTree)
{
let minUsages = db.table(SqlCondition.begin()
.andIn("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes)
.andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", objectType)
.buildSql("select AB_ATTRIBUTE_ID, MIN_COUNT from AB_ATTRIBUTEUSAGE", "1=2")
);
minUsages.forEach(function (usage)
{
this[usage[0]] = {
count : 0,
min : usage[1]
};
}, countCheck);
}
var attributeValues = db.table(attributeSql.build()).map(function (row)
{
var attributeId = row[1];
var attributeName = translate.text(row[4]);
var type = row[3].trim();
if (!getTree && !displaySimpleName && row[2])
{
let parentName = AttributeUtil.getFullAttributeName(row[2]);
attributeName = (parentName ? parentName + " / " : "") + attributeName;
}
var value = row[AttributeTypeUtil.getTypeColumnIndex(row[3]) + defaultFields.length];
var viewValue;
if (type == $AttributeTypes.COMBO)
viewValue = translate.text(row[6]);
else
viewValue = AttributeTypeUtil.getAttributeViewValue(type, value, row[5]);
if (attributeId in countCheck)
countCheck[attributeId].count++;
//TODO: what should be the uid if showEmpty is true?
// V-- set "," to mark this as new generated UUID
return [row[0] || util.getNewUUID() + "," + attributeId, row[2], value, viewValue, attributeId, attributeName, "", row[3].trim()];
});
for (let i = 0; i < attributeValues.length; i++)
{
let attrId = attributeValues[i][4];
if (attrId in countCheck && countCheck[attrId].min >= countCheck[attrId].count)
attributeValues[i][6] = "true";
}
var parentAttributes = [];
var attributeObj = {}; //object of attribute ids to avoid duplicates
if (getTree)
_fetchAttributes(attributeValues.map(function (row) {return row[1]}));
allAttributes = TreeUtils.sortArrayForTree(parentAttributes, 0, 1).concat(attributeValues);
result.object(allAttributes);
/*
* recursive function that loads all superordinate attributes for the tree
*/
function _fetchAttributes (pAttributeIds)
{
var sqlCondition = SqlCondition.begin();
var nextIds = [];
pAttributeIds.forEach(function (id)
{
if (!(id in this))
sqlCondition.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
}, attributeObj);
db.table(sqlCondition.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2"))
.forEach(function (row)
{
this[row[0]] = true; //make entry in attributeObj to avoid duplicates
if (row[1])
nextIds.push(row[1]);
else
row[1] = null;
row[2] = translate.text(row[2]); //translate attribute name
parentAttributes.push([row[0], row[1], "", "", "", row[2], "true"]);
}, attributeObj);
if (nextIds.length)
_fetchAttributes(nextIds);
}
\ No newline at end of file
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