X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPage%2FAngular.php;h=59c4dc81cefd6e7247cc8d42c03de3a7aa1e3409;hb=ad7abea28f5ba077971be9e8e4b40b1caada2a35;hp=c11188e82f86dfaa0a058a8f8853dd7938c7af86;hpb=7bf1cc022db08708fa0de88e88200905abd0f9d8;p=civicrm-core.git diff --git a/CRM/Core/Page/Angular.php b/CRM/Core/Page/Angular.php index c11188e82f..59c4dc81ce 100644 --- a/CRM/Core/Page/Angular.php +++ b/CRM/Core/Page/Angular.php @@ -12,30 +12,57 @@ class CRM_Core_Page_Angular extends CRM_Core_Page { */ const DEFAULT_MODULE_WEIGHT = 200; + /** + * @var CRM_Core_Resources + */ + protected $res; + + + /** + * @var Civi\Angular\Manager + */ + protected $angular; + + /** + * @param string $title + * Title of the page. + * @param int $mode + * Mode of the page. + * @param CRM_Core_Resources|null $res + * Resource manager. + */ + public function __construct($title = NULL, $mode = NULL, $res = NULL) { + parent::__construct($title, $mode); + $this->res = CRM_Core_Resources::singleton(); + $this->angular = Civi\Core\Container::singleton()->get('angular'); + } + /** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * - * @return string The content generated by running this page + * @return string + * The content generated by running this page */ public function run() { - $this->registerResources(CRM_Core_Resources::singleton()); + $this->registerResources(); return parent::run(); } /** - * @param CRM_Core_Resources $res + * Register resources required by Angular. */ - public function registerResources(CRM_Core_Resources $res) { - $modules = self::getAngularModules(); + public function registerResources() { + $modules = $this->angular->getModules(); - $res->addSettingsFactory(function () use (&$modules) { + $this->res->addSettingsFactory(function () use (&$modules) { // TODO optimization; client-side caching return array( 'resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array( 'modules' => array_merge(array('ngRoute'), array_keys($modules)), + 'cacheCode' => $this->res->getCacheCode(), ), 'crmAttachment' => array( 'token' => CRM_Core_Page_AJAX_Attachment::createToken(), @@ -43,47 +70,18 @@ class CRM_Core_Page_Angular extends CRM_Core_Page { ); }); - $res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); - $res->addScriptFile('civicrm', 'bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE); + $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); + $this->res->addScriptFile('civicrm', 'bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE); $headOffset = 0; - foreach ($modules as $module) { - if (!empty($module['css'])) { - foreach ($module['css'] as $file) { - $res->addStyleFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); - } + foreach ($modules as $moduleName => $module) { + foreach ($this->angular->getStyleUrls($moduleName) as $url) { + $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header'); } - if (!empty($module['js'])) { - foreach ($module['js'] as $file) { - $res->addScriptFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header', TRUE); - } + foreach ($this->angular->getScriptUrls($moduleName) as $url) { + $this->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + (++$headOffset), 'html-header'); + // addScriptUrl() bypasses the normal string-localization of addScriptFile(), + // but that's OK because all Angular strings (JS+HTML) will load via crmResource. } } } - - /** - * Get a list of AngularJS modules which should be autoloaded - * - * @return array (string $name => array('ext' => string $key, 'js' => array $paths, 'css' => array $paths)) - */ - public static function getAngularModules() { - $angularModules = array(); - $angularModules['angularFileUpload'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-file-upload/angular-file-upload.min.js')); - $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmApp.js')); - $angularModules['crmAttachment'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmAttachment.js'), 'css' => array('css/angular-crmAttachment.css')); - $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-ui.js', 'packages/ckeditor/ckeditor.js')); - $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('js/angular-crm-util.js')); - // https://github.com/jwstadler/angular-jquery-dialog-service - $angularModules['dialogService'] = array('ext' => 'civicrm' , 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js')); - $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('js/angular-sanitize.js')); - $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js')); - $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-sortable/sortable.min.js')); - $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js')); - - foreach (CRM_Core_Component::getEnabledComponents() as $component) { - $angularModules = array_merge($angularModules, $component->getAngularModules()); - } - CRM_Utils_Hook::angularModules($angularModules); - return $angularModules; - } - }