Skip to content

Commit

Permalink
Merge pull request #266 from compucorp/develop
Browse files Browse the repository at this point in the history
Release v1.0.0-alpha9
  • Loading branch information
deb1990 authored Sep 27, 2019
2 parents eb5ebcf + ff3e26f commit 42fa314
Show file tree
Hide file tree
Showing 26 changed files with 311 additions and 174 deletions.
65 changes: 47 additions & 18 deletions CRM/Civicase/Activity/ContactActivitiesSelector.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<?php

/**
* Class CRM_Civicase_Activity_ContactActivitiesSelector.
*/
class CRM_Civicase_Activity_ContactActivitiesSelector {

const API_DEFAULT_LIMIT = 25;

/**
* Returns all the activities for a given contact. The contact must be either the creator,
* the client, or be one of the assignees for the activity. Also, the activity should
* not be assigned to someone else unless the contact is also an assignee.
* Get Acitivities for a Contact.
*
* Returns all the activities for a given contact. The contact must be
* either the creator, the client, or be one of the assignees for the
* activity. Also, the activity should not be assigned to someone else
* unless the contact is also an assignee.
*
* @param array $params
* Parameters.
*
* @return array
* Activities.
*/
public function getAllActivitiesForContact($params) {
public function getAllActivitiesForContact(array $params) {
$newParams = $this->getParamsWithoutOffsetsAndLimits($params);

$this->addAssigneeContactIdToReturnParams($newParams);
Expand All @@ -25,13 +34,17 @@ public function getAllActivitiesForContact($params) {
}

/**
* Returns paginated activities for the given contact using the limit and offset
* options.
* Returns paginated activities for the given contact.
*
* Uses the limit and offset options.
*
* @param array $params
* Parameters.
*
* @return array
* Activities.
*/
public function getPaginatedActivitiesForContact($params) {
public function getPaginatedActivitiesForContact(array $params) {
$activities = $this->getAllActivitiesForContact($params);

$this->paginateActivityRecords($activities, $params);
Expand All @@ -43,9 +56,12 @@ public function getPaginatedActivitiesForContact($params) {
* Returns the number of activities for the given contact.
*
* @param array $params
* Parameters.
*
* @return int
* Count.
*/
public function getActivitiesForContactCount($params) {
public function getActivitiesForContactCount(array $params) {
$activities = $this->getAllActivitiesForContact($params);

return $activities['count'];
Expand All @@ -55,9 +71,12 @@ public function getActivitiesForContactCount($params) {
* Returns the original parameters, but without any offsets or limits.
*
* @param array $params
* Parameters.
*
* @return array
* Paramaters.
*/
private function getParamsWithoutOffsetsAndLimits($params) {
private function getParamsWithoutOffsetsAndLimits(array $params) {
$options = CRM_Utils_Array::value('options', $params, []);
$options['limit'] = 0;
$options['offset'] = 0;
Expand All @@ -67,13 +86,15 @@ private function getParamsWithoutOffsetsAndLimits($params) {
}

/**
* Adds the `assignee_contact_id` field to the return parameter. This field
* is necesary in order to properly filter the activities for the contact and
* remove activities that have been delegated to someone else.
* Adds the `assignee_contact_id` field to the return parameter.
*
* This field is necesary in order to properly filter the activities for the
* contact and remove activities that have been delegated to someone else.
*
* @param array $params
* Parameters.
*/
private function addAssigneeContactIdToReturnParams(&$params) {
private function addAssigneeContactIdToReturnParams(array &$params) {
$return = (array) CRM_Utils_Array::value('return', $params, []);
$return[] = 'assignee_contact_id';
$return = array_unique($return);
Expand All @@ -82,15 +103,21 @@ private function addAssigneeContactIdToReturnParams(&$params) {
}

/**
* Removes any activities that have been assigned to another contact other than
* the requested one. It also updates the activities count in order to reflect the
* new value.
* Removes activities assigned to other contacts.
*
* Removes any activities that have been assigned to another contact other
* than the requested one. It also updates the activities count in order to
* reflect the new value.
*
* @param array $activities
* Activities.
* @param array $params
* Parameters.
*
* @return array
* Activities.
*/
private function filterOutActivitiesNotBelongingToContact(&$activities, $params) {
private function filterOutActivitiesNotBelongingToContact(array &$activities, array $params) {
$activities['values'] = array_filter($activities['values'], function ($activity) use ($params) {
$hasNoAssignee = empty($activity['assignee_contact_id']);
$isContactAssignedToActivity = in_array($params['contact_id'], $activity['assignee_contact_id']);
Expand All @@ -105,9 +132,11 @@ private function filterOutActivitiesNotBelongingToContact(&$activities, $params)
* Paginates the activity records according to the limit and offset params.
*
* @param array $activities
* Activities.
* @param array $params
* Paramaters.
*/
private function paginateActivityRecords(&$activities, $params) {
private function paginateActivityRecords(array &$activities, array $params) {
$options = CRM_Utils_Array::value('options', $params, []);
$limit = CRM_Utils_Array::value('limit', $options, self::API_DEFAULT_LIMIT);
$offset = CRM_Utils_Array::value('offset', $options, 0);
Expand Down
1 change: 1 addition & 0 deletions CRM/Civicase/Form/CaseWebforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function postProcess() {
}
}
Civi::settings()->set('civi_drupal_webforms', $items);
CRM_Core_Session::setStatus(ts('Your changes have been saved successfully.'), 'Case Webforms', 'success');
}

}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The activities tab on the case has been redesigned to take its own tab, making m

![Screenshot](img/activities-tab.png)

Users can also see an overall view of their activities from all cases allowing them to filter to see a few tasks or actions that they need to perform.

## Activity Categories

Activity Categories are sub-types of Activity type that determines how the activities are displayed to the user. There are 6 main types of activity category:
Expand Down Expand Up @@ -119,3 +121,18 @@ Link to extension: https://github.com/civicrm/org.civicrm.casetokens
* Lots of improvements to the CiviCase API
* Activity type icons
* Case status now has a ‘Status class’ field to show cases which are incomplete, completed, or cancelled.

# Technical Requirements
* CiviCRM: version >= v5.8, preferably the latest version.
* [Shoreditch](https://github.com/civicrm/org.civicrm.shoreditch): version >= v0.1-alpha32, preferably the latest version.
* (Recommended) Migrate from embedded activity revisions to full system logging ([CRM-21051](https://issues.civicrm.org/jira/browse/CRM-21051))

# Installation (git/cli)
To install the extension on an existing CiviCRM site:

mkdir sites/all/modules/civicrm/ext
cd sites/all/modules/civicrm/ext
git clone https://github.com/civicrm/org.civicrm.shoreditch shoreditch
git clone https://github.com/compucorp/uk.co.compucorp.civicase civicase
cv en shoreditch civicase

4 changes: 3 additions & 1 deletion ang/civicase.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ function set_tags_to_js_vars(&$options) {
function set_option_values_to_js_vars(&$options) {
foreach ($options as &$option) {
$result = civicrm_api3('OptionValue', 'get', [
'return' => ['value', 'label', 'color', 'icon', 'name', 'grouping'],
'return' => [
'value', 'label', 'color', 'icon', 'name', 'grouping', 'weight',
],
'option_group_id' => $option,
'is_active' => 1,
'options' => ['limit' => 0, 'sort' => 'weight'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,14 @@
}

return crmApi('Activity', 'get', _.assign(params, {
'return': [
return: [
'subject', 'details', 'activity_type_id', 'status_id',
'source_contact_name', 'target_contact_name', 'assignee_contact_name',
'activity_date_time', 'is_star', 'original_id', 'tag_id.name', 'tag_id.description',
'tag_id.color', 'file_id', 'is_overdue', 'case_id', 'priority_id',
'case_id.case_type_id', 'case_id.status_id', 'case_id.contacts'
],
activity_type_id: { '!=': 'Bulk Email' },
sequential: 1,
options: {
// We try to get one activity more than the display limit, so we can
Expand Down Expand Up @@ -504,6 +505,7 @@
var params = {};
var dateMoment = moment(date);

params.activity_type_id = { '!=': 'Bulk Email' };
params.status_id = status;
params.activity_date_time = {
BETWEEN: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
is_current_revision: 1,
is_deleted: 0,
is_test: 0,
activity_type_id: { '!=': 'Bulk Email' },
'api.Activity.getactionlinks': getActionLinksParams,
options: {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@
name: 'activity_type_id',
label: ts('Activity type'),
html_type: 'Select',
options: _.map(CRM.civicase.activityTypes, mapSelectOptions)
options: _.chain(CRM.civicase.activityTypes)
.filter(function (activity) {
return activity.name !== 'Bulk Email';
})
.map(mapSelectOptions)
.value()
},
{
name: 'status_id',
Expand Down
4 changes: 2 additions & 2 deletions ang/civicase/case/details/directives/case-details-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
<li>
<span class="list-group-item-info">{{ ts("Change status to:") }}</span>
</li>
<li ng-repeat="(id, status) in allowedCaseStatuses" ng-if="id != item.status_id">
<li ng-repeat="status in allowedCaseStatuses" ng-if="status.value != item.status_id">
<a
crm-popup-form-success="pushCaseData($data.civicase_reload[0])"
class="crm-popup"
ng-href="{{ 'civicrm/case/activity' | civicaseCrmUrl:{ action: 'add', reset: 1, cid: item.client[0].contact_id, caseid: item.id, atype: getActivityType('Change Case Status'), case_status_id: id, civicase_reload: caseGetParams() } }}">
ng-href="{{ 'civicrm/case/activity' | civicaseCrmUrl:{ action: 'add', reset: 1, cid: item.client[0].contact_id, caseid: item.id, atype: getActivityType('Change Case Status'), case_status_id: status.value, civicase_reload: caseGetParams() } }}">
{{ status.label }}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@

function getAllowedCaseStatuses (definition) {
var ret = _.cloneDeep(caseStatuses);
ret = _.chain(ret)
.sortBy(function (status) { return status.weight; })
.indexBy('weight')
.value();
if (definition.statuses && definition.statuses.length) {
_.each(_.cloneDeep(ret), function (status, id) {
if (definition.statuses.indexOf(status.name) < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
* @params {Boolean} replace
*/
$scope.assignRole = function (role, replace) {
var message = '<input name="caseRoleSelector" placeholder="' + ts('Select Coantact') + '" />';
var message = '<input name="caseRoleSelector" placeholder="' + ts('Select Contact') + '" />';
if (role.role !== 'Client') {
message = message + '<br/><textarea rows="3" cols="35" name="description" class="crm-form-textarea" style="margin-top: 10px;padding-left: 10px;border-color: #C2CFDE;color: #9494A4;" placeholder="Description"></textarea>';
}
Expand Down
8 changes: 4 additions & 4 deletions ang/civicase/case/directives/case-overview.directive.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
<div
class="civicase__case-overview__flow-status civicase__case-overview__flow-status--hoverable"
ng-if="!status.isHidden"
ng-repeat="(statusId, status) in caseStatuses"
ng-repeat="status in caseStatuses"
uib-popover="{{ status.label }}"
popover-trigger="'mouseenter'"
popover-placement="bottom"
popover-append-to-body="true"
popover-class="civicase__tooltip-popup-list">
<div class="civicase__case-overview__flow-status__count">
<a ng-href="{{ caseListLink(null, status.name) }}">
{{ summaryData.all[statusId] || '0' }}
{{ summaryData.all[status.value] || '0' }}
</a>
</div>
<div class="civicase__case-overview__flow-status__description">
Expand Down Expand Up @@ -80,9 +80,9 @@ <h3>No status selected</h3>
<div
class="civicase__case-overview__breakdown-field"
ng-if="!status.isHidden"
ng-repeat="(statusId, status) in caseStatuses">
ng-repeat="status in caseStatuses">
<a ng-href="{{ caseListLink(caseType.name, status.name) }}">
{{ summaryData[ctid][statusId] || '0' }}
{{ summaryData[ctid][status.value] || '0' }}
</a>
</div>
<div class="civicase__case-overview__breakdown-field" ng-if="areAllStatusesHidden()"> - </div>
Expand Down
5 changes: 4 additions & 1 deletion ang/civicase/case/directives/case-overview.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
var caseTypes = CRM.civicase.caseTypes;
var caseTypeCategories = CRM.civicase.caseTypeCategories;

$scope.caseStatuses = CRM.civicase.caseStatuses;
$scope.summaryData = [];
$scope.caseStatuses = _.chain(CRM.civicase.caseStatuses)
.sortBy(function (status) { return status.weight; })
.indexBy('weight')
.value();

(function init () {
setCaseTypesBasedOnCategory();
Expand Down
5 changes: 5 additions & 0 deletions ang/civicase/case/factories/get-case-query-params.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
case_id: caseId,
is_current_revision: 1,
is_test: 0,
activity_type_id: { '!=': 'Bulk Email' },
'activity_type_id.grouping': {LIKE: '%communication%'},
'status_id.filter': 1,
options: {limit: panelLimit, sort: 'activity_date_time DESC'},
Expand All @@ -54,6 +55,7 @@
case_id: caseId,
is_current_revision: 1,
is_test: 0,
activity_type_id: { '!=': 'Bulk Email' },
'activity_type_id.grouping': {LIKE: '%task%'},
'status_id.filter': 0,
options: {limit: panelLimit, sort: 'activity_date_time ASC'},
Expand All @@ -63,6 +65,7 @@
'api.Activity.get.nextActivitiesWhichIsNotMileStone': {
case_id: caseId,
status_id: {'!=': 'Completed'},
activity_type_id: { '!=': 'Bulk Email' },
'activity_type_id.grouping': {'NOT LIKE': '%milestone%'},
options: {
limit: 1
Expand All @@ -73,6 +76,7 @@
case_id: caseId,
is_current_revision: 1,
is_deleted: 0,
activity_type_id: { '!=': 'Bulk Email' },
'status_id': 'Scheduled'
},
// For the "scheduled-overdue" count
Expand All @@ -81,6 +85,7 @@
is_current_revision: 1,
is_deleted: 0,
is_overdue: 1,
activity_type_id: { '!=': 'Bulk Email' },
status_id: 'Scheduled'
},
// Custom data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'is_deleted': 0,
'is_test': 0,
'activity_type_id.grouping': { 'NOT LIKE': '%milestone%' },
'activity_type_id': { '!=': 'Bulk Email' },
'status_id': { 'IN': CRM.civicase.activityStatusTypes.incomplete },
'options': { 'sort': 'is_overdue DESC, activity_date_time ASC' },
'return': [
Expand Down
Loading

0 comments on commit 42fa314

Please sign in to comment.