Skip to content

Commit

Permalink
Use settingsFactory intead of settings for angular modules.
Browse files Browse the repository at this point in the history
We are moving toward the use of settingsFactory and away from settings for angular modules.
This would allow the list of modules to be cached as it would only contain static metadata.
  • Loading branch information
colemanw committed Nov 25, 2020
1 parent 309de23 commit d56e4a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CRM/Core/Page/AJAX/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ public static function sendResponse($result) {
CRM_Utils_JSON::output(array_merge($result));
}

/**
* @return array
*/
public static function angularSettings() {
return [
'token' => self::createToken(),
];
}

/**
* @return string
*/
Expand Down
4 changes: 1 addition & 3 deletions ang/crmAttachment.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
'js' => ['ang/crmAttachment.js'],
'css' => ['ang/crmAttachment.css'],
'partials' => ['ang/crmAttachment'],
'settings' => [
'token' => \CRM_Core_Page_AJAX_Attachment::createToken(),
],
'settingsFactory' => ['CRM_Core_Page_AJAX_Attachment', 'angularSettings'],
'requires' => ['angularFileUpload', 'crmResource'],
];
1 change: 0 additions & 1 deletion ang/crmStatusPage.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
'js' => ['ang/crmStatusPage.js', 'ang/crmStatusPage/*.js'],
'css' => ['ang/crmStatusPage.css'],
'partials' => ['ang/crmStatusPage'],
'settings' => [],
'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'crmResource'],
];
1 change: 0 additions & 1 deletion ang/exportui.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
'ui.sortable',
'dialogService',
],
'settings' => [],
];
8 changes: 7 additions & 1 deletion tests/phpunit/Civi/Angular/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testGetModules() {
'css' => 0,
'partials' => 0,
'settings' => 0,
'settingsFactory' => 0,
];

foreach ($modules as $module) {
Expand Down Expand Up @@ -80,12 +81,17 @@ public function testGetModules() {
$counts['settings']++;
}
}
if (isset($module['settingsFactory'])) {
$this->assertTrue(is_callable($module['settingsFactory']));
$counts['settingsFactory']++;
}
}

$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'] > 0, 'Expect to find at least one setting');
$this->assertTrue($counts['settingsFactory'] > 0, 'Expect to find at least one settingsFactory');
$this->assertEquals(0, $counts['settings'], 'Angular settings are deprecated in favor of settingsFactory');
}

/**
Expand Down

0 comments on commit d56e4a9

Please sign in to comment.