Skip to content

Commit

Permalink
Merge pull request #9 from compucorp/develop
Browse files Browse the repository at this point in the history
Release v1.0.0-alpha3
  • Loading branch information
deb1990 authored Mar 19, 2019
2 parents 7219dbe + 0a1c198 commit 86d071b
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 28 deletions.
31 changes: 25 additions & 6 deletions ang/civicaseextras.ang.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
<?php

return [
'js' => [
/**
* Returns a list of Civicaseextras JS files to be bundled.
*
* @return array
*/
function getCivicaseExtrasJSFiles () {
return array_merge(array(
'assetBuilder://visual-bundle.js',
'ang/civicaseextras.js',
'ang/civicaseextras/*.js',
],
'ang/civicaseextras.js'
), glob_recursive(dirname(__FILE__) . '/civicaseextras/*.js'));
}

/**
* Returns a list of Civicaseextras settings that will be shared with the front-end.
*
* @return array
*/
function getCivicaseExtrasSettings () {
return [
'overdueNotificationLimit' => (int) Civi::settings()->get('civicaseCaseLastUpdatedNotificationLimit'),
];
}

return [
'js' => getCivicaseExtrasJSFiles(),
'css' => [
'assetBuilder://visual-bundle.css',
'css/*.css',
],
'partials' => [
'ang/civicaseextras',
],
'settings' => [],
'settings' => getCivicaseExtrasSettings(),
'requires' => [
'crmUtil'
],
Expand Down
34 changes: 34 additions & 0 deletions ang/civicaseextras/decorators/formatCase.decorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(function (angular, caseStatuses, civicaseextras) {
var module = angular.module('civicase');

module.config(function ($provide) {
$provide.decorator('formatCase', formatCaseDecorator);
});

function formatCaseDecorator ($delegate) {
var originalFormatCase = $delegate;

/**
* Enhances the formatCase method so it adds information about overdue dates for the case.
*
* @param {Object} caseItem
* @return {Object}
*/
return function formatCase (caseItem) {
var overdueNotificationLimit = parseInt(civicaseextras.overdueNotificationLimit, 10);
var isStatusOpen = caseStatuses[caseItem.status_id].grouping === 'Opened';
var isModifiedDateOverdue = moment().subtract(overdueNotificationLimit, 'days')
.isSameOrAfter(caseItem.modified_date);
caseItem = originalFormatCase(caseItem);
caseItem.overdueDates = {
modified_date: isStatusOpen && isModifiedDateOverdue
};

return caseItem;
};
}
})(
angular,
CRM.civicase.caseStatuses,
CRM.civicaseextras
);
42 changes: 42 additions & 0 deletions ang/test/civicaseextras/decorators/formatCase.decorator.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env jasmine */

(function (CRM) {
describe('formatCase decorator', function () {
var formatCase, formattedCase, mockCase;

beforeEach(module('civicase', 'civicaseextras', 'civicase.data'));

beforeEach(inject(function (CasesData, _formatCase_) {
mockCase = CasesData.get().values[0];
formatCase = _formatCase_;
}));

describe('when the case modified date is over the limit', function () {
beforeEach(function () {
CRM.civicaseextras.overdueNotificationLimit = 90;
mockCase.modified_date = moment()
.subtract(90, 'days')
.format('YYYY-MM-DD HH:mm:ss');
formattedCase = formatCase(mockCase);
});

it('marks the modified date as overdue', function () {
expect(formattedCase.overdueDates.modified_date).toBe(true);
});
});

describe('when the case modified date is not over the limit', function () {
beforeEach(function () {
CRM.civicaseextras.overdueNotificationLimit = 160;
mockCase.modified_date = moment()
.subtract(90, 'days')
.format('YYYY-MM-DD HH:mm:ss');
formattedCase = formatCase(mockCase);
});

it('does not mark the modified date as overdue', function () {
expect(formattedCase.overdueDates.modified_date).toBe(false);
});
});
});
})(CRM);
1 change: 1 addition & 0 deletions ang/test/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(function (CRM) {
CRM.civicase = {};
CRM.civicaseextras = {};
CRM.angular = { requires: {} };
/**
* Dependency Injection for civicase module, defined in ang/civicase.ang.php
Expand Down
4 changes: 3 additions & 1 deletion ang/test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module.exports = function (config) {
// angular templates
extPath + '/ang/civicaseextras/*.html',

// Civicase Mock files
// Civicase files
civicasePath + '/ang/civicase.js',
civicasePath + '/ang/civicase/case/factories/format-case.factory.js',
{ pattern: civicasePath + '/ang/test/mocks/modules.mock.js' },
{ pattern: civicasePath + '/ang/test/mocks/**/*.js' },

Expand Down
116 changes: 97 additions & 19 deletions civicaseextras.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require_once 'civicaseextras.civix.php';
use CRM_Civicaseextras_ExtensionUtil as E;
use \Civi\Angular\ChangeSet as AngularChangeSet;
use \Civi\Angular\Manager as AngularManager;

/**
* Implements hook_civicrm_config().
Expand Down Expand Up @@ -134,34 +136,110 @@ function civicaseextras_civicrm_entityTypes(&$entityTypes) {
_civicaseextras_civix_civicrm_entityTypes($entityTypes);
}

function civicaseextras_civicrm_alterAngular(\Civi\Angular\Manager $angular) {
_civicaseextras_civicrm_alterAngular($angular);
/**
* Implements hook_civicrm_alterAngular().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterAngular/
*/
function civicaseextras_civicrm_alterAngular(AngularManager $angular) {
_civicaseextras_alterAngular_addVisualAlert($angular);
_civicaseextras_alterAngular_appendOutcomePanel($angular);
}

// --- Functions below this ship commented out. Uncomment as required. ---
/**
* Implements hook_civicrm_alterContent().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterContent/
*/
function civicaseextras_civicrm_alterContent (&$content, $context, $templateName, $form) {
$isViewingTheCaseAdminForm = get_class($form) === CRM_Admin_Form_Setting_Case::class;

if ($isViewingTheCaseAdminForm) {
_civicaseextras_alterContent_addCivicaseAdminSettingsFields($content);
}
}

/**
* Implements hook_civicrm_preProcess().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess/
*/
function civicaseextras_civicrm_preProcess($formName, &$form) {
if ($formName == 'CRM_Admin_Form_Setting_Case') {
_civicaseextras_preProcess_addCivicaseAdminSettingsFieldsReference($form);
}
}

/**
* Adds extra settings fields to the Civicase Admin Settings form.
*
* @param string $content the original form content.
*/
function _civicaseextras_alterContent_addCivicaseAdminSettingsFields (&$content) {
$settingsTemplateHtml = _civicaseextras_getTemplateContent('CRM/Civicaseextra/Admin/Form/Settings.tpl');

$doc = phpQuery::newDocumentHTML($content);
$doc->find('table.form-layout tr:last')->append($settingsTemplateHtml);

$content = $doc->getDocument();
}

/**
* It adds extra settings to the Civicase settings page.
*
* @param object $form a reference to the civicase admin form.
*/
function _civicaseextras_preProcess_addCivicaseAdminSettingsFieldsReference (&$form) {
$settings = $form->getVar('_settings');
$settings['civicaseCaseLastUpdatedNotificationLimit'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;

} // */
$form->setVar('_settings', $settings);
}

/**
* Implements hook_civicrm_navigationMenu().
* Replaces the date column type on case lists so it displays an alert when the
* given date is overdue.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
* @param $angular AngularManager
*/
function _civicaseextras_alterAngular_addVisualAlert (AngularManager &$angular) {
$changeSet = AngularChangeSet::create('display_warning_for_overdue_cases')
->alterHtml('~/civicase/case/list/directives/case-list-table.directive.html',
function (phpQueryObject $doc) {
$caseListTableHtml = _civicaseextras_getTemplateContent('CRM/Civicaseextra/Partials/CaseListTable.tpl');

$doc->find('[ng-switch-when="date"]')
->html($caseListTableHtml);
});

$angular->add($changeSet);
}

/**
* Appends the case outcomes to the case details summary.
*
function civicaseextras_civicrm_navigationMenu(&$menu) {
_civicaseextras_civix_insert_navigation_menu($menu, 'Mailings', array(
'label' => E::ts('New subliminal message'),
'name' => 'mailing_subliminal_message',
'url' => 'civicrm/mailing/subliminal',
'permission' => 'access CiviMail',
'operator' => 'OR',
'separator' => 0,
));
_civicaseextras_civix_navigationMenu($menu);
} // */
* @param $angular AngularManager
*/
function _civicaseextras_alterAngular_appendOutcomePanel (AngularManager &$angular) {
$changeSet = AngularChangeSet::create('inject_case_outcomes')
->alterHtml('~/civicase/case/details/summary-tab/case-summary-custom-data.html',
function (phpQueryObject $doc) {
$doc->find('civicase-masonry-grid')
->prepend('<civicase-extras-case-outcome case="item"></civicase-extras-case-outcome>');
});
$angular->add($changeSet);
}

/**
* Returns the HTML generated by the smarty template located at the given path.
*
* @param string $templatePath the path tot he smarty template.
* @param array $vars the list of vars and their values to pass to the template.
*
* @return string
*/
function _civicaseextras_getTemplateContent ($templatePath, $vars = []) {
$smarty = &CRM_Core_Smarty::singleton();

return $smarty->fetchWith($templatePath, $vars);
}
4 changes: 2 additions & 2 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<url desc="Support">http://compucorp.co.uk</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2018-10-29</releaseDate>
<version>1.0.0-alpha1</version>
<releaseDate>2019-03-19</releaseDate>
<version>1.0.0-alpha3</version>
<develStage>alpha</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"globals": [
"CRM",
"angular",
"moment",
"inject"
]
},
Expand Down
23 changes: 23 additions & 0 deletions settings/Civicaseextras.setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

return [
'civicaseCaseLastUpdatedNotificationLimit' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'civicaseCaseLastUpdatedNotificationLimit',
'quick_form_type' => 'Element',
'type' => 'Integer',
'default' => 90,
'html_type' => 'text',
'html_attributes' => array(
'size' => 2,
'maxlength' => 4,
),
'add' => '4.7',
'title' => 'Last updated notification after days',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'This adds a visual indicator for cases where there has not been any activity for the selected number of days. This will be visible on the Manage Cases screen on the last updated date.',
'help_text' => '',
],
];
10 changes: 10 additions & 0 deletions templates/CRM/Civicaseextra/Admin/Form/Settings.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tr class="crm-case-form-block-civicase-overdue-notification-limit">
<td class="label">{$form.civicaseCaseLastUpdatedNotificationLimit.label}</td>
<td>{$form.civicaseCaseLastUpdatedNotificationLimit.html}<br />
<span class="description">
{ts}This adds a visual indicator for cases where there has not been any activity
for the selected number of days. This will be visible on the Manage Cases screen
on the last updated date.{/ts}
</span>
</td>
</tr>
12 changes: 12 additions & 0 deletions templates/CRM/Civicaseextra/Partials/CaseListTable.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<span ng-if="!item.overdueDates[header.name]">
{literal}
{{ CRM.utils.formatDate(item[header.name]) }}
{/literal}
</span>
<strong ng-if="item.overdueDates[header.name]"
class="text-danger">
{literal}
{{ CRM.utils.formatDate(item[header.name]) }}
{/literal}
<i class="material-icons civicase__icon">error</i>
</strong>

0 comments on commit 86d071b

Please sign in to comment.