CIVICRM-874: CiviCase, added reference of activities from different timelines.
authorAlok Patel <alok@agileware.com.au>
Thu, 31 May 2018 12:22:21 +0000 (17:52 +0530)
committerAlok Patel <alok@agileware.com.au>
Thu, 31 May 2018 12:22:21 +0000 (17:52 +0530)
CRM/Case/BAO/CaseType.php
ang/crmCaseType.js
ang/crmCaseType/timelineTable.html
tests/phpunit/CRM/Case/BAO/CaseTypeTest.php
tests/phpunit/api/v3/CaseTypeTest.php

index 42cc1baedde825e5ec2075a6dc75f2b749780d04..89baec6098e0224babbbac96f9508b18857481d6 100644 (file)
@@ -242,6 +242,8 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType {
     // set activity sets
     if (isset($xml->ActivitySets)) {
       $definition['activitySets'] = array();
+      $definition['timelineActivityTypes'] = array();
+
       foreach ($xml->ActivitySets->ActivitySet as $activitySetXML) {
         // parse basic properties
         $activitySet = array();
@@ -257,7 +259,11 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType {
         if (isset($activitySetXML->ActivityTypes)) {
           $activitySet['activityTypes'] = array();
           foreach ($activitySetXML->ActivityTypes->ActivityType as $activityTypeXML) {
-            $activitySet['activityTypes'][] = json_decode(json_encode($activityTypeXML), TRUE);
+            $activityType = json_decode(json_encode($activityTypeXML), TRUE);
+            $activitySet['activityTypes'][] = $activityType;
+            if ($activitySetXML->timeline) {
+              $definition['timelineActivityTypes'][] = $activityType;
+            }
           }
         }
         $definition['activitySets'][] = $activitySet;
index ee9efb960306a0300db811fe211f5b17a779b9fe..0f74d410f8c90850daa6f0c40d6a49d8453445d7 100644 (file)
     $scope.caseType.definition.caseRoles = $scope.caseType.definition.caseRoles || [];
     $scope.caseType.definition.statuses = $scope.caseType.definition.statuses || [];
 
+    $scope.caseType.definition.timelineActivityTypes = $scope.caseType.definition.timelineActivityTypes || [];
+
     $scope.selectedStatuses = {};
     _.each(apiCalls.caseStatuses.values, function (status) {
       $scope.selectedStatuses[status.name] = !$scope.caseType.definition.statuses.length || $scope.caseType.definition.statuses.indexOf(status.name) > -1;
     }
 
     function addActivityToSet(activitySet, activityTypeName) {
-      activitySet.activityTypes.push({
-        name: activityTypeName,
-        label: $scope.activityTypes[activityTypeName].label,
-        status: 'Scheduled',
-        reference_activity: 'Open Case',
-        reference_offset: '1',
-        reference_select: 'newest'
-      });
+      var activity = {
+          name: activityTypeName,
+          label: $scope.activityTypes[activityTypeName].label,
+          status: 'Scheduled',
+          reference_activity: 'Open Case',
+          reference_offset: '1',
+          reference_select: 'newest'
+      };
+      activitySet.activityTypes.push(activity);
+      if(typeof activitySet.timeline !== "undefined" && activitySet.timeline == "1") {
+        $scope.caseType.definition.timelineActivityTypes.push(activity);
+      }
+    }
+
+    function resetTimelineActivityTypes() {
+        $scope.caseType.definition.timelineActivityTypes = [];
+        angular.forEach($scope.caseType.definition.activitySets, function(activitySet) {
+            angular.forEach(activitySet.activityTypes, function(activityType) {
+                $scope.caseType.definition.timelineActivityTypes.push(activityType);
+            });
+        });
     }
 
     function createActivity(name, callback) {
       var idx = _.indexOf(array, item);
       if (idx != -1) {
         array.splice(idx, 1);
+        resetTimelineActivityTypes();
       }
     };
 
     if (!$scope.isForkable()) {
       CRM.alert(ts('The CiviCase XML file for this case-type prohibits editing the definition.'));
     }
+
   });
 
   crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) {
index bc38d3ddd57438bcd13f93a04e3f7e23f4b71b79..0dba5c98bda64b6dfda5dec7f5a8777ad46b71e7 100644 (file)
@@ -39,7 +39,7 @@ Required vars: activitySet
         ui-jq="select2"
         ui-options="{dropdownAutoWidth : true}"
         ng-model="activity.reference_activity"
-        ng-options="activityType.name as activityType.label for activityType in activitySet.activityTypes"
+        ng-options="activityType.name as activityType.label for activityType in caseType.definition.timelineActivityTypes"
         >
         <option value="">-- Case Start --</option>
       </select>
index d43375c0173b6c07ec0def7115d88e8e1a38491e..d0f8bed73dc65996a1975082b084b31365c0c4dc 100644 (file)
@@ -23,6 +23,7 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
         'activitySets' => array(),
         'activityTypes' => array(),
         'caseRoles' => array(),
+        'timelineActivityTypes' => array(),
       )),
       'xml' => file_get_contents(__DIR__ . '/xml/empty-lists.xml'),
     );
@@ -42,6 +43,9 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
             ),
           ),
         ),
+        'timelineActivityTypes' => array(
+          array('name' => 'Open Case', 'status' => 'Completed'),
+        ),
         'caseRoles' => array(
           array('name' => 'First role', 'creator' => 1, 'manager' => 1),
         ),
@@ -80,6 +84,15 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
             ),
           ),
         ),
+        'timelineActivityTypes' => array(
+          array('name' => 'Open Case', 'status' => 'Completed'),
+          array(
+            'name' => 'Meeting',
+            'reference_activity' => 'Open Case',
+            'reference_offset' => 1,
+            'reference_select' => 'newest',
+          ),
+        ),
         'caseRoles' => array(
           array('name' => 'First role', 'creator' => 1, 'manager' => 1),
           array('name' => 'Second role'),
index fc6516a7f692e00a24a039f1480a5205046dca5f..ebdcf2e9fee59b96b05675aa8b344a07d7bfd9dd 100644 (file)
@@ -54,6 +54,9 @@ class api_v3_CaseTypeTest extends CiviCaseTestCase {
             ),
           ),
         ),
+        'timelineActivityTypes' => array(
+          array('name' => 'Open Case', 'status' => 'Completed'),
+        ),
         'caseRoles' => array(
           array('name' => 'First role', 'creator' => 1, 'manager' => 1),
         ),