From: Alok Patel Date: Thu, 31 May 2018 12:22:21 +0000 (+0530) Subject: CIVICRM-874: CiviCase, added reference of activities from different timelines. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=093f1cfda6c10e8e29c4c42523859ca9fa669d29;p=civicrm-core.git CIVICRM-874: CiviCase, added reference of activities from different timelines. --- diff --git a/CRM/Case/BAO/CaseType.php b/CRM/Case/BAO/CaseType.php index 42cc1baedd..89baec6098 100644 --- a/CRM/Case/BAO/CaseType.php +++ b/CRM/Case/BAO/CaseType.php @@ -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; diff --git a/ang/crmCaseType.js b/ang/crmCaseType.js index ee9efb9603..0f74d410f8 100644 --- a/ang/crmCaseType.js +++ b/ang/crmCaseType.js @@ -261,6 +261,8 @@ $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; @@ -288,14 +290,27 @@ } 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) { @@ -363,6 +378,7 @@ var idx = _.indexOf(array, item); if (idx != -1) { array.splice(idx, 1); + resetTimelineActivityTypes(); } }; @@ -462,6 +478,7 @@ 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) { diff --git a/ang/crmCaseType/timelineTable.html b/ang/crmCaseType/timelineTable.html index bc38d3ddd5..0dba5c98bd 100644 --- a/ang/crmCaseType/timelineTable.html +++ b/ang/crmCaseType/timelineTable.html @@ -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" > diff --git a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php index d43375c017..d0f8bed73d 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTypeTest.php @@ -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'), diff --git a/tests/phpunit/api/v3/CaseTypeTest.php b/tests/phpunit/api/v3/CaseTypeTest.php index fc6516a7f6..ebdcf2e9fe 100644 --- a/tests/phpunit/api/v3/CaseTypeTest.php +++ b/tests/phpunit/api/v3/CaseTypeTest.php @@ -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), ),