From 1da632e0cdb873a6fcb20bbbe6455b0a5a30c625 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 9 Apr 2015 17:19:09 -0700 Subject: [PATCH] CRM-16253 - Angular - Declare settings in $angularModules. Add setting for callback URL. --- Civi/Angular/Manager.php | 22 ++++++++++++++++++++-- Civi/Angular/Page/Main.php | 7 ++----- tests/phpunit/Civi/Angular/ManagerTest.php | 8 ++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Civi/Angular/Manager.php b/Civi/Angular/Manager.php index 6effe4ce1c..b3ac3d60c4 100644 --- a/Civi/Angular/Manager.php +++ b/Civi/Angular/Manager.php @@ -25,6 +25,8 @@ class Manager { * - partials: array(string $relativeFilePath) * A list of partial-HTML folders (relative to the extension). * This will be mapped to "~/moduleName" by crmResource. + * - settings: array(string $key => mixed $value) + * List of settings to preload. */ protected $modules = NULL; @@ -50,9 +52,12 @@ class Manager { * - partials: array(string $relativeFilePath) * A list of partial-HTML folders (relative to the extension). * This will be mapped to "~/moduleName" by crmResource. + * - settings: array(string $key => mixed $value) + * List of settings to preload. */ public function getModules() { if ($this->modules === NULL) { + $config = \CRM_Core_Config::singleton(); $angularModules = array(); $angularModules['angularFileUpload'] = array( @@ -68,6 +73,9 @@ class Manager { 'js' => array('ang/crmAttachment.js'), 'css' => array('ang/crmAttachment.css'), 'partials' => array('ang/crmAttachment'), + 'settings' => array( + 'token' => \CRM_Core_Page_AJAX_Attachment::createToken(), + ), ); $angularModules['crmAutosave'] = array( 'ext' => 'civicrm', @@ -87,6 +95,10 @@ class Manager { 'ext' => 'civicrm', 'js' => array('ang/crmUi.js'), 'partials' => array('ang/crmUi'), + 'settings' => array( + 'browseUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/browse.php', + 'uploadUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/upload.php', + ), ); $angularModules['crmUtil'] = array( 'ext' => 'civicrm', @@ -264,9 +276,9 @@ class Manager { * @param string|array $moduleNames * List of module names. * @param string $resType - * Type of resource ('js', 'css'). + * Type of resource ('js', 'css', 'settings'). * @param string $refType - * Type of reference to the resource ('cacheUrl', 'rawUrl', 'path'). + * Type of reference to the resource ('cacheUrl', 'rawUrl', 'path', 'settings'). * @return array * List of URLs or paths. * @throws \CRM_Core_Exception @@ -291,6 +303,12 @@ class Manager { $result[] = $this->res->getUrl($module['ext'], $file, TRUE); break; + case 'settings': + if (!empty($module[$resType])) { + $result[$moduleName] = $module[$resType]; + } + break; + default: throw new \CRM_Core_Exception("Unrecognized resource format"); } diff --git a/Civi/Angular/Page/Main.php b/Civi/Angular/Page/Main.php index e52f0a1dd3..feff8c441a 100644 --- a/Civi/Angular/Page/Main.php +++ b/Civi/Angular/Page/Main.php @@ -68,16 +68,13 @@ class Main extends \CRM_Core_Page { $this->res->addSettingsFactory(function () use (&$modules, $page) { // TODO optimization; client-side caching - return array( + return array_merge($page->angular->getResources(array_keys($modules), 'settings', 'settings'), array( 'resourceUrls' => \CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array( 'modules' => array_merge(array('ngRoute'), array_keys($modules)), 'cacheCode' => $page->res->getCacheCode(), ), - 'crmAttachment' => array( - 'token' => \CRM_Core_Page_AJAX_Attachment::createToken(), - ), - ); + )); }); $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); diff --git a/tests/phpunit/Civi/Angular/ManagerTest.php b/tests/phpunit/Civi/Angular/ManagerTest.php index aac9ac7ec4..9b21851cca 100644 --- a/tests/phpunit/Civi/Angular/ManagerTest.php +++ b/tests/phpunit/Civi/Angular/ManagerTest.php @@ -65,6 +65,7 @@ class ManagerTest extends \CiviUnitTestCase { 'js' => 0, 'css' => 0, 'partials' => 0, + 'settings' => 0, ); foreach ($modules as $module) { @@ -91,11 +92,18 @@ class ManagerTest extends \CiviUnitTestCase { $counts['partials']++; } } + if (isset($module['settings'])) { + $this->assertTrue(is_array($module['settings'])); + foreach ($module['settings'] as $name => $value) { + $counts['settings']++; + } + } } $this->assertTrue($counts['js'] > 0, 'Expect to find at least one JS file'); $this->assertTrue($counts['css'] > 0, 'Expect to find at least one CSS file'); $this->assertTrue($counts['partials'] > 0, 'Expect to find at least one partial HTML file'); + $this->assertTrue($counts['settings'] > 1, 'Expect to find at least one setting'); } /** -- 2.25.1