From e5afbdad0ba74feb0570783c7dd8829404c3b515 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jan 2015 22:29:34 -0800 Subject: [PATCH] CRM-15832 - Angular - Add page which aggregates partials+strings --- CRM/Core/Page/AJAX.php | 15 +++++++---- CRM/Core/xml/Menu/Misc.xml | 5 ++++ Civi/Angular/Page/Modules.php | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 Civi/Angular/Page/Modules.php diff --git a/CRM/Core/Page/AJAX.php b/CRM/Core/Page/AJAX.php index af7ae6613a..dabebbb846 100644 --- a/CRM/Core/Page/AJAX.php +++ b/CRM/Core/Page/AJAX.php @@ -200,13 +200,18 @@ class CRM_Core_Page_AJAX { /** * Set headers appropriate for a js file + * + * @param int|NULL $ttl + * Time-to-live (seconds). */ - public static function setJsHeaders() { - // Encourage browsers to cache for a long time - 1 year - $year = 60 * 60 * 24 * 364; - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $year)); + public static function setJsHeaders($ttl = NULL) { + if ($ttl === NULL) { + // Encourage browsers to cache for a long time - 1 year + $ttl = 60 * 60 * 24 * 364; + } + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl)); header('Content-Type: application/javascript'); - header("Cache-Control: max-age=$year, public"); + header("Cache-Control: max-age=$ttl, public"); } /** diff --git a/CRM/Core/xml/Menu/Misc.xml b/CRM/Core/xml/Menu/Misc.xml index 0dc981bfa3..98f96c99b8 100644 --- a/CRM/Core/xml/Menu/Misc.xml +++ b/CRM/Core/xml/Menu/Misc.xml @@ -180,6 +180,11 @@ CRM_Core_Page_Angular access CiviCRM + + civicrm/ajax/angular-modules + \Civi\Angular\Page\Modules + access CiviCRM + civicrm/ajax/recurringentity/update-mode CRM_Core_Page_AJAX_RecurringEntity::updateMode diff --git a/Civi/Angular/Page/Modules.php b/Civi/Angular/Page/Modules.php new file mode 100644 index 0000000000..5f517e5a8b --- /dev/null +++ b/Civi/Angular/Page/Modules.php @@ -0,0 +1,50 @@ +debug ? 30 : NULL); + \CRM_Core_Page_AJAX::setJsHeaders(); + + /** + * @var \Civi\Angular\Manager $angular + */ + $angular = \Civi\Core\Container::singleton()->get('angular'); + $modules = $angular->getModules(); + + $modulesExpr = \CRM_Utils_Request::retrieve('modules', 'String'); + if ($modulesExpr) { + $moduleNames = preg_grep( + '/^[a-zA-Z0-9\-_\.]+$/', + explode(',', $modulesExpr) + ); + } + else { + $moduleNames = array_keys($modules); + } + + $result = array(); + foreach ($moduleNames as $moduleName) { + if (isset($modules[$moduleName])) { + $result[$moduleName] = array(); + $result[$moduleName]['js'] = $angular->getScriptUrls($moduleName); + $result[$moduleName]['css'] = $angular->getStyleUrls($moduleName); + $result[$moduleName]['partials'] = $angular->getPartials($moduleName); + $result[$moduleName]['strings'] = $angular->getTranslatedStrings($moduleName); + } + } + + echo json_encode($result); + \CRM_Utils_System::civiExit(); + } + +} -- 2.25.1