From bf53fc9f62d11b2890767f422db4fa7a9589240c Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Tue, 28 Jan 2020 11:24:59 +0100
Subject: [PATCH] Attribute_entitiy newChildAttribute and parent lookup

---
 entity/Attribute_entity/Attribute_entity.aod  | 20 +++++++++++++++++++
 .../attribute_parent_id/valueProcess.js       |  4 ++--
 .../attribute_type/valueProcess.js            | 10 +++++++---
 .../newchildattribute/onActionProcess.js      |  4 ++--
 .../children/childtype_param/valueProcess.js  |  5 ++++-
 .../displaysimplename_param/valueProcess.js   |  3 +++
 .../dropdownfilter/stateProcess.js            | 10 ++++++++++
 .../whitelistids_param/valueProcess.js        | 19 +++++++-----------
 .../AttributeEdit_view/AttributeEdit_view.aod |  8 ++++----
 .../AttributeLookup_view.aod                  |  1 +
 process/Attribute_lib/process.js              |  5 +++--
 .../SetAttribute_workflowService/process.js   |  2 +-
 12 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 entity/Attribute_entity/entityfields/attributegroup/children/displaysimplename_param/valueProcess.js
 create mode 100644 entity/Attribute_entity/entityfields/dropdownfilter/stateProcess.js

diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod
index 26495570d6..8f0a4a35b9 100644
--- a/entity/Attribute_entity/Attribute_entity.aod
+++ b/entity/Attribute_entity/Attribute_entity.aod
@@ -173,6 +173,10 @@
           <name>ChildType_param</name>
           <expose v="false" />
         </entityParameter>
+        <entityParameter>
+          <name>ParentIdPreset_param</name>
+          <expose v="false" />
+        </entityParameter>
       </children>
     </entityProvider>
     <entityField>
@@ -211,6 +215,7 @@
     </entityProvider>
     <entityConsumer>
       <name>AttributeGroup</name>
+      <description>Used for the selection of the parent attribute</description>
       <dependency>
         <name>dependency</name>
         <entityName>Attribute_entity</entityName>
@@ -225,6 +230,10 @@
           <name>ChildType_param</name>
           <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributegroup/children/childtype_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>DisplaySimpleName_param</name>
+          <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributegroup/children/displaysimplename_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityField>
@@ -262,6 +271,7 @@
       <name>DROPDOWNFILTER</name>
       <title>Filter</title>
       <contentType>FILTER_TREE</contentType>
+      <stateProcess>%aditoprj%/entity/Attribute_entity/entityfields/dropdownfilter/stateProcess.js</stateProcess>
       <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/dropdownfilter/valueProcess.js</valueProcess>
     </entityField>
     <entityParameter>
@@ -348,11 +358,21 @@
           <name>ParentId_param</name>
           <expose v="false" />
         </entityParameter>
+        <entityParameter>
+          <name>ParentIdPreset_param</name>
+          <expose v="false" />
+        </entityParameter>
       </children>
     </entityProvider>
     <entityParameter>
       <name>ParentId_param</name>
       <expose v="true" />
+      <description>parent id, this is used for filtering by the parent in the content process</description>
+    </entityParameter>
+    <entityParameter>
+      <name>ParentIdPreset_param</name>
+      <expose v="true" />
+      <description>parent id that is used to preset the parent when the action newChildAttribute is used</description>
     </entityParameter>
   </entityFields>
   <recordContainers>
diff --git a/entity/Attribute_entity/entityfields/attribute_parent_id/valueProcess.js b/entity/Attribute_entity/entityfields/attribute_parent_id/valueProcess.js
index 33e1114869..75b9d2d76b 100644
--- a/entity/Attribute_entity/entityfields/attribute_parent_id/valueProcess.js
+++ b/entity/Attribute_entity/entityfields/attribute_parent_id/valueProcess.js
@@ -2,5 +2,5 @@ import("system.neon");
 import("system.result");
 import("system.vars");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$param.ParentId_param") && vars.get("$this.value") == null)
