From 26d338d09dc8f33e08d94d8b103869526fb2a795 Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Thu, 18 Apr 2019 15:59:45 +0200
Subject: [PATCH] Task: reactivate the dashlet with filter for your own tasks

---
 entity/Task_entity/Task_entity.aod                |  6 ++++++
 .../filteronlyowntask_param/valueProcess.js       |  3 +++
 .../recordcontainers/db/conditionProcess.js       | 15 +++++++++++++--
 neonView/TaskFilter_view/TaskFilter_view.aod      |  6 ++++++
 4 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 entity/Task_entity/entityfields/filteronlyowntask_param/valueProcess.js

diff --git a/entity/Task_entity/Task_entity.aod b/entity/Task_entity/Task_entity.aod
index c2a53c27f12..954b18c3d26 100644
--- a/entity/Task_entity/Task_entity.aod
+++ b/entity/Task_entity/Task_entity.aod
@@ -395,6 +395,12 @@
       <title>subject</title>
       <linkedContext>Task</linkedContext>
     </entityField>
+    <entityParameter>
+      <name>FilterOnlyOwnTask_param</name>
+      <valueProcess>%aditoprj%/entity/Task_entity/entityfields/filteronlyowntask_param/valueProcess.js</valueProcess>
+      <expose v="true" />
+      <description>PARAMETER</description>
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Task_entity/entityfields/filteronlyowntask_param/valueProcess.js b/entity/Task_entity/entityfields/filteronlyowntask_param/valueProcess.js
new file mode 100644
index 00000000000..e0f3ec47e2b
--- /dev/null
+++ b/entity/Task_entity/entityfields/filteronlyowntask_param/valueProcess.js
@@ -0,0 +1,3 @@
+import("system.result");
+
+result.string(false);
\ No newline at end of file
diff --git a/entity/Task_entity/recordcontainers/db/conditionProcess.js b/entity/Task_entity/recordcontainers/db/conditionProcess.js
index 28d6be4aaec..923b39eb1ad 100644
--- a/entity/Task_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Task_entity/recordcontainers/db/conditionProcess.js
@@ -1,18 +1,29 @@
+import("Employee_lib");
 import("system.vars");
 import("system.db");
 import("system.result");
 import("Sql_lib");
 
 var cond = new SqlCondition();
+var alternativeFallbackCondition = "1 = 1";
+
+if (vars.getString("$param.FilterOnlyOwnTask_param") == "true")
+{
+    var ownContactId = EmployeeUtils.getCurrentContactId();
+    if (ownContactId)
+        cond.andPrepareIfSet("TASK.EDITOR_CONTACT_ID", ownContactId);
+    else
+        alternativeFallbackCondition = "1 = 2";
+}
 if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param"))
 {
     var activityLinkCond = SqlCondition.begin().andPrepareVars("TASKLINK.OBJECT_ROWID", "$param.RowId_param")
                                                .andPrepareVars("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param");
 
-                                                            // TODO: more performant way than IN. Maybe a join??
+                                                            // TODO: more performant way than IN. Maybe a join?
     cond.and(db.translateStatement(activityLinkCond.buildSql("TASK.TASKID in (select TASKLINK.TASK_ID from TASKLINK", "1=2", ")")))
 }
 
 //TODO: use a preparedCondition when available #1030812 #1034026
-var resCond = db.translateCondition(cond.build("1 = 1"));
+var resCond = db.translateCondition(cond.build(alternativeFallbackCondition));
 result.string(resCond);
diff --git a/neonView/TaskFilter_view/TaskFilter_view.aod b/neonView/TaskFilter_view/TaskFilter_view.aod
index 7494ed682d3..71b68935414 100644
--- a/neonView/TaskFilter_view/TaskFilter_view.aod
+++ b/neonView/TaskFilter_view/TaskFilter_view.aod
@@ -18,6 +18,12 @@
           <title>Tasks</title>
         </neonDashletCategory>
       </categories>
+      <parameters>
+        <neonDashletParameter>
+          <name>FilterOnlyOwnTask_param</name>
+          <value>true</value>
+        </neonDashletParameter>
+      </parameters>
     </neonDashletConfiguration>
   </dashletConfigurations>
   <layout>
-- 
GitLab