Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEUSPRT-324: Allow user to customize activity date format #1015

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: pull_request
jobs:
run-unit-tests:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
container: compucorp/civicrm-buildkit:1.3.1-php8.0-chrome

env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* Add ActivityDateFormat To DateSettings BuildForm Hook Class.
*/
class CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings {

/**
* Adds Activity DateFormat To Date Settings Form.
*
* @param CRM_Core_Form $form
* Form Class object.
* @param string $formName
* Form Name.
*/
public function run(CRM_Core_Form &$form, $formName) {
if (!$this->shouldRun($formName)) {
return;
}

$this->addActivityDateFormatField($form);
}

/**
* Checks if this shook should run.
*
* @param string $formName
* Form Name.
*
* @return bool
* True if the hook should run.
*/
public function shouldRun($formName) {
return $formName == CRM_Admin_Form_Setting_Date::class;
}

/**
* Add activity date format field.
*
* @param CRM_Core_Form $form
* Form Class object.
*/
private function addActivityDateFormatField($form) {
$name = 'civiCaseActivityDateformat';
$fieldName = '_qf_' . $name;
$field = [
$fieldName => [
'html_type' => 'text',
'title' => ts('Date Format: Activity Feed'),
'weight' => 5,
],
];

$form->add('text', $fieldName, $field[$fieldName]['title'], $field[$fieldName]['attributes']);
$value = Civi::settings()->get($name) ?? '%d %b %Y';
$form->setDefaults(array_merge($form->_defaultValues, [$fieldName => $value]));

CRM_Core_Region::instance('form-body')->add([
'template' => "CRM/Civicase/Form/CaseActivityDateFormat.tpl",
]);
}

}
48 changes: 48 additions & 0 deletions CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use CRM_Civicase_ExtensionUtil as E;

/**
* FormatCaseActivityDateFormat BuildForm Hook Class.
*/
class CRM_Civicase_Hook_BuildForm_FormatCaseActivityDateFormat {

/**
* Adds Activity DateFormat To Date Settings Form.
*
* @param CRM_Core_Form $form
* Form Class object.
* @param string $formName
* Form Name.
*/
public function run(CRM_Core_Form &$form, $formName) {
if (!$this->shouldRun($form, $formName)) {
return;
}

$format = Civi::settings()->get('civiCaseActivityDateformat') ?? '%d %b %Y';
$dateValue = CRM_Utils_Date::customFormat($form->_defaultValues['activity_date_time'], $format);

\Civi::resources()->addVars('civicase', ['formatted_date' => $dateValue]);
\Civi::resources()->add([
'scriptFile' => [E::LONG_NAME, 'js/modify-activity-date.js'],
'region' => 'form-body',
]);
}

/**
* Checks if this shook should run.
*
* @param CRM_Core_Form $form
* Form Class object.
* @param string $formName
* Form Name.
*
* @return bool
* True if the hook should run.
*/
public function shouldRun($form, $formName) {
return $formName == CRM_Activity_Form_Activity::class && $form->getAction() & CRM_Core_Action::VIEW;
}

}
50 changes: 50 additions & 0 deletions CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Save Activity DateFormat.
*/
class CRM_Civicase_Hook_PostProcess_SaveCaseActivityDateFormat {

/**
* Saves The Activity DateFormat field.
*
* @param string $formName
* Form Name.
* @param CRM_Core_Form $form
* Form Class object.
*/
public function run($formName, CRM_Core_Form $form) {
if (!$this->shouldRun($formName)) {
return;
}

$this->saveCaseActivityDateFormatField($form);
}

/**
* Checks if this shook should run.
*
* @param string $formName
* Form Name.
*
* @return bool
* True if the hook should run.
*/
public function shouldRun($formName) {
return $formName == CRM_Admin_Form_Setting_Date::class;
}

/**
* Saves The Activity DateFormat field.
*
* @param CRM_Core_Form $form
* Form Class object.
*/
public function saveCaseActivityDateFormatField(CRM_Core_Form &$form) {
$values = $form->getVar('_submitValues');
if (!empty($values['_qf_civiCaseActivityDateformat'])) {
Civi::settings()->set('civiCaseActivityDateformat', $values['_qf_civiCaseActivityDateformat']);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</civicase-tooltip>
</div>
<!-- End - top section -->
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}"><i class="material-icons">event</i>{{formatDate(activity.activity_date_time, 'DD MMM YYYY') }}</span>
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}"><i class="material-icons">event</i>{{activity.formatted_activity_date_time}}</span>
<!-- Subject -->
<div class="civicase__activity-subject">{{ activity.subject }}</div>
<!-- End - Subject -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
class="civicase__activity-date"
ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">
<span class="civicase__activity-date__with-year">
{{formatDate(activity.activity_date_time, 'DD MMM YYYY')}}
{{activity.formatted_activity_date_time}}
</span>
<span
class="civicase__activity-date__without-year"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<span ng-if="activity.icon || activity.category.indexOf('milestone') > -1" activity-icon="activity"></span>

<!-- Activity Date -->
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">{{ formatDate(activity.activity_date_time, 'DD MMM YYYY') }}</span>
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">{{activity.formatted_activity_date_time}}</span>
<!-- End - Activity Date -->

<span class="civicase__activity__right-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3 class="panel-subtitle clearfix">
<span
class="civicase__activity-date"
ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">
{{formatDate(activity.activity_date_time, 'DD MMM YYYY')}}
{{activity.formatted_activity_date_time}}
</span>
<!-- End - Activity Date -->

Expand Down
13 changes: 11 additions & 2 deletions ang/civicase/shared/directives/file-uploader.directive.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ <h3>{{ts('Drop file here')}}</h3>
<input type="text" class="form-control" id="uploadSubject" required placeholder="" ng-model="activity.subject"/>
</div>
<div class="row">
<div class="form-group col-md-4 civicase__ui-range">
<div class="form-group col-md-4 civicase__ui-range date_range">
<div><label for="receivedDate">{{ts('Received Date')}}</label></div>
<input id="receivedDate" class="form-control" crm-ui-datepicker="{time: false}" ng-model="activity.activity_date_time" placeholder=""/>
<input id="receivedDate" class="form-control" crm-ui-datepicker="{time: true}" ng-model="activity.activity_date_time" placeholder=""/>
</div>
</div>
<div class="row">
Expand Down Expand Up @@ -66,3 +66,12 @@ <h4 class="civicase__file-upload-name col-md-8" ng-bind="item.file.name"></h4>
</div>
</fieldset>
</form>

<style>
.date_range > .crm-form-date-wrapper {
display: flex !important;
}
.date_range.civicase__ui-range .crm-form-date {
width: 100% !important;
}
</style>
3 changes: 2 additions & 1 deletion ang/civicase/shared/directives/file-uploader.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
$scope.activity = {
case_id: $scope.ctx.id,
activity_type_id: 'File Upload',
subject: ''
subject: '',
activity_date_time: moment().format('YYYY-MM-DD HH:MM:SS')
};
}

