From c44a504f03d30065803be5d7d6e7fe4955f7aa1d Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Tue, 19 Feb 2019 13:39:06 +0100
Subject: [PATCH] Combobox Attribute

---
 .../AttributeRelation_entity.aod              |  1 +
 .../possibleItemsProcess.js                   |  2 +-
 .../possibleItemsProcess.js                   | 19 ++++++++++++++
 .../attributerelation_value/valueProcess.js   | 16 ++++++------
 entity/Attribute_entity/Attribute_entity.aod  | 14 +++-------
 .../attribute_level/valueProcess.js           | 12 ++++++---
 .../displayValueProcess.js                    |  6 +----
 .../attribute_type/displayValueProcess.js     | 13 ++++++++++
 .../attribute_type/valueProcess.js            | 12 +++++++++
 .../children/attributelevel_param/code.js     |  4 ---
 .../children/attrparentid_param/code.js       |  3 ++-
 .../recordcontainers/db/conditionProcess.js   |  3 ++-
 entity/Attribute_entity/titleProcess.js       |  4 +++
 .../AttributeRelationFilter_view.aod          |  4 ++-
 process/Attribute_lib/process.js              | 26 ++++++++++++-------
 15 files changed, 95 insertions(+), 44 deletions(-)
 create mode 100644 entity/AttributeRelation_entity/entityfields/attributerelation_value/possibleItemsProcess.js
 create mode 100644 entity/Attribute_entity/entityfields/attribute_type/displayValueProcess.js
 create mode 100644 entity/Attribute_entity/entityfields/attribute_type/valueProcess.js
 delete mode 100644 entity/Attribute_entity/entityfields/attributechildren/children/attributelevel_param/code.js
 create mode 100644 entity/Attribute_entity/titleProcess.js

diff --git a/entity/AttributeRelation_entity/AttributeRelation_entity.aod b/entity/AttributeRelation_entity/AttributeRelation_entity.aod
index 3578214cba..a9171ba77e 100644
--- a/entity/AttributeRelation_entity/AttributeRelation_entity.aod
+++ b/entity/AttributeRelation_entity/AttributeRelation_entity.aod
@@ -34,6 +34,7 @@
       <title>Value</title>
       <contentTypeProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/attributerelation_value/contentTypeProcess.js</contentTypeProcess>
       <resolution>DAY</resolution>
+      <possibleItemsProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/attributerelation_value/possibleItemsProcess.js</possibleItemsProcess>
       <valueProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/attributerelation_value/valueProcess.js</valueProcess>
       <onValueChange>%aditoprj%/entity/AttributeRelation_entity/entityfields/attributerelation_value/onValueChange.js</onValueChange>
     </entityField>
diff --git a/entity/AttributeRelation_entity/entityfields/attribute_parent_id/possibleItemsProcess.js b/entity/AttributeRelation_entity/entityfields/attribute_parent_id/possibleItemsProcess.js
index 2449074c96..4a159dc81d 100644
--- a/entity/AttributeRelation_entity/entityfields/attribute_parent_id/possibleItemsProcess.js
+++ b/entity/AttributeRelation_entity/entityfields/attribute_parent_id/possibleItemsProcess.js
@@ -2,4 +2,4 @@ import("system.vars");
 import("system.result");
 import("Attribute_lib");
         
-result.object(AttributeUtil.getPossibleAttributes(vars.get("$param.objectType_param")));
+result.object(AttributeUtil.getPossibleAttributes(vars.get("$param.objectType_param"), true));
diff --git a/entity/AttributeRelation_entity/entityfields/attributerelation_value/possibleItemsProcess.js b/entity/AttributeRelation_entity/entityfields/attributerelation_value/possibleItemsProcess.js
new file mode 100644
index 0000000000..5a3b4bd6a7
--- /dev/null
+++ b/entity/AttributeRelation_entity/entityfields/attributerelation_value/possibleItemsProcess.js
@@ -0,0 +1,19 @@
+import("system.db");
+import("system.result");
+import("system.vars");
+import("Attribute_lib");
+import("Sql_lib");
+
+var attributeId = vars.get("$field.AB_ATTRIBUTE_ID");
+var attrType = AttributeHandler.begin(attributeId).getAttributeType();
+
+if (attrType == AttributeTypes.COMBO)
+{
+    var valueSql = SqlCondition.begin()
+        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId)
+        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", AttributeTypes.COMBOVALUE)
+        .buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_NAME from AB_ATTRIBUTE");
+    var valueList = db.table(valueSql);
+    
+    result.object(valueList);
+}    
\ No newline at end of file
diff --git a/entity/AttributeRelation_entity/entityfields/attributerelation_value/valueProcess.js b/entity/AttributeRelation_entity/entityfields/attributerelation_value/valueProcess.js
index 334477e1aa..6edf4b6ff8 100644
--- a/entity/AttributeRelation_entity/entityfields/attributerelation_value/valueProcess.js
+++ b/entity/AttributeRelation_entity/entityfields/attributerelation_value/valueProcess.js
@@ -2,25 +2,25 @@ import("system.result");
 import("system.vars");
 import("Attribute_lib");
 