-    result.string(vars.get("$param.ParentId_param"));
\ No newline at end of file
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$param.ParentIdPreset_param") && vars.get("$this.value") == null)
+    result.string(vars.get("$param.ParentIdPreset_param"));
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js b/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js
index 8ce11bd55e..05edbe151d 100644
--- a/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js
+++ b/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js
@@ -6,8 +6,12 @@ import("Attribute_lib");
 
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$field.ATTRIBUTE_PARENT_ID"))
 {
-    var type = AttributeUtil.getAttributeType(vars.get("$field.ATTRIBUTE_PARENT_ID"));
-    var possibleTypes = AttributeTypeUtil.getPossibleChildren(type);
-    if (possibleTypes && possibleTypes.length === 1)
+    var parentType = AttributeUtil.getAttributeType(vars.get("$field.ATTRIBUTE_PARENT_ID"));
+    var type = vars.get("$this.value");
+    var possibleTypes = AttributeTypeUtil.getPossibleChildren(parentType);
+    
+    if (possibleTypes && possibleTypes.length === 1) //only one type possible -> set that type
         result.string(possibleTypes[0]);
+    else if (possibleTypes.indexOf(type) === -1) //selected type can't be used with parent -> reset type
+        result.string("");
 }
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attributeactions/children/newchildattribute/onActionProcess.js b/entity/Attribute_entity/entityfields/attributeactions/children/newchildattribute/onActionProcess.js
index 20effae6f9..f78e4a1844 100644
--- a/entity/Attribute_entity/entityfields/attributeactions/children/newchildattribute/onActionProcess.js
+++ b/entity/Attribute_entity/entityfields/attributeactions/children/newchildattribute/onActionProcess.js
@@ -8,8 +8,8 @@ if (vars.exists("$local.rows"))
     var row = vars.get("$local.rows");
     var type = row[0].ATTRIBUTE_TYPE.trim();
     if (AttributeTypeUtil.isGroupType(type))
-        params["ParentId_param"] = row[0].UID;
+        params["ParentIdPreset_param"] = row[0].UID;
     else if (row[0].ATTRIBUTE_PARENT_ID)
-        params["ParentId_param"] = row[0].ATTRIBUTE_PARENT_ID;
+        params["ParentIdPreset_param"] = row[0].ATTRIBUTE_PARENT_ID;
 }
 neon.openContext("Attribute", null, null, neon.OPERATINGSTATE_NEW, params);
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attributegroup/children/childtype_param/valueProcess.js b/entity/Attribute_entity/entityfields/attributegroup/children/childtype_param/valueProcess.js
index fee1dfa70b..42196cc111 100644
--- a/entity/Attribute_entity/entityfields/attributegroup/children/childtype_param/valueProcess.js
+++ b/entity/Attribute_entity/entityfields/attributegroup/children/childtype_param/valueProcess.js
@@ -1,4 +1,7 @@
+import("system.neon");
 import("system.vars");
 import("system.result");
 
-result.string(vars.get("$field.ATTRIBUTE_TYPE").trim());
\ No newline at end of file
+//filter by parent types only when editing an existing attribute because in new-mode the own type can always change depending on the parent
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
+    result.string(vars.get("$field.ATTRIBUTE_TYPE").trim());
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attributegroup/children/displaysimplename_param/valueProcess.js b/entity/Attribute_entity/entityfields/attributegroup/children/displaysimplename_param/valueProcess.js
new file mode 100644
index 0000000000..40effa0178
--- /dev/null
+++ b/entity/Attribute_entity/entityfields/attributegroup/children/displaysimplename_param/valueProcess.js
@@ -0,0 +1,3 @@
+import("system.result");
+
+result.string(true);
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/dropdownfilter/stateProcess.js b/entity/Attribute_entity/entityfields/dropdownfilter/stateProcess.js
new file mode 100644
index 0000000000..0d13ea84ec
--- /dev/null
+++ b/entity/Attribute_entity/entityfields/dropdownfilter/stateProcess.js
@@ -0,0 +1,10 @@
+import("system.neon");
+import("system.vars");
+import("system.result");
+import("Attribute_lib");
+
+var fieldState = neon.COMPONENTSTATE_INVISIBLE;
+if (vars.get("$field.ATTRIBUTE_TYPE").trim() == $AttributeTypes.OBJECTSELECTION)
+    fieldState = neon.COMPONENTSTATE_EDITABLE;
+
+result.string(fieldState);
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/keywordattributetypes/children/whitelistids_param/valueProcess.js b/entity/Attribute_entity/entityfields/keywordattributetypes/children/whitelistids_param/valueProcess.js
index 2e9ce3a224..e6e7f7340b 100644
--- a/entity/Attribute_entity/entityfields/keywordattributetypes/children/whitelistids_param/valueProcess.js
+++ b/entity/Attribute_entity/entityfields/keywordattributetypes/children/whitelistids_param/valueProcess.js
@@ -6,18 +6,13 @@ import("Attribute_lib");
 
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
 {
-    var possibleTypes;
+    var type;
     if (vars.get("$field.ATTRIBUTE_PARENT_ID"))
-    {
-        var type = AttributeUtil.getAttributeType(vars.get("$field.ATTRIBUTE_PARENT_ID"));
-        possibleTypes = AttributeTypeUtil.getPossibleChildren(type);
-    }
-    if (!possibleTypes)
-    {
-        possibleTypes = [];
-        for (let attrType in $AttributeTypes)
-            if ($AttributeTypes[attrType].toString() != $AttributeTypes.COMBOVALUE.toString())
-                possibleTypes.push($AttributeTypes[attrType].toString());
-    }
+        type = AttributeUtil.getAttributeType(vars.get("$field.ATTRIBUTE_PARENT_ID"));
+    else
+        type = $AttributeTypes.GROUP.toString(); //GROUP can have everything except COMBOVALUE as child
+    
+    var possibleTypes = AttributeTypeUtil.getPossibleChildren(type);
+    
     result.object(possibleTypes);
 }