Expand Down
4 changes: 4 additions & 0 deletions api/v3/Activity/Getall.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ function civicrm_api3_activity_getall(array $params) {
if (!empty($activityIdsToFetchContactsFor[$row['id']])) {
$row = array_merge($activityIdsToFetchContactsFor[$row['id']], $row);
}

if (!empty($row['activity_date_time'])) {
$row['formatted_activity_date_time'] = CRM_Utils_Date::customFormat($row['activity_date_time'], Civi::settings()->get('civiCaseActivityDateformat') ?? '%d %b %Y');
}
}

return $result;
Expand Down
3 changes: 3 additions & 0 deletions civicase.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ function civicase_civicrm_buildForm($formName, &$form) {
new CRM_Civicase_Hook_BuildForm_AddEntityReferenceToCustomField(),
new CRM_Civicase_Hook_BuildForm_AttachQuotationToInvoiceMail(),
new CRM_Civicase_Hook_BuildForm_RefreshInvoiceListOnUpdate(),
new CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings(),
new CRM_Civicase_Hook_BuildForm_FormatCaseActivityDateFormat(),
];

foreach ($hooks as $hook) {
Expand Down Expand Up @@ -304,6 +306,7 @@ function civicase_civicrm_postProcess($formName, &$form) {
new CRM_Civicase_Hook_PostProcess_SaveCaseCategoryCustomFields(),
new CRM_Civicase_Hook_PostProcess_SaveCaseCategoryFeature(),
new CRM_Civicase_Hook_PostProcess_SaveQuotationsNotesSettings(),
new CRM_Civicase_Hook_PostProcess_SaveCaseActivityDateFormat(),
];

foreach ($hooks as $hook) {
Expand Down
7 changes: 7 additions & 0 deletions js/modify-activity-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CRM.$(function ($) {
(function () {
const date = CRM.vars.civicase.formatted_date;

CRM.$('.crm-activity-form-block-activity_date_time > td.view-value').text(date);
})();
});
12 changes: 12 additions & 0 deletions templates/CRM/Civicase/Form/CaseActivityDateFormat.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table class="form-layout-compressed">
<tr class="crm-date-form-block-_qf_civiCaseActivityDateformat">
<td class="label">{$form._qf_civiCaseActivityDateformat.label}</td>
<td>{$form._qf_civiCaseActivityDateformat.html}</td>
</tr>
</table>

{literal}
<script>
CRM.$('.crm-date-form-block-dateformatTime').last().after(CRM.$('.crm-date-form-block-_qf_civiCaseActivityDateformat'))
</script>
{/literal}
Loading