forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Refactor angular modules to use settingsFactory instead of settings #991
Open
agileware-fj
wants to merge
1
commit into
compucorp:master
Choose a base branch
from
agileware:ang-settings-factory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
<?php | ||
|
||
/** | ||
* Option factory class for Civicase AngularJS module | ||
*/ | ||
class CRM_Civicase_Angular { | ||
|
||
private static $options = []; | ||
private static $case_category_permissions; | ||
|
||
/** | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public static function getOptions(): array { | ||
self::load_resources(); | ||
[ | ||
$caseCategoryId, | ||
$caseCategoryName, | ||
] = CRM_Civicase_Helper_CaseUrl::getCategoryParamsFromUrl(); | ||
|
||
// Word replacements are already loaded for the contact tab ContactCaseTab. | ||
if (CRM_Utils_System::currentPath() !== 'civicrm/case/contact-case-tab') { | ||
$notTranslationPath = $caseCategoryName == CRM_Civicase_Helper_CaseCategory::CASE_TYPE_CATEGORY_NAME && CRM_Utils_System::currentPath() != 'civicrm/case/a'; | ||
|
||
if (!$notTranslationPath) { | ||
if (!in_array($caseCategoryName, CRM_Civicase_Helper_CaseCategory::getAccessibleCaseTypeCategories())) { | ||
throw new Exception('Access denied! You are not authorized to access this page.'); | ||
} | ||
|
||
CRM_Civicase_Hook_Helper_CaseTypeCategory::addWordReplacements($caseCategoryName); | ||
} | ||
} | ||
|
||
$permissionService = new \CRM_Civicase_Service_CaseCategoryPermission(); | ||
self::$case_category_permissions = $permissionService->get($caseCategoryName); | ||
|
||
// The following changes are only relevant to the full-page app. | ||
if (CRM_Utils_System::currentPath() == 'civicrm/case/a') { | ||
self::adds_shoreditch_css(); | ||
\CRM_Civicase_Helper_CaseCategory::updateBreadcrumbs($caseCategoryId); | ||
} | ||
|
||
self::set_case_actions(); | ||
self::set_contact_tasks(); | ||
|
||
return self::$options; | ||
} | ||
|
||
/** | ||
* Loads Resources. | ||
*/ | ||
public static function load_resources() { | ||
Civi::resources() | ||
->addPermissions([ | ||
'administer CiviCase', | ||
'administer CiviCRM', | ||
'access all cases and activities', | ||
'add cases', | ||
'basic case information', | ||
'access CiviCRM', | ||
'access my cases and activities', | ||
]) | ||
->addScriptFile('org.civicrm.shoreditch', 'base/js/affix.js', 1000, 'html-header') | ||
->addSetting([ | ||
'config' => [ | ||
'enableComponents' => CRM_Core_Config::singleton()->enableComponents, | ||
'user_contact_id' => (int) CRM_Core_Session::getLoggedInContactID(), | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* Add shoreditch custom css if not already present. | ||
*/ | ||
public static function adds_shoreditch_css() { | ||
if (!civicrm_api3('Setting', 'getvalue', ['name' => "customCSSURL"])) { | ||
Civi::resources() | ||
->addStyleFile('org.civicrm.shoreditch', 'css/custom-civicrm.css', 99, 'html-header'); | ||
} | ||
} | ||
|
||
/** | ||
* Get a list of JS files. | ||
*/ | ||
public static function get_js_files() { | ||
return array_merge( | ||
[ | ||
// At the moment, it's safe to include this multiple times. | ||
// deduped by resource manager. | ||
'assetBuilder://visual-bundle.js', | ||
'ang/civicase.js', | ||
], | ||
CRM_Civicase_Helper_GlobRecursive::getRelativeToExtension( | ||
'uk.co.compucorp.civicase', | ||
'ang/civicase/*.js' | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Bulk actions for case list. | ||
* | ||
* We put this here so it can be modified by other extensions. | ||
*/ | ||
public static function set_case_actions() { | ||
self::$options['caseActions'] = [ | ||
[ | ||
'title' => ts('Change Case Status'), | ||
'action' => 'ChangeStatus', | ||
'icon' => 'fa-pencil-square-o', | ||
'is_write_action' => TRUE, | ||
], | ||
[ | ||
'title' => ts('Edit Tags'), | ||
'action' => 'EditTags', | ||
'icon' => 'fa-tags', | ||
'number' => 1, | ||
'is_write_action' => TRUE, | ||
], | ||
[ | ||
'title' => ts('Print Case'), | ||
'action' => 'Print', | ||
'number' => 1, | ||
'icon' => 'fa-print', | ||
'is_write_action' => FALSE, | ||
], | ||
[ | ||
'title' => ts('Email - send now'), | ||
'action' => 'Email', | ||
'icon' => 'fa-envelope-o', | ||
'is_write_action' => TRUE, | ||
], | ||
[ | ||
'title' => ts('Print/Merge Document'), | ||
'action' => 'PrintMerge', | ||
'icon' => 'fa-file-pdf-o', | ||
'is_write_action' => TRUE, | ||
], | ||
[ | ||
'title' => ts('Link Cases'), | ||
'action' => 'LinkCases', | ||
'number' => 1, | ||
'icon' => 'fa-link', | ||
'is_write_action' => TRUE, | ||
], | ||
[ | ||
'title' => ts('Link 2 Cases'), | ||
'action' => 'LinkCases', | ||
'number' => 2, | ||
'icon' => 'fa-link', | ||
'is_write_action' => TRUE, | ||
], | ||
]; | ||
if (CRM_Core_Permission::check('administer CiviCase')) { | ||
self::$options['caseActions'][] = [ | ||
'title' => ts('Merge 2 Cases'), | ||
'number' => 2, | ||
'action' => 'MergeCases', | ||
'icon' => 'fa-compress', | ||
'is_write_action' => TRUE, | ||
]; | ||
self::$options['caseActions'][] = [ | ||
'title' => ts('Lock Case'), | ||
'action' => 'LockCases', | ||
'number' => 1, | ||
'icon' => 'fa-lock', | ||
'is_write_action' => TRUE, | ||
]; | ||
} | ||
if (CRM_Core_Permission::check(self::$case_category_permissions['DELETE_IN_CASE_CATEGORY']['name'])) { | ||
self::$options['caseActions'][] = [ | ||
'title' => ts('Delete Case'), | ||
'action' => 'DeleteCases', | ||
'icon' => 'fa-trash', | ||
'is_write_action' => TRUE, | ||
]; | ||
} | ||
if (CRM_Core_Permission::check(CRM_Civicase_Hook_Permissions_ExportCasesAndReports::PERMISSION_NAME)) { | ||
self::$options['caseActions'][] = [ | ||
'title' => ts('Export Cases'), | ||
'action' => 'ExportCases', | ||
'icon' => 'fa-file-excel-o', | ||
'is_write_action' => FALSE, | ||
]; | ||
} | ||
|
||
self::add_webforms_case_action(); | ||
} | ||
|
||
/** | ||
* Add webforms with cases attached to menu. | ||
*/ | ||
public static function add_webforms_case_action() { | ||
$items = []; | ||
|
||
$webformsToDisplay = Civi::settings()->get('civi_drupal_webforms'); | ||
if (isset($webformsToDisplay)) { | ||
$allowedWebforms = []; | ||
foreach ($webformsToDisplay as $webformNode) { | ||
$allowedWebforms[] = $webformNode['nid']; | ||
} | ||
$webforms = civicrm_api3('Case', 'getwebforms'); | ||
if (isset($webforms['values'])) { | ||
foreach ($webforms['values'] as $webform) { | ||
if (!in_array($webform['nid'], $allowedWebforms)) { | ||
continue; | ||
} | ||
|
||
$items[] = [ | ||
'title' => $webform['title'], | ||
'action' => 'GoToWebform', | ||
'path' => $webform['path'], | ||
'case_type_ids' => $webform['case_type_ids'], | ||
'clientID' => NULL, | ||
'is_write_action' => FALSE, | ||
]; | ||
} | ||
self::$options['caseActions'][] = [ | ||
'title' => ts('Forms'), | ||
'action' => 'Forms', | ||
'icon' => 'fa-file-text-o', | ||
'items' => $items, | ||
'is_write_action' => FALSE, | ||
]; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Sets contact tasks. | ||
*/ | ||
public static function set_contact_tasks() { | ||
$contactTasks = CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()); | ||
self::$options['contactTasks'] = []; | ||
foreach (CRM_Contact_Task::$_tasks as $id => $value) { | ||
if (isset($contactTasks[$id]) && isset($value['url'])) { | ||
self::$options['contactTasks'][$id] = $value; | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agileware-fj Putting this on one line fixed all the civilint errors for me (same error in another file, I'll comment there too).