\ No newline at end of file
diff --git a/neonView/AttributeEdit_view/AttributeEdit_view.aod b/neonView/AttributeEdit_view/AttributeEdit_view.aod
index 3f5917a44b..aa32605fe0 100644
--- a/neonView/AttributeEdit_view/AttributeEdit_view.aod
+++ b/neonView/AttributeEdit_view/AttributeEdit_view.aod
@@ -30,6 +30,10 @@
           <name>529f9734-182e-46f3-ad89-14dc5656f307</name>
           <entityField>DROPDOWNDEFINITION</entityField>
         </entityFieldLink>
+        <entityFieldLink>
+          <name>7f7616c5-d633-4ffd-b05e-51f9fed982c2</name>
+          <entityField>DROPDOWNFILTER</entityField>
+        </entityFieldLink>
         <entityFieldLink>
           <name>d26696ac-199c-45f0-9147-b75dee3f4b65</name>
           <entityField>ATTRIBUTE_ACTIVE</entityField>
@@ -38,10 +42,6 @@
           <name>c8a5f45e-8092-45f4-ac22-681700447235</name>
           <entityField>ATTRIBUTE_LEVEL</entityField>
         </entityFieldLink>
-        <entityFieldLink>
-          <name>7f7616c5-d633-4ffd-b05e-51f9fed982c2</name>
-          <entityField>DROPDOWNFILTER</entityField>
-        </entityFieldLink>
       </fields>
     </genericViewTemplate>
     <neonViewReference>
diff --git a/neonView/AttributeLookup_view/AttributeLookup_view.aod b/neonView/AttributeLookup_view/AttributeLookup_view.aod
index 760e5a324d..7f0dd4723a 100644
--- a/neonView/AttributeLookup_view/AttributeLookup_view.aod
+++ b/neonView/AttributeLookup_view/AttributeLookup_view.aod
@@ -11,6 +11,7 @@
     <treeTableViewTemplate>
       <name>TreeTable</name>
       <parentField>ATTRIBUTE_PARENT_ID</parentField>
+      <showChildrenCount v="false" />
       <entityField>#ENTITY</entityField>
       <columns>
         <neonTreeTableColumn>
diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js
index d897d664cb..9c2bd2c0a4 100644
--- a/process/Attribute_lib/process.js
+++ b/process/Attribute_lib/process.js
@@ -787,7 +787,8 @@ $AttributeTypes.GROUP = {
     toString : function () {return "GROUP";},
     contentType : null, 
     databaseField : null,
-    isGroup : true
+    isGroup : true,
+    possibleChildren : ["GROUP", "TEXT", "NUMBER", "COMBO", "VOID", "THEME", "KEYWORD", "OBJECTSELECTION", "MEMO", "DATE", "BOOLEAN"]
 };
 $AttributeTypes.KEYWORD = {
     toString : function () {return "KEYWORD";},
@@ -958,7 +959,7 @@ AttributeTypeUtil.getGroupTypes = function (pChildType)
     var groupTypes = [];
     for (let type in $AttributeTypes)
     {
-        if (AttributeTypeUtil.isGroupType(type) && (!AttributeTypeUtil.getPossibleChildren(type) || AttributeTypeUtil.getPossibleChildren(type).indexOf(pChildType) !== -1))
+        if (AttributeTypeUtil.isGroupType(type) && (!pChildType || (!AttributeTypeUtil.getPossibleChildren(type) || AttributeTypeUtil.getPossibleChildren(type).indexOf(pChildType) !== -1)) )
             groupTypes.push(type);
     }
     return groupTypes;
diff --git a/process/SetAttribute_workflowService/process.js b/process/SetAttribute_workflowService/process.js
index 1bc687a73c..bff728c897 100644
--- a/process/SetAttribute_workflowService/process.js
+++ b/process/SetAttribute_workflowService/process.js
@@ -9,4 +9,4 @@ var value = variables.attributeValue;
 var objectRowId = variables.targetId;
 var objectType = variables.targetContext;
 
-result.string(new AttributeRelationQuery(objectRowId, attributeId, objectType).insertAttribute(value));
\ No newline at end of file
+result.string(new AttributeRelationQuery(objectRowId, attributeId, objectType).insertAttribute(value));
-- 
GitLab