diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 98ba66b06..b989b4fea 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -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: diff --git a/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php b/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php new file mode 100644 index 000000000..624525ef6 --- /dev/null +++ b/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php @@ -0,0 +1,63 @@ +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", + ]); + } + +} diff --git a/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php b/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php new file mode 100644 index 000000000..67d34750d --- /dev/null +++ b/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php @@ -0,0 +1,48 @@ +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; + } + +} diff --git a/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php b/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php new file mode 100644 index 000000000..0886112f6 --- /dev/null +++ b/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php @@ -0,0 +1,50 @@ +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']); + } + } + +} diff --git a/ang/civicase/activity/card/directives/activity-card-big.directive.html b/ang/civicase/activity/card/directives/activity-card-big.directive.html index 8225ce65d..2e948e309 100644 --- a/ang/civicase/activity/card/directives/activity-card-big.directive.html +++ b/ang/civicase/activity/card/directives/activity-card-big.directive.html @@ -74,7 +74,7 @@ - event{{formatDate(activity.activity_date_time, 'DD MMM YYYY') }} + event{{activity.formatted_activity_date_time}}
{{ activity.subject }}
diff --git a/ang/civicase/activity/card/directives/activity-card-long.directive.html b/ang/civicase/activity/card/directives/activity-card-long.directive.html index 0675d5ca0..a4490d4cc 100644 --- a/ang/civicase/activity/card/directives/activity-card-long.directive.html +++ b/ang/civicase/activity/card/directives/activity-card-long.directive.html @@ -84,7 +84,7 @@ 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}} - {{ formatDate(activity.activity_date_time, 'DD MMM YYYY') }} + {{activity.formatted_activity_date_time}} diff --git a/ang/civicase/activity/panel/directives/activity-panel.directive.html b/ang/civicase/activity/panel/directives/activity-panel.directive.html index 107af169f..147c4d335 100644 --- a/ang/civicase/activity/panel/directives/activity-panel.directive.html +++ b/ang/civicase/activity/panel/directives/activity-panel.directive.html @@ -96,7 +96,7 @@

- {{formatDate(activity.activity_date_time, 'DD MMM YYYY')}} + {{activity.formatted_activity_date_time}} diff --git a/ang/civicase/shared/directives/file-uploader.directive.html b/ang/civicase/shared/directives/file-uploader.directive.html index 408c69d87..18e678961 100644 --- a/ang/civicase/shared/directives/file-uploader.directive.html +++ b/ang/civicase/shared/directives/file-uploader.directive.html @@ -20,9 +20,9 @@

{{ts('Drop file here')}}

-
+
- +
@@ -66,3 +66,12 @@

+ + diff --git a/ang/civicase/shared/directives/file-uploader.directive.js b/ang/civicase/shared/directives/file-uploader.directive.js index b9fdc98b3..28d156df0 100644 --- a/ang/civicase/shared/directives/file-uploader.directive.js +++ b/ang/civicase/shared/directives/file-uploader.directive.js @@ -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') }; } diff --git a/api/v3/Activity/Getall.php b/api/v3/Activity/Getall.php index 4caf5594a..25c5c347f 100644 --- a/api/v3/Activity/Getall.php +++ b/api/v3/Activity/Getall.php @@ -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; diff --git a/civicase.php b/civicase.php index 44e527c15..0a6784f89 100644 --- a/civicase.php +++ b/civicase.php @@ -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) { @@ -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) { diff --git a/js/modify-activity-date.js b/js/modify-activity-date.js new file mode 100644 index 000000000..86f5cd8fb --- /dev/null +++ b/js/modify-activity-date.js @@ -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); + })(); +}); diff --git a/templates/CRM/Civicase/Form/CaseActivityDateFormat.tpl b/templates/CRM/Civicase/Form/CaseActivityDateFormat.tpl new file mode 100644 index 000000000..e0da9c454 --- /dev/null +++ b/templates/CRM/Civicase/Form/CaseActivityDateFormat.tpl @@ -0,0 +1,12 @@ + + + + + +
{$form._qf_civiCaseActivityDateformat.label}{$form._qf_civiCaseActivityDateformat.html}
+ +{literal} + +{/literal}