From 48a47a74a57f031600de8a4520063348510277f5 Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Mon, 1 Apr 2019 09:21:06 +0200
Subject: [PATCH] Exclude Activity & Task as chooseable context within the
 ActivityLink and TaskLink entity

---
 .../ActivityLink_entity.aod                   |  2 +-
 entity/Context_entity/Context_entity.aod      | 59 +++++++++++++++----
 .../excludecontexts_param/valueProcess.js     |  2 +
 .../excludecontexts_param/valueProcess.js     |  2 +
 .../recordcontainers/jdito/contentProcess.js  |  5 +-
 entity/TaskLink_entity/TaskLink_entity.aod    |  2 +-
 process/Context_lib/process.js                | 17 ++++--
 7 files changed, 70 insertions(+), 19 deletions(-)
 create mode 100644 entity/Context_entity/entityfields/activitylinkable/children/excludecontexts_param/valueProcess.js
 create mode 100644 entity/Context_entity/entityfields/tasklinkable/children/excludecontexts_param/valueProcess.js

diff --git a/entity/ActivityLink_entity/ActivityLink_entity.aod b/entity/ActivityLink_entity/ActivityLink_entity.aod
index be69dcabe1..ed4fc232f6 100644
--- a/entity/ActivityLink_entity/ActivityLink_entity.aod
+++ b/entity/ActivityLink_entity/ActivityLink_entity.aod
@@ -73,7 +73,7 @@
       <dependency>
         <name>dependency</name>
         <entityName>Context_entity</entityName>
-        <fieldName>#PROVIDER</fieldName>
+        <fieldName>ActivityLinkable</fieldName>
       </dependency>
     </entityConsumer>
     <entityParameter>
diff --git a/entity/Context_entity/Context_entity.aod b/entity/Context_entity/Context_entity.aod
index 922b46b44d..5410da87b5 100644
--- a/entity/Context_entity/Context_entity.aod
+++ b/entity/Context_entity/Context_entity.aod
@@ -16,18 +16,6 @@
           <fieldName>Context</fieldName>
           <isConsumer v="false" />
         </entityDependency>
-        <entityDependency>
-          <name>d713987f-1cf0-4c6c-8373-24d135d22dc8</name>
-          <entityName>ActivityLink_entity</entityName>
-          <fieldName>Context</fieldName>
-          <isConsumer v="false" />
-        </entityDependency>
-        <entityDependency>
-          <name>2dcb4637-6096-43fc-b07e-d44fb51fbc1b</name>
-          <entityName>TaskLink_entity</entityName>
-          <fieldName>Contexts</fieldName>
-          <isConsumer v="false" />
-        </entityDependency>
         <entityDependency>
           <name>37559258-24f1-4c8c-b462-23ddf8de4e1e</name>
           <entityName>AppointmentLink_entity</entityName>
@@ -53,6 +41,53 @@
     <entityProvider>
       <name>Context</name>
       <fieldType>DEPENDENCY_IN</fieldType>
+      <children>
+        <entityParameter>
+          <name>excludeContexts_param</name>
+          <expose v="false" />
+        </entityParameter>
+      </children>
+    </entityProvider>
+    <entityParameter>
+      <name>excludeContexts_param</name>
+      <expose v="true" />
+      <description>PARAMETER</description>
+    </entityParameter>
+    <entityProvider>
+      <name>ActivityLinkable</name>
+      <fieldType>DEPENDENCY_IN</fieldType>
+      <dependencies>
+        <entityDependency>
+          <name>de50f67e-5ed0-46aa-b007-8c086cf5fea5</name>
+          <entityName>ActivityLink_entity</entityName>
+          <fieldName>Context</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
+      </dependencies>
+      <children>
+        <entityParameter>
+          <name>excludeContexts_param</name>
+          <valueProcess>%aditoprj%/entity/Context_entity/entityfields/activitylinkable/children/excludecontexts_param/valueProcess.js</valueProcess>
+        </entityParameter>
+      </children>
+    </entityProvider>
+    <entityProvider>
+      <name>TaskLinkable</name>
+      <fieldType>DEPENDENCY_IN</fieldType>
+      <dependencies>
+        <entityDependency>
+          <name>ff8925da-b69a-46dd-8fe2-d6707da8808e</name>
+          <entityName>TaskLink_entity</entityName>
+          <fieldName>Contexts</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
+      </dependencies>
+      <children>
+        <entityParameter>
+          <name>excludeContexts_param</name>
+          <valueProcess>%aditoprj%/entity/Context_entity/entityfields/tasklinkable/children/excludecontexts_param/valueProcess.js</valueProcess>
+        </entityParameter>
+      </children>
     </entityProvider>
   </entityFields>
   <recordContainers>