-var attrField = AttributeHandler.begin(vars.get("$field.AB_ATTRIBUTE_ID")).getAttributeField();
+var attrType = AttributeHandler.begin(vars.get("$field.AB_ATTRIBUTE_ID")).getAttributeType();
 
-if (attrField != null) //load the value from the correct field for the type
+if (attrType != null) //load the value from the correct field for the type
 {
-    switch (attrField)
+    switch (attrType)
     {
-        case "CHAR_VALUE":
+        case AttributeTypes.TEXT:
             result.string(vars.get("$field.CHAR_VALUE"));
             break;    
-        case "DATE_VALUE":
+        case AttributeTypes.DATE:
             result.string(vars.get("$field.DATE_VALUE"));
             break;
-        case "NUMBER_VALUE":
+        case AttributeTypes.NUMBER:
             result.string(vars.get("$field.NUMBER_VALUE"));
             break;
-        case "BOOL_VALUE":
+        case AttributeTypes.BOOLEAN:
             result.string(vars.get("$field.BOOL_VALUE"));
             break;
-        case "ID_VALUE":
+        case AttributeTypes.COMBO:
             result.string(vars.get("$field.ID_VALUE"));
             break;            
     }
diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod
index 6a7b129788..33e1964169 100644
--- a/entity/Attribute_entity/Attribute_entity.aod
+++ b/entity/Attribute_entity/Attribute_entity.aod
@@ -5,6 +5,7 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/Attribute_entity/documentation.adoc</documentation>
   <iconId>VAADIN:TAG</iconId>
+  <titleProcess>%aditoprj%/entity/Attribute_entity/titleProcess.js</titleProcess>
   <recordContainer>db</recordContainer>
   <entityFields>
     <entityProvider>
@@ -22,6 +23,8 @@
       <title>Type</title>
       <consumer>KeywordAttributeType</consumer>
       <mandatory v="true" />
+      <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js</valueProcess>
+      <displayValueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attribute_type/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
       <name>AB_ATTRIBUTEID</name>
@@ -53,12 +56,6 @@
           <triggerRecalculation v="true" />
           <mandatory v="false" />
         </entityParameter>
-        <entityParameter>
-          <name>attributeLevel_param</name>
-          <code>%aditoprj%/entity/Attribute_entity/entityfields/attributechildren/children/attributelevel_param/code.js</code>
-          <triggerRecalculation v="true" />
-          <mandatory v="false" />
-        </entityParameter>
       </children>
     </entityConsumer>
     <entityProvider>
@@ -124,11 +121,6 @@
         </entityParameter>
       </children>
     </entityConsumer>
-    <entityParameter>
-      <name>attributeLevel_param</name>
-      <expose v="true" />
-      <description>PARAMETER</description>
-    </entityParameter>
     <entityField>
       <name>ATTRIBUTE_LEVEL</name>
       <title>Level</title>
diff --git a/entity/Attribute_entity/entityfields/attribute_level/valueProcess.js b/entity/Attribute_entity/entityfields/attribute_level/valueProcess.js
index 5098441456..1c37c30f46 100644
--- a/entity/Attribute_entity/entityfields/attribute_level/valueProcess.js
+++ b/entity/Attribute_entity/entityfields/attribute_level/valueProcess.js
@@ -1,10 +1,16 @@
+import("system.db");
 import("system.neon");
 import("system.result");
 import("system.vars");
+import("Sql_lib");
 
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
-    if (vars.exists("$param.attributeLevel_param") && vars.get("$param.attributeLevel_param")
-        && vars.exists("$param.attrParentId_param") && vars.get("$param.attrParentId_param"))
-        result.string(parseInt(vars.get("$param.attributeLevel_param")) + 1);
+    if (vars.get("$field.ATTRIBUTE_PARENT_ID") != "")
+    {
+        var level = db.cell(SqlCondition.begin()
+            .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", vars.get("$field.ATTRIBUTE_PARENT_ID"))
+            .buildSql("select ATTRIBUTE_LEVEL from AB_ATTRIBUTE"));
+        result.string(parseInt(level) + 1);
+    }
     else
         result.string("0");
diff --git a/entity/Attribute_entity/entityfields/attribute_parent_id/displayValueProcess.js b/entity/Attribute_entity/entityfields/attribute_parent_id/displayValueProcess.js
index 24c340a034..c220255e0c 100644
--- a/entity/Attribute_entity/entityfields/attribute_parent_id/displayValueProcess.js
+++ b/entity/Attribute_entity/entityfields/attribute_parent_id/displayValueProcess.js
@@ -1,9 +1,5 @@
-import("system.neon");
 import("system.result");
 import("system.vars");
 import("Attribute_lib");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.attrParentId_param") && vars.get("$param.attrParentId_param"))
-    result.string(AttributeUtil.getAttributeNameById(vars.get("$param.attrParentId_param")));
-else
-    result.string(AttributeUtil.getAttributeNameById(vars.get("$field.ATTRIBUTE_PARENT_ID")))
\ No newline at end of file
+result.string(AttributeUtil.getAttributeNameById(vars.get("$field.ATTRIBUTE_PARENT_ID")))
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attribute_type/displayValueProcess.js b/entity/Attribute_entity/entityfields/attribute_type/displayValueProcess.js
new file mode 100644
index 0000000000..22960d0b70
--- /dev/null
+++ b/entity/Attribute_entity/entityfields/attribute_type/displayValueProcess.js
@@ -0,0 +1,13 @@
+import("system.db");
+import("system.neon");
+import("system.result");
+import("system.vars");
+import("Attribute_lib");
+import("Keyword_lib");
+
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$field.ATTRIBUTE_PARENT_ID") != "")
+{
+    var type = AttributeHandler.begin(vars.get("$field.ATTRIBUTE_PARENT_ID")).getAttributeType();
+    if (type == AttributeTypes.COMBO)
+        result.string(KeywordUtils.getViewValue($KeywordRegistry.get.AttributeType, AttributeTypes.COMBOVALUE));
+}
\ 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
new file mode 100644
index 0000000000..6dff8bf600
--- /dev/null
+++ b/entity/Attribute_entity/entityfields/attribute_type/valueProcess.js
@@ -0,0 +1,12 @@
+import("system.db");
+import("system.neon");
+import("system.result");
+import("system.vars");
+import("Attribute_lib");
+
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$field.ATTRIBUTE_PARENT_ID") != "")
+{
+    var type = AttributeHandler.begin(vars.get("$field.ATTRIBUTE_PARENT_ID")).getAttributeType();
+    if (type == AttributeTypes.COMBO)
+        result.string(AttributeTypes.COMBOVALUE);
+}
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attributechildren/children/attributelevel_param/code.js b/entity/Attribute_entity/entityfields/attributechildren/children/attributelevel_param/code.js
deleted file mode 100644
index 5790e0cc44..0000000000
--- a/entity/Attribute_entity/entityfields/attributechildren/children/attributelevel_param/code.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import("system.vars");
-import("system.result");
-
-result.string(vars.getString("$field.ATTRIBUTE_LEVEL"));
\ No newline at end of file
diff --git a/entity/Attribute_entity/entityfields/attributechildren/children/attrparentid_param/code.js b/entity/Attribute_entity/entityfields/attributechildren/children/attrparentid_param/code.js
index 58f3a0fedf..11e081d017 100644
--- a/entity/Attribute_entity/entityfields/attributechildren/children/attrparentid_param/code.js
+++ b/entity/Attribute_entity/entityfields/attributechildren/children/attrparentid_param/code.js
@@ -2,7 +2,8 @@ import("system.vars");
 import("system.result");
 import("Attribute_lib");
 
-if (vars.getString("$field.ATTRIBUTE_TYPE").trim() == AttributeTypes.GROUP)
+var type = vars.getString("$field.ATTRIBUTE_TYPE").trim();
+if (type == AttributeTypes.GROUP || type == AttributeTypes.COMBO)
     result.string(vars.getString("$field.AB_ATTRIBUTEID"));
 else
     result.string("");
diff --git a/entity/Attribute_entity/recordcontainers/db/conditionProcess.js b/entity/Attribute_entity/recordcontainers/db/conditionProcess.js
index 8b53a13f9c..f43b26a529 100644
--- a/entity/Attribute_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Attribute_entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,9 @@ import("system.db");
 import("system.vars");
 import("system.result");
 import("Sql_lib");
+import("Attribute_lib");
 
-var condition = "1=2";
+var condition = "AB_ATTRIBUTE.ATTRIBUTE_TYPE = '" + AttributeTypes.GROUP + "'";
 
 if (vars.exists("$param.attrParentId_param") && vars.get("$param.attrParentId_param"))
     condition = "AB_ATTRIBUTE.AB_ATTRIBUTEID in ('" + getAllChildren(vars.getString("$param.attrParentId_param")).join("','") + "')";
diff --git a/entity/Attribute_entity/titleProcess.js b/entity/Attribute_entity/titleProcess.js
new file mode 100644
index 0000000000..09b4ecb2cc
--- /dev/null
+++ b/entity/Attribute_entity/titleProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$field.ATTRIBUTE_NAME"));
\ No newline at end of file
diff --git a/neonView/AttributeRelationFilter_view/AttributeRelationFilter_view.aod b/neonView/AttributeRelationFilter_view/AttributeRelationFilter_view.aod
index 75bd616a56..fbcf895c91 100644
--- a/neonView/AttributeRelationFilter_view/AttributeRelationFilter_view.aod
+++ b/neonView/AttributeRelationFilter_view/AttributeRelationFilter_view.aod
@@ -27,7 +27,9 @@
     </tableViewTemplate>
     <treetableViewTemplate>
       <name>Tree</name>
-      <titleField>ATTRIBUTERELATION_VALUE</titleField>
+      <parentField>ATTRIBUTE_PARENT_ID</parentField>
+      <titleField>AB_ATTRIBUTE_ID</titleField>
+      <descriptionField>ATTRIBUTERELATION_VALUE</descriptionField>
       <entityField>#ENTITY</entityField>
     </treetableViewTemplate>
   </children>
diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js
index e756e95ca3..dac5966054 100644
--- a/process/Attribute_lib/process.js
+++ b/process/Attribute_lib/process.js
@@ -18,23 +18,25 @@ function AttributeUtil () {}
  * process for the attribute id in AttributeRelation
  * 
  * @param {String} pObjectType the object type (= context)
+ * @param {boolean} pIncludeGroups
  * 
  * @return {String[][]} two-dimensional array of attributeIds and names
  */
-AttributeUtil.getPossibleAttributes = function (pObjectType)
+AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups)
 {
     if (pObjectType == null)
         return [];
     
     var attrSql = "select AB_ATTRIBUTEID from AB_ATTRIBUTE"
         + " join AB_ATTRIBUTEUSAGE  on AB_ATTRIBUTEID = AB_ATTRIBUTE_ID";
-    attrSql = SqlCondition.begin()
+    attrCond = SqlCondition.begin()
         .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
-        .and("ATTRIBUTE_TYPE != '" + AttributeTypes.GROUP + "'")
-        .and("ATTRIBUTE_ACTIVE = 1")
-        .buildSql(attrSql);
+        .and("ATTRIBUTE_ACTIVE = 1");
+        
+    if (!pIncludeGroups)
+        attrCond.and("ATTRIBUTE_TYPE != '" + AttributeTypes.GROUP + "'");
     
-    var attributes = db.array(db.COLUMN, attrSql).map(function (id) 
+    var attributes = db.array(db.COLUMN, attrCond.buildSql(attrSql)).map(function (id) 
     {
         return [id, AttributeUtil.getAttributeNameById(id)];
     });
@@ -115,7 +117,7 @@ AttributeHandler.begin = function (pAttrId)
  * 
  * @return {String} attribute type
  */
-AttributeHandler.prototype._getAttributeType = function () //TODO: maybe the type should be an own field in the entity instead of getting the type from the attribute id
+AttributeHandler.prototype.getAttributeType = function () //TODO: maybe the type should be an own field in the entity instead of getting the type from the attribute id
 {
     if (this._attributeType == null && this.attributeId != null)
     {
@@ -135,7 +137,7 @@ AttributeHandler.prototype._getAttributeType = function () //TODO: maybe the typ
  */
 AttributeHandler.prototype.getAttributeField = function ()
 {
-    return AttributeTypes.getEntityField(this._getAttributeType());
+    return AttributeTypes.getEntityField(this.getAttributeType());
 }
 
 /**
@@ -145,7 +147,7 @@ AttributeHandler.prototype.getAttributeField = function ()
  */
 AttributeHandler.prototype.getAttributeContentType = function ()
 {
-    return AttributeTypes.getContentType(this._getAttributeType());
+    return AttributeTypes.getContentType(this.getAttributeType());
 }
 
 AttributeHandler.prototype.setAttributeValue = function (pValue)
@@ -200,6 +202,12 @@ var AttributeTypes = {
         databaseField : "ID_VALUE", 
         entityField : "ID_VALUE"
     },
+    COMBOVALUE : {
+        toString : function () {return "COMBOVALUE"},
+        contentType : null, 
+        databaseField : null, 
+        entityField : null
+    },
     GROUP : {
         toString : function () {return "GROUP"},
         contentType : null, 
-- 
GitLab