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

Prevent deleting mandatory attributes

parent cc3cda83
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
<title>Attribute</title> <title>Attribute</title>
<consumer>SpecificAttribute</consumer> <consumer>SpecificAttribute</consumer>
<mandatory v="false" /> <mandatory v="false" />
<stateProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/stateProcess.js</stateProcess>
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/valueProcess.js</valueProcess> <valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/valueProcess.js</valueProcess>
<displayValueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/displayValueProcess.js</displayValueProcess> <displayValueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/displayValueProcess.js</displayValueProcess>
<onValueChange>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js</onValueChange> <onValueChange>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js</onValueChange>
...@@ -261,6 +262,10 @@ ...@@ -261,6 +262,10 @@
<valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/showdsgvomessage_param/valueProcess.js</valueProcess> <valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/showdsgvomessage_param/valueProcess.js</valueProcess>
<expose v="true" /> <expose v="true" />
</entityParameter> </entityParameter>
<entityField>
<name>PROTECTED</name>
<state>READONLY</state>
</entityField>
</entityFields> </entityFields>
<recordContainers> <recordContainers>
<jDitoRecordContainer> <jDitoRecordContainer>
...@@ -289,6 +294,9 @@ ...@@ -289,6 +294,9 @@
<jDitoRecordFieldMapping> <jDitoRecordFieldMapping>
<name>AB_ATTRIBUTE_ID.displayValue</name> <name>AB_ATTRIBUTE_ID.displayValue</name>
</jDitoRecordFieldMapping> </jDitoRecordFieldMapping>
<jDitoRecordFieldMapping>
<name>PROTECTED.value</name>
</jDitoRecordFieldMapping>
</recordFieldMappings> </recordFieldMappings>
</jDitoRecordContainer> </jDitoRecordContainer>
</recordContainers> </recordContainers>
......
import("system.neon");
import("system.vars");
import("system.result");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
result.string(vars.exists("$param.GetTree_param") && vars.getString("$param.GetTree_param") == "true"
? neon.COMPONENTSTATE_READONLY
: neon.COMPONENTSTATE_EDITABLE
);
\ No newline at end of file
import("Attribute_lib");
import("system.result"); import("system.result");
import("system.vars"); import("system.vars");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"); result.object(vars.get("$field.PROTECTED") != "true");
var rowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param"); \ No newline at end of file
if (vars.get("$param.GetTree_param") == "true" && rowId)
result.object(AttributeRelationUtils.countAttributeRelations(rowId, objectType) != 0);
\ No newline at end of file
...@@ -22,6 +22,8 @@ var sqlCondition = new SqlCondition(); //where-condition (condition for the Attr ...@@ -22,6 +22,8 @@ var sqlCondition = new SqlCondition(); //where-condition (condition for the Attr
var joinCondition = new SqlCondition(); //condition for the joined values (for AttributeRelation) 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 //=> 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")) if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
{ {
let idVals = vars.get("$local.idvalues"); let idVals = vars.get("$local.idvalues");
...@@ -45,7 +47,6 @@ else if (showEmpty || rowId) ...@@ -45,7 +47,6 @@ else if (showEmpty || rowId)
{ {
let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"); let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param");
let possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
sqlCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes); sqlCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes);
} }
if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param")) if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"))
...@@ -98,6 +99,23 @@ else ...@@ -98,6 +99,23 @@ else
attributeSql.leftJoin("AB_ATTRIBUTE", "COMBOVAL.AB_ATTRIBUTEID = " + $AttributeTypes.COMBO.databaseField, "COMBOVAL"); 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 attributeValues = db.table(attributeSql.build()).map(function (row)
{ {
var attributeId = row[1]; var attributeId = row[1];
...@@ -115,11 +133,20 @@ var attributeValues = db.table(attributeSql.build()).map(function (row) ...@@ -115,11 +133,20 @@ var attributeValues = db.table(attributeSql.build()).map(function (row)
else else
viewValue = AttributeTypeUtil.getAttributeViewValue(type, value, row[5]); viewValue = AttributeTypeUtil.getAttributeViewValue(type, value, row[5]);
if (attributeId in countCheck)
countCheck[attributeId].count++;
//TODO: what should be the uid if showEmpty is true? //TODO: what should be the uid if showEmpty is true?
// V-- set "," to mark this as new generated UUID // V-- set "," to mark this as new generated UUID
return [row[0] || util.getNewUUID() + "," + attributeId, row[2], value, viewValue, attributeId, attributeName]; 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 parentAttributes = [];
var attributeObj = {}; //object of attribute ids to avoid duplicates var attributeObj = {}; //object of attribute ids to avoid duplicates
...@@ -151,7 +178,7 @@ function _fetchAttributes (pAttributeIds) ...@@ -151,7 +178,7 @@ function _fetchAttributes (pAttributeIds)
else else
row[1] = null; row[1] = null;
row[2] = translate.text(row[2]); //translate attribute name row[2] = translate.text(row[2]); //translate attribute name
parentAttributes.push([row[0], row[1], "", "", "", row[2]]); parentAttributes.push([row[0], row[1], "", "", "", row[2], "true"]);
}, attributeObj); }, attributeObj);
if (nextIds.length) if (nextIds.length)
......
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