diff --git a/entity/Context_entity/entityfields/activitylinkable/children/excludecontexts_param/valueProcess.js b/entity/Context_entity/entityfields/activitylinkable/children/excludecontexts_param/valueProcess.js
new file mode 100644
index 0000000000..e48be1dbc1
--- /dev/null
+++ b/entity/Context_entity/entityfields/activitylinkable/children/excludecontexts_param/valueProcess.js
@@ -0,0 +1,2 @@
+import("system.result");
+result.object(["Task", "Activity"]);
\ No newline at end of file
diff --git a/entity/Context_entity/entityfields/tasklinkable/children/excludecontexts_param/valueProcess.js b/entity/Context_entity/entityfields/tasklinkable/children/excludecontexts_param/valueProcess.js
new file mode 100644
index 0000000000..e48be1dbc1
--- /dev/null
+++ b/entity/Context_entity/entityfields/tasklinkable/children/excludecontexts_param/valueProcess.js
@@ -0,0 +1,2 @@
+import("system.result");
+result.object(["Task", "Activity"]);
\ No newline at end of file
diff --git a/entity/Context_entity/recordcontainers/jdito/contentProcess.js b/entity/Context_entity/recordcontainers/jdito/contentProcess.js
index 9ecbf1f708..503f36da09 100644
--- a/entity/Context_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Context_entity/recordcontainers/jdito/contentProcess.js
@@ -2,4 +2,7 @@ import("system.vars");
 import("system.result");
 import("Context_lib");
 
-result.object(ContextUtils.getContexts(true));
+var excludeContexts = vars.getString("$param.excludeContexts_param");
+if (excludeContexts)
+    excludeContexts = JSON.parse(excludeContexts);
+result.object(ContextUtils.getContexts(true, excludeContexts));
diff --git a/entity/TaskLink_entity/TaskLink_entity.aod b/entity/TaskLink_entity/TaskLink_entity.aod
index 8074c19d87..3809c91d58 100644
--- a/entity/TaskLink_entity/TaskLink_entity.aod
+++ b/entity/TaskLink_entity/TaskLink_entity.aod
@@ -60,7 +60,7 @@
       <dependency>
         <name>dependency</name>
         <entityName>Context_entity</entityName>
-        <fieldName>#PROVIDER</fieldName>
+        <fieldName>TaskLinkable</fieldName>
       </dependency>
     </entityConsumer>
     <entityConsumer>
diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index b8034c7952..70bfde6d1d 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -42,10 +42,11 @@ ContextUtils.getContextName = function(pContextId)
 /**
  *
  * @param {Boolean} [pFilter=false] filter only for contexts which have a mapping in ContextUtils._getSelectMap
+ * @param {String[]} [pExcludeContexts] contextIds that shall not be included (so this is a additional filter to the pFiler param)
  *
  * @return {String[][]} the contexts [[contextId, contextName, contextTitle], [... ], ...]
  */
-ContextUtils.getContexts = function(pFilter)
+ContextUtils.getContexts = function(pFilter, pExcludeContexts)
 {
     if (pFilter == undefined)
         pFilter = false;
@@ -54,13 +55,21 @@ ContextUtils.getContexts = function(pFilter)
 
     if (pFilter)
     {
-        contexts = contexts.filter(function(pContext)
-        {
+        contexts = contexts.filter(function(pContext) {
+            if (pExcludeContexts && pExcludeContexts.indexOf(pContext[0]) > -1)
+                return false;
             // filter only contexts which have defined mappings in Context_lib
             return ContextUtils._getSelectMap()[pContext[0]] != undefined;
         });
     }
-
+    else if (pExcludeContexts)
+    {
+        contexts = contexts.filter(function(pContext) {
+            if (pExcludeContexts && pExcludeContexts.indexOf(pContext[0]) > -1)
+                return false;
+            return true;
+        });
+    }
 
     return contexts.map(ContextUtils._contextDataMapping).sort(function(pContext1, pContext2)
         {
-- 
GitLab