From b1510da43317f8c5edfa3285f910320db9b167e1 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 27 Mar 2021 12:15:50 -0400 Subject: [PATCH] AngularLoader - use new service to run angular modules --- CRM/Api4/Page/Api4Explorer.php | 11 ++++------- CRM/Contact/Page/DashBoard.php | 9 +++------ CRM/Export/Form/Map.php | 7 +++---- Civi/Angular/AngularLoader.php | 4 ++++ ang/crmDashboard.ang.php | 2 +- ext/afform/admin/CRM/AfformAdmin/Page/Base.php | 5 ++--- ext/search/CRM/Search/Page/Admin.php | 9 +++------ ext/search/CRM/Search/Page/Search.php | 8 +------- templates/CRM/Export/Form/Map.tpl | 4 ++-- 9 files changed, 23 insertions(+), 36 deletions(-) diff --git a/CRM/Api4/Page/Api4Explorer.php b/CRM/Api4/Page/Api4Explorer.php index d78ef91ddc..655800bfe5 100644 --- a/CRM/Api4/Page/Api4Explorer.php +++ b/CRM/Api4/Page/Api4Explorer.php @@ -48,13 +48,10 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page { ->addScriptFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.js') ->addStyleFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.css'); - $loader = new Civi\Angular\AngularLoader(); - $loader->setModules(['api4Explorer']); - $loader->setPageName('civicrm/api4'); - $loader->useApp([ - 'defaultRoute' => '/explorer', - ]); - $loader->load(); + Civi::service('angularjs.loader') + ->addModules('api4Explorer') + ->useApp(['defaultRoute' => '/explorer']); + parent::run(); } diff --git a/CRM/Contact/Page/DashBoard.php b/CRM/Contact/Page/DashBoard.php index 55d48127df..48ea3ac19c 100644 --- a/CRM/Contact/Page/DashBoard.php +++ b/CRM/Contact/Page/DashBoard.php @@ -44,24 +44,21 @@ class CRM_Contact_Page_DashBoard extends CRM_Core_Page { } } - $loader = new Civi\Angular\AngularLoader(); + $loader = Civi::service('angularjs.loader'); + $loader->addModules('crmDashboard'); $loader->setPageName('civicrm/dashboard'); // For each dashlet that requires an angular directive, load the angular module which provides that directive - $modules = []; foreach (CRM_Core_BAO_Dashboard::getContactDashlets() as $dashlet) { if (!empty($dashlet['directive'])) { foreach ($loader->getAngular()->getModules() as $name => $module) { if (!empty($module['exports'][$dashlet['directive']])) { - $modules[] = $name; + $loader->addModules($name); continue; } } } } - $loader->setModules($modules); - - $loader->load(); return parent::run(); } diff --git a/CRM/Export/Form/Map.php b/CRM/Export/Form/Map.php index 9e4e5fbaf1..4bbc28bbc5 100644 --- a/CRM/Export/Form/Map.php +++ b/CRM/Export/Form/Map.php @@ -69,10 +69,9 @@ class CRM_Export_Form_Map extends CRM_Core_Form { ], ]); - // Bootstrap angular and load exportui app - $loader = new Civi\Angular\AngularLoader(); - $loader->setModules(['exportui']); - $loader->load(); + // Add exportui app + Civi::service('angularjs.loader') + ->addModules('exportui'); } public function buildQuickForm() { diff --git a/Civi/Angular/AngularLoader.php b/Civi/Angular/AngularLoader.php index d446fec947..6ddd90ed09 100644 --- a/Civi/Angular/AngularLoader.php +++ b/Civi/Angular/AngularLoader.php @@ -338,6 +338,10 @@ class AngularLoader { } /** + * Replace all previously set modules. + * + * Use with caution, as it can cause conflicts with other extensions who have added modules. + * * @param array $modules * @return AngularLoader */ diff --git a/ang/crmDashboard.ang.php b/ang/crmDashboard.ang.php index 65f312a7e2..ea27d015c4 100644 --- a/ang/crmDashboard.ang.php +++ b/ang/crmDashboard.ang.php @@ -10,7 +10,7 @@ return [ 'css' => ['css/dashboard.css'], 'partials' => ['ang/crmDashboard'], 'partialsCallback' => ['CRM_Contact_Page_DashBoard', 'angularPartials'], - 'basePages' => ['civicrm/dashboard'], + 'basePages' => [], 'requires' => ['crmUi', 'crmUtil', 'ui.sortable', 'dialogService', 'api4'], 'settingsFactory' => ['CRM_Contact_Page_DashBoard', 'angularSettings'], 'permissions' => ['administer CiviCRM'], diff --git a/ext/afform/admin/CRM/AfformAdmin/Page/Base.php b/ext/afform/admin/CRM/AfformAdmin/Page/Base.php index b01400badb..d9395e9a97 100644 --- a/ext/afform/admin/CRM/AfformAdmin/Page/Base.php +++ b/ext/afform/admin/CRM/AfformAdmin/Page/Base.php @@ -23,10 +23,9 @@ class CRM_AfformAdmin_Page_Base extends CRM_Core_Page { CRM_Utils_System::appendBreadCrumb([$breadCrumb]); // Load angular module - $loader = new Civi\Angular\AngularLoader(); - $loader->setPageName('civicrm/admin/afform'); + $loader = Civi::service('angularjs.loader'); $loader->useApp(); - $loader->load(); + parent::run(); } diff --git a/ext/search/CRM/Search/Page/Admin.php b/ext/search/CRM/Search/Page/Admin.php index 0d6cc55fad..315a0efc96 100644 --- a/ext/search/CRM/Search/Page/Admin.php +++ b/ext/search/CRM/Search/Page/Admin.php @@ -24,12 +24,9 @@ class CRM_Search_Page_Admin extends CRM_Core_Page { CRM_Utils_System::appendBreadCrumb([$breadCrumb]); // Load angular module - $loader = new Civi\Angular\AngularLoader(); - $loader->setPageName('civicrm/admin/search'); - $loader->useApp([ - 'defaultRoute' => '/list', - ]); - $loader->load(); + Civi::service('angularjs.loader') + ->useApp(['defaultRoute' => '/list']); + parent::run(); } diff --git a/ext/search/CRM/Search/Page/Search.php b/ext/search/CRM/Search/Page/Search.php index ffd4ce40cd..d73e1b274f 100644 --- a/ext/search/CRM/Search/Page/Search.php +++ b/ext/search/CRM/Search/Page/Search.php @@ -18,13 +18,7 @@ class CRM_Search_Page_Search extends CRM_Core_Page { public function run() { - Civi::resources()->addBundle('bootstrap3'); - - // Load angular module - $loader = new Civi\Angular\AngularLoader(); - $loader->setPageName('civicrm/search'); - $loader->useApp(); - $loader->load(); + Civi::service('angularjs.loader')->useApp(); if (CRM_Core_Permission::check('administer CiviCRM')) { CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Search Kit'), 'url' => CRM_Utils_System::url('civicrm/admin/search')]]); diff --git a/templates/CRM/Export/Form/Map.tpl b/templates/CRM/Export/Form/Map.tpl index dda47d32d2..24eb7a9816 100644 --- a/templates/CRM/Export/Form/Map.tpl +++ b/templates/CRM/Export/Form/Map.tpl @@ -22,9 +22,9 @@ {include file="CRM/common/WizardHeader.tpl"}
{include file="CRM/common/formButtons.tpl" location="top"}
-
+
-
+
{include file="CRM/common/formButtons.tpl" location="bottom"}
{$initHideBoxes} -- 2.25.1