Skip to content
Snippets Groups Projects
Commit 5c48cda2 authored by S.Listl's avatar S.Listl Committed by Sebastian Listl
Browse files

AttributeRelation refactored to make sure uids don't change

(cherry picked from commit cb3fa119)
parent 5e5b7941
No related branches found
No related tags found
No related merge requests found
Showing
with 278 additions and 241 deletions
...@@ -22,11 +22,13 @@ ...@@ -22,11 +22,13 @@
<entityParameter> <entityParameter>
<name>ObjectType_param</name> <name>ObjectType_param</name>
<expose v="true" /> <expose v="true" />
<mandatory v="true" />
<description>PARAMETER</description> <description>PARAMETER</description>
</entityParameter> </entityParameter>
<entityParameter> <entityParameter>
<name>ObjectRowId_param</name> <name>ObjectRowId_param</name>
<expose v="true" /> <expose v="true" />
<mandatory v="true" />
<description>PARAMETER</description> <description>PARAMETER</description>
</entityParameter> </entityParameter>
<entityProvider> <entityProvider>
...@@ -156,6 +158,7 @@ ...@@ -156,6 +158,7 @@
</entityConsumer> </entityConsumer>
<entityParameter> <entityParameter>
<name>GetTree_param</name> <name>GetTree_param</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/gettree_param/valueProcess.js</valueProcess>
<expose v="true" /> <expose v="true" />
<description>PARAMETER</description> <description>PARAMETER</description>
</entityParameter> </entityParameter>
...@@ -261,6 +264,7 @@ ...@@ -261,6 +264,7 @@
</entityField> </entityField>
<entityParameter> <entityParameter>
<name>DisplaySimpleName_param</name> <name>DisplaySimpleName_param</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/displaysimplename_param/valueProcess.js</valueProcess>
<expose v="true" /> <expose v="true" />
<description>PARAMETER</description> <description>PARAMETER</description>
</entityParameter> </entityParameter>
...@@ -271,6 +275,7 @@ ...@@ -271,6 +275,7 @@
</entityParameter> </entityParameter>
<entityParameter> <entityParameter>
<name>ShowEmpty_param</name> <name>ShowEmpty_param</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/showempty_param/valueProcess.js</valueProcess>
<expose v="true" /> <expose v="true" />
<documentation>%aditoprj%/entity/AttributeRelation_entity/entityfields/showempty_param/documentation.adoc</documentation> <documentation>%aditoprj%/entity/AttributeRelation_entity/entityfields/showempty_param/documentation.adoc</documentation>
</entityParameter> </entityParameter>
...@@ -293,6 +298,7 @@ ...@@ -293,6 +298,7 @@
</entityParameter> </entityParameter>
<entityParameter> <entityParameter>
<name>GetTheme_param</name> <name>GetTheme_param</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/gettheme_param/valueProcess.js</valueProcess>
<expose v="true" /> <expose v="true" />
</entityParameter> </entityParameter>
<entityField> <entityField>
...@@ -333,6 +339,10 @@ ...@@ -333,6 +339,10 @@
<entityProvider> <entityProvider>
<name>ThemeProvider</name> <name>ThemeProvider</name>
</entityProvider> </entityProvider>
<entityField>
<name>AB_ATTRIBUTERELATIONID</name>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attributerelationid/valueProcess.js</valueProcess>
</entityField>
</entityFields> </entityFields>
<recordContainers> <recordContainers>
<jDitoRecordContainer> <jDitoRecordContainer>
...@@ -346,6 +356,9 @@ ...@@ -346,6 +356,9 @@
<jDitoRecordFieldMapping> <jDitoRecordFieldMapping>
<name>UID.value</name> <name>UID.value</name>
</jDitoRecordFieldMapping> </jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>AB_ATTRIBUTERELATIONID.value</name>
</jDitoRecordFieldMapping>
<jDitoRecordFieldMapping> <jDitoRecordFieldMapping>
<name>PARENT_ID.value</name> <name>PARENT_ID.value</name>
</jDitoRecordFieldMapping> </jDitoRecordFieldMapping>
......
import("system.util");
import("system.neon");
import("system.vars");
import("system.result");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null)
result.string(util.getNewUUID());
\ No newline at end of file
import("system.result");
result.string(false);
\ No newline at end of file
import("system.result");
result.string(false);
\ No newline at end of file
import("system.result");
result.string(false);
\ No newline at end of file
import("system.result");
result.string(false);
\ No newline at end of file
...@@ -3,5 +3,10 @@ import("system.result"); ...@@ -3,5 +3,10 @@ import("system.result");
import("system.neon"); import("system.neon");
import("system.util"); import("system.util");
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null) if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
result.string("," + util.getNewUUID()); // set "," to mark this as new generated UUID {
\ No newline at end of file if (vars.getString("$param.ShowEmpty_param") == "true")
result.string(JSON.stringify([vars.get("$field.AB_ATTRIBUTERELATIONID"), vars.get("$field.AB_ATTRIBUTE_ID")]));
else
result.string(vars.get("$field.AB_ATTRIBUTERELATIONID"));
}
\ No newline at end of file
...@@ -7,251 +7,256 @@ import("system.db"); ...@@ -7,251 +7,256 @@ import("system.db");
import("Attribute_lib"); import("Attribute_lib");
import("Sql_lib"); import("Sql_lib");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"); var idvalues = vars.exists("$local.idvalues") ? vars.get("$local.idvalues") : null;
var objectRowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param"); var getTree = !idvalues && vars.getString("$param.GetTree_param") == "true";
var loadFullAttributeName = vars.getString("$param.DisplaySimpleName_param") != "true";
var idvalues = vars.exists("$local.idvalues") && vars.get("$local.idvalues"); var typeWhitelist, typeBlacklist;
if (vars.getString("$param.GetTheme_param") == "true")
var getTree = vars.exists("$param.GetTree_param") && vars.getString("$param.GetTree_param") == "true"; typeWhitelist = [$AttributeTypes.THEME.toString()];
var getTheme = vars.exists("$param.IsTheme_param") && vars.getString("$param.IsTheme_param") == "true"; else
var showEmpty = vars.exists("$param.ShowEmpty_param") && vars.getString("$param.ShowEmpty_param") == "true"; typeBlacklist = [$AttributeTypes.THEME.toString()];
var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.getString("$param.DisplaySimpleName_param") == "true";
var loadEmptyAttributes = vars.getString("$param.ShowEmpty_param") == "true";
var defaultFields = [ var filteredAttributeIds = vars.exists("$param.FilteredAttributeIds_param") && vars.get("$param.FilteredAttributeIds_param");
"AB_ATTRIBUTERELATIONID", if (filteredAttributeIds)
"AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredAttributeIds = JSON.parse(filteredAttributeIds);
"AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", var objectRowId = vars.get("$param.ObjectRowId_param");
"AB_ATTRIBUTE.ATTRIBUTE_TYPE", var objectType = vars.get("$param.ObjectType_param");
"AB_ATTRIBUTE.ATTRIBUTE_NAME",
"AB_ATTRIBUTE.DROPDOWNDEFINITION",
"COMBOVAL.ATTRIBUTE_NAME",
"AB_ATTRIBUTERELATION.DATE_NEW",
"AB_ATTRIBUTERELATION.USER_NEW",
"AB_ATTRIBUTERELATION.DATE_EDIT",
"AB_ATTRIBUTERELATION.USER_EDIT",
"AB_ATTRIBUTE.DROPDOWNFILTER"
];
//these fields hold the attributeRelation value, depending on the attribute type
var valueFields = AttributeTypeUtil.getAllDatabaseFields();
var attributeSql = newSelect(defaultFields.concat(valueFields))
.from("AB_ATTRIBUTE")
.orderBy("AB_ATTRIBUTE.SORTING asc")
.where(); // go into where mode
var possibleAttributes;
if (idvalues) var attributeQueryMaker = {
{ defaultQueryFields : [
let attrId = idvalues.length === 1 && idvalues[0].split(",")[1]; "AB_ATTRIBUTERELATIONID",
if (!attrId) "AB_ATTRIBUTE.AB_ATTRIBUTEID",
showEmpty = false; "AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID",
"AB_ATTRIBUTE.ATTRIBUTE_TYPE",
"AB_ATTRIBUTE.ATTRIBUTE_NAME",
"AB_ATTRIBUTE.DROPDOWNDEFINITION",
"COMBOVAL.ATTRIBUTE_NAME",
"AB_ATTRIBUTERELATION.DATE_NEW",
"AB_ATTRIBUTERELATION.USER_NEW",
"AB_ATTRIBUTERELATION.DATE_EDIT",
"AB_ATTRIBUTERELATION.USER_EDIT",
"AB_ATTRIBUTE.DROPDOWNFILTER"
],
valueQueryFields : AttributeTypeUtil.getAllDatabaseFields(),
if (showEmpty) getConditionForIdValues : function (pIdValues, pLoadEmptyAttributes)
attributeSql.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId);
else
{ {
attributeSql.andIfSet("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idvalues.map(function(pId) var idCondition = newWhere();
if (pLoadEmptyAttributes)
{ {
return pId[0] == "," ? pId.split(",")[1] : pId; pIdValues.forEach(function (id)
}), SqlBuilder.IN()); {
objectRowId = null; var [attributeRelationId, attributeId] = JSON.parse(id);
} idCondition.or("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", attributeRelationId);
getTree = false; idCondition.or(newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID is null")
} .and("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId));
else if (showEmpty || objectRowId) });
{ }
if (getTheme) else
attributeSql.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME); idCondition.andIfSet("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", pIdValues, SqlBuilder.IN());
else
attributeSql.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME, SqlBuilder.NOT_EQUAL());
if (showEmpty)
{
possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param");
attributeSql.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes, SqlBuilder.IN()); return idCondition;
} },
if (vars.get("$param.FilteredAttributeIds_param")) getConditionForLinkedObject : function (pObjectType, pLoadEmptyAttributes, pAttributeIds, pTypeBlacklist, pTypeWhitelist)
{ {
let filteredIds = JSON.parse(vars.getString("$param.FilteredAttributeIds_param")); var attributeCondition = newWhereIfSet("AB_ATTRIBUTE.ATTRIBUTE_TYPE", pTypeBlacklist, SqlBuilder.NOT_IN());
attributeCondition.andIfSet("AB_ATTRIBUTE.ATTRIBUTE_TYPE", pTypeWhitelist, SqlBuilder.IN());
let filteredIdChildren = AttributeUtil.getAllChildren(filteredIds); if (pLoadEmptyAttributes)
attributeCondition.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", AttributeUtil.getPossibleAttributes(pObjectType), SqlBuilder.IN());
let filteredCondition = newWhere(); if (pAttributeIds)
{
let attributeChildren = AttributeUtil.getAllChildren(pAttributeIds);
let attributeIdCondition = newWhere();
if (attributeChildren.length > 0)
{
attributeIdCondition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeChildren, SqlBuilder.IN())
attributeIdCondition.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, SqlBuilder.NOT_EQUAL());
}
// return nothing if filteredAttributeIds is an empty array. (--> and 1=2)
if (!attributeIdCondition.hasCondition())
return null;
attributeCondition.and(attributeIdCondition);
}
return attributeCondition;
},
getAttributeQuery : function (pIdValues, pObjectRowId, pObjectType, pLoadEmptyAttributes, pAttributeIds, pTypeBlacklist, pTypeWhitelist)
{
var attributeQuery = newSelect(this.defaultQueryFields.concat(this.valueQueryFields))
.from("AB_ATTRIBUTE")
.orderBy("AB_ATTRIBUTE.SORTING asc");
if (filteredIdChildren.length > 0) if (pIdValues)
attributeQuery.where(this.getConditionForIdValues(pIdValues, pLoadEmptyAttributes));
else if (pObjectRowId)
{ {
filteredCondition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredIdChildren, SqlBuilder.IN()) let condition = this.getConditionForLinkedObject(pObjectType, pLoadEmptyAttributes, pAttributeIds, pTypeBlacklist, pTypeWhitelist);
.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, SqlBuilder.NOT_EQUAL()); if (condition === null)
return null;
attributeQuery.where(condition);
} }
// return nothing if filteredAttributeIds is an empty array. (--> and 1=2) var attributeRelationCond = newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"); //condition for the joined values (for AttributeRelation)
if (filteredCondition.hasCondition())
attributeSql.and(filteredCondition);
else
attributeSql.and("1=2");
}
}
var attributeRelationCond = newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"); //condition for the joined values (for AttributeRelation) if (!pIdValues && pObjectRowId)
{
if (objectRowId) attributeRelationCond.and("AB_ATTRIBUTERELATION.OBJECT_ROWID", pObjectRowId);
{ attributeRelationCond.andIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType);
attributeRelationCond.and("AB_ATTRIBUTERELATION.OBJECT_ROWID", objectRowId); }
if (objectType)
attributeRelationCond.and("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
}
if (pLoadEmptyAttributes)
attributeQuery.leftJoin("AB_ATTRIBUTERELATION", attributeRelationCond);
else
attributeQuery.join("AB_ATTRIBUTERELATION", attributeRelationCond);
attributeQuery.leftJoin("AB_ATTRIBUTE", "COMBOVAL.AB_ATTRIBUTEID = " + $AttributeTypes.COMBO.databaseField, "COMBOVAL");
if (showEmpty)
attributeSql.leftJoin("AB_ATTRIBUTERELATION", attributeRelationCond); return attributeQuery;
else }
attributeSql.join("AB_ATTRIBUTERELATION", attributeRelationCond); }
attributeSql.leftJoin("AB_ATTRIBUTE", "COMBOVAL.AB_ATTRIBUTEID = " + $AttributeTypes.COMBO.databaseField, "COMBOVAL") var attributeQuery = attributeQueryMaker.getAttributeQuery(idvalues, objectRowId, objectType, loadEmptyAttributes, filteredAttributeIds, typeBlacklist, typeWhitelist);
var attributeRelations = attributeQuery != null ? attributeQuery.table(false) : [];
//Builds an object containing the minimal counts of the attributes, this is required for //Builds an object containing the minimal counts of the attributes, this is required for
//checking if an attribute is used not often enough or just often enough. When this is the case, //checking if an attribute is used not often enough or just often enough. When this is the case,
//deletion of this attributeRelation will be prohibited. //deletion of this attributeRelation will be prohibited.
var minCountInsurance = {}; var minCountInsurance = {
if (getTree) minCounts : {},
{ usageCounts : {},
if (!possibleAttributes)
possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
let minUsages = newSelect("AB_ATTRIBUTE_ID, MIN_COUNT") loadMinCounts : function (pObjectType)
.from("AB_ATTRIBUTEUSAGE")
.whereIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes, SqlBuilder.IN())
.and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", objectType)
.table(true);
minUsages.forEach(function (usage)
{ {
this[usage[0]] = {
count : 0, var minUsages = newSelect("AB_ATTRIBUTE_ID, MIN_COUNT")
min : usage[1] .from("AB_ATTRIBUTEUSAGE")
}; .whereIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", Object.keys(this.usageCounts), SqlBuilder.IN())
}, minCountInsurance); .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
} .table(true);
var attrRelations = attributeSql.table(true).map( minUsages.forEach(function ([attributeId, minCount])
function (row)
{
var [attrRelId, attrId, attrParentId, attrType, attrName, dropDownDef, comboViewVal, dateNew, userNew, dateEdit, userEdit, dropDownFilter] = row;
attrName = translate.text(attrName);
attrType = attrType.trim();
if (!getTree && !displaySimpleName && attrParentId)
{ {
let parentName = AttributeUtil.getFullAttributeName(attrParentId); this.minCounts[attributeId] = minCount;
attrName = (parentName ? parentName + " / " : "") + attrName; }, this);
} },
var value = row[AttributeTypeUtil.getTypeColumnIndex(attrType) + defaultFields.length]; incrUsageCount : function (pAttributeId)
var viewValue; {
if (attrType == $AttributeTypes.COMBO) if (pAttributeId in this.usageCounts)
viewValue = translate.text(comboViewVal); this.usageCounts[pAttributeId]++;
else else
viewValue = AttributeTypeUtil.getAttributeViewValue(attrType, value, dropDownDef); this.usageCounts[pAttributeId] = 1;
},
attributeNotDeletable : function (pAttributeId)
{
return this.minCounts[pAttributeId] >= this.usageCounts[pAttributeId];
}
};
if (attrId in minCountInsurance) attributeRelations = attributeRelations.map(function (row)
minCountInsurance[attrId].count++; {
var [attrRelId, attrId, attrParentId, attrType, attrName, dropDownDef, comboViewVal, dateNew, userNew, dateEdit, userEdit, dropDownFilter] = row;
//TODO: what should be the uid if showEmpty is true? attrName = translate.text(attrName);
// V-- set "," to mark this as new generated UUID attrType = attrType.trim();
return [ if (!getTree && loadFullAttributeName && attrParentId)
attrRelId || util.getNewUUID() + "," + attrId, {
attrParentId, let parentName = AttributeUtil.getFullAttributeName(attrParentId);
value, attrName = (parentName ? parentName + " / " : "") + attrName;
viewValue,
attrId,
attrName,
"",
attrType.trim(),
dateNew,
userNew,
dateEdit,
userEdit,
value,
viewValue,
dropDownDef,
dropDownFilter
];
} }
); var value = row[AttributeTypeUtil.getTypeColumnIndex(attrType) + attributeQueryMaker.defaultQueryFields.length];
var viewValue;
if (attrType == $AttributeTypes.COMBO)
viewValue = translate.text(comboViewVal);
else
viewValue = AttributeTypeUtil.getAttributeViewValue(attrType, value, dropDownDef);
_protectMinCountAttributes(attrRelations, minCountInsurance); minCountInsurance.incrUsageCount(attrId);
//if loadEmptyAttributes is true, the id is contains the attributeRelation id and the attribute id.
//in case there is no attributeRelation, a random id is used
return [
loadEmptyAttributes ? JSON.stringify([attrRelId || util.getNewUUID(), attrId]) : attrRelId,
attrRelId,
attrParentId,
value,
viewValue,
attrId,
attrName,
"", //protected
attrType.trim(),
dateNew,
userNew,
dateEdit,
userEdit,
value,
viewValue,
dropDownDef,
dropDownFilter
];
});
minCountInsurance.loadMinCounts(objectType);
attributeRelations.forEach(function (attributeRelation)
{
var attrId = attributeRelation[4];
if (minCountInsurance.attributeNotDeletable(attrId))
attributeRelation[7] = "true";
});
//object of attribute ids to avoid duplicates (more than one attribute can have the same parent)
var attrCatalog = {};
if (getTree) if (getTree)
attrRelations = _buildAttributeTree(attrRelations); attributeRelations = _buildAttributeTree(attributeRelations);
result.object(attrRelations); result.object(attributeRelations);
/* /*
* loads the parents for a tree * loads the parents for a tree
*/ */
function _buildAttributeTree (pAttrRelations) function _buildAttributeTree (pAttrRelations)
{ {
var parentAttributes = []; //object of attribute ids to avoid duplicates (more than one attribute can have the same parent)
_fetchParentAttributes(pAttrRelations.map(function (row) {return row[1]}), parentAttributes); var attrCatalog = {};
return TreeUtils.sortArrayForTree(parentAttributes, 0, 1).concat(pAttrRelations);
}
/* var parentAttributes = [];
* recursive function that loads all superordinate attributes for the tree _fetchParentAttributes(pAttrRelations.map(function (row) {return row[2]}), parentAttributes);
*/ return TreeUtils.sortArrayForTree(parentAttributes, 0, 2).concat(pAttrRelations);
function _fetchParentAttributes (pAttributeIds, pParentAttributes)
{
var attributeCond = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME")
.from("AB_ATTRIBUTE")
.where()
var nextIds = [];
pAttributeIds.forEach(function (id)
{
if (!(id in this))
attributeCond.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
}, attrCatalog);
attributeCond.table(true) /*
.forEach(function ([attrId, parentId, attrName]) * recursive function that loads all superordinate attributes for the tree
{ */
this[attrId] = true; //make entry in attrCatalog to avoid duplicates function _fetchParentAttributes (pAttributeIds, pParentAttributes)
if (parentId)
nextIds.push(parentId);
pParentAttributes.push([
attrId,
parentId,
"",
"",
"",
translate.text(attrName), //translate attribute name
"true",
"",
"",
"",
"",
"",
"",
"",
"",
"",
]);
}, attrCatalog);
if (nextIds.length)
_fetchParentAttributes(nextIds, pParentAttributes);
}
function _protectMinCountAttributes (pAttrRelations, pMinCountInsurance)
{
for (let i = 0; i < pAttrRelations.length; i++)
{ {
let attrId = pAttrRelations[i][4]; var attributeCond = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME")
if (attrId in pMinCountInsurance && pMinCountInsurance[attrId].min >= pMinCountInsurance[attrId].count) .from("AB_ATTRIBUTE")
pAttrRelations[i][6] = "true"; .where()
var nextIds = [];
pAttributeIds.forEach(function (id)
{
if (!(id in this))
attributeCond.orIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
}, attrCatalog);
attributeCond.table(true)
.forEach(function ([attrId, parentId, attrName])
{
this[attrId] = true; //make entry in attrCatalog to avoid duplicates
if (parentId)
nextIds.push(parentId);
pParentAttributes.push([
attrId, "", parentId, "", "", "", //0-5
translate.text(attrName), //translate attribute name
"true", //7
"", "", "", "", "", "", "", "", "" //8-16
]);
}, attrCatalog);
if (nextIds.length)
_fetchParentAttributes(nextIds, pParentAttributes);
} }
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ var columns = [ ...@@ -17,7 +17,7 @@ var columns = [
var rowdata = vars.get("$local.rowdata"); var rowdata = vars.get("$local.rowdata");
var uid = rowdata["UID.value"]; var uid = rowdata["UID.value"];
var values = [ var values = [
uid[0] == "," ? uid.substr(1) : uid, // if first char is "," it is a newly generated UUID rowdata["AB_ATTRIBUTERELATIONID.value"],
rowdata["AB_ATTRIBUTE_ID.value"], rowdata["AB_ATTRIBUTE_ID.value"],
vars.get("$param.ObjectRowId_param"), vars.get("$param.ObjectRowId_param"),
vars.get("$param.ObjectType_param"), vars.get("$param.ObjectType_param"),
......
...@@ -8,31 +8,11 @@ import("Attribute_lib"); ...@@ -8,31 +8,11 @@ import("Attribute_lib");
var rowdata = vars.get("$local.rowdata"); var rowdata = vars.get("$local.rowdata");
var attributeId = rowdata["AB_ATTRIBUTE_ID.value"] var attributeId = rowdata["AB_ATTRIBUTE_ID.value"]
var type = AttributeUtil.getAttributeType(attributeId); var type = AttributeUtil.getAttributeType(attributeId);
var uid = vars.get("$local.uid").split(","); var attributeRelationId = vars.getString("$param.ShowEmpty_param") == "true"
? JSON.parse(vars.get("$local.uid"))[0]
: vars.get("$local.uid");
// if first char is "," it is a newly generated UUID if (vars.getString("$param.ShowEmpty_param") == "true" && !rowdata["AB_ATTRIBUTERELATIONID.value"])
if (uid.length === 1)
{
var fieldValues = {
"AB_ATTRIBUTE_ID" : attributeId,
"DATE_EDIT" : rowdata["DATE_EDIT.value"],
"USER_EDIT" : rowdata["USER_EDIT.value"]
};
var dbFields = AttributeTypeUtil.getAllDatabaseFields();
dbFields.forEach(function (row)
{
fieldValues[row] = ""; //set every field but the correct value field to null
});
fieldValues[AttributeTypeUtil.getDatabaseField(type)] = AttributeTypeUtil.useLookup(type)
? rowdata["VALUE_LOOKUP.value"]
: rowdata["VALUE.value"];
newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", "$local.uid")
.updateFields(fieldValues);
}
else
{ {
var columns = [ var columns = [
"AB_ATTRIBUTERELATIONID", "AB_ATTRIBUTERELATIONID",
...@@ -44,7 +24,7 @@ else ...@@ -44,7 +24,7 @@ else
]; ];
var values = [ var values = [
uid[0], // if first char is "," it is a newly generated UUID attributeRelationId,
attributeId, attributeId,
vars.get("$param.ObjectRowId_param"), vars.get("$param.ObjectRowId_param"),
vars.get("$param.ObjectType_param"), vars.get("$param.ObjectType_param"),
...@@ -62,6 +42,27 @@ else ...@@ -62,6 +42,27 @@ else
} }
db.insertData("AB_ATTRIBUTERELATION", columns, null, values); db.insertData("AB_ATTRIBUTERELATION", columns, null, values);
} }
else
{
var fieldValues = {
"AB_ATTRIBUTE_ID" : attributeId,
"DATE_EDIT" : rowdata["DATE_EDIT.value"],
"USER_EDIT" : rowdata["USER_EDIT.value"]
};
var dbFields = AttributeTypeUtil.getAllDatabaseFields();
dbFields.forEach(function (row)
{
fieldValues[row] = ""; //set every field but the correct value field to null
});
fieldValues[AttributeTypeUtil.getDatabaseField(type)] = AttributeTypeUtil.useLookup(type)
? rowdata["VALUE_LOOKUP.value"]
: rowdata["VALUE.value"];
newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", attributeRelationId)
.updateFields(fieldValues);
}
if (vars.get("$param.ObjectType_param") == "Person") if (vars.get("$param.ObjectType_param") == "Person")
DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$param.ObjectRowId_param"), vars.get("$param.ShowDsgvoMessage_param")); DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$param.ObjectRowId_param"), vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
<contentTitleProcess>%aditoprj%/entity/Attribute_entity/contentTitleProcess.js</contentTitleProcess> <contentTitleProcess>%aditoprj%/entity/Attribute_entity/contentTitleProcess.js</contentTitleProcess>
<afterUiInit>%aditoprj%/entity/Attribute_entity/afterUiInit.js</afterUiInit> <afterUiInit>%aditoprj%/entity/Attribute_entity/afterUiInit.js</afterUiInit>
<onValidation>%aditoprj%/entity/Attribute_entity/onValidation.js</onValidation> <onValidation>%aditoprj%/entity/Attribute_entity/onValidation.js</onValidation>
<afterOperatingState>%aditoprj%/entity/Attribute_entity/afterOperatingState.js</afterOperatingState>
<iconId>VAADIN:TAG</iconId> <iconId>VAADIN:TAG</iconId>
<titlePlural>Attributes</titlePlural> <titlePlural>Attributes</titlePlural>
<recordContainer>jdito</recordContainer> <recordContainer>jdito</recordContainer>
......
import("system.vars");
import("system.neon");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW && vars.get("$param.ParentIdPreset_param"))
neon.refreshAll();
\ 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