From 1d73ae195ec7ee871d5ca5f61624bc21b462e70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20J=2E=20G=C3=B3mez?= Date: Thu, 20 Dec 2018 17:11:36 -0500 Subject: [PATCH] Added resolve dependency to the parent dashboard state to make the organization contact information available to all states. - Added error page for invalid contact IDs. - Updated page title to include the name of the organization contact (note: for the crmPageTitle directive to work, the AngularJS base page cannot have a custom title -- it must be named "CiviCRM"; see https://github.com/civicrm/civicrm-core/pull/13337). - Updated file name for DashCtrl to match conventions. --- CRM/Orgdash/Page/Angular.php | 1 - ang/orgdash.js | 24 +++++++++++++++++++++++ ang/orgdash/controllers/Dash.js | 7 ------- ang/orgdash/controllers/DashCtrl.js | 8 ++++++++ ang/orgdash/controllers/OrgCtrl.js | 4 +--- ang/orgdash/partials/Dash.html | 2 +- ang/orgdash/partials/Org.html | 2 +- ang/orgdash/partials/OrgContactError.html | 8 ++++++++ 8 files changed, 43 insertions(+), 13 deletions(-) delete mode 100644 ang/orgdash/controllers/Dash.js create mode 100644 ang/orgdash/controllers/DashCtrl.js create mode 100644 ang/orgdash/partials/OrgContactError.html diff --git a/CRM/Orgdash/Page/Angular.php b/CRM/Orgdash/Page/Angular.php index d7c002e..94b8bef 100644 --- a/CRM/Orgdash/Page/Angular.php +++ b/CRM/Orgdash/Page/Angular.php @@ -4,7 +4,6 @@ class CRM_Orgdash_Page_Angular extends CRM_Core_Page { public function run() { - CRM_Utils_System::setTitle(E::ts('Organization Dashboard')); $this->exposeConfigurations(); // See https://docs.civicrm.org/dev/en/latest/framework/angular/loader/#other-base-pages. diff --git a/ang/orgdash.js b/ang/orgdash.js index f6f9e97..48e0b86 100644 --- a/ang/orgdash.js +++ b/ang/orgdash.js @@ -17,6 +17,27 @@ resolve: { orgId: function ($stateParams) { return $stateParams.id; + }, + orgContact: function (crmApi, orgId) { + const resultHandler = function (result) { + return result; + }; + + return crmApi('Contact', 'getsingle', { + id: orgId, + contact_type: 'Organization' + }) + // The same handler is used for successes and failures so that + // the state's onEnter callback (which has appropriate context + // to change states) can redirect to an error page if necessary. + // Otherwise, the rejected promise would result in a Transition + // Rejection and confusing UX. + .then(resultHandler, resultHandler); + } + }, + onEnter: function ($state, orgContact) { + if (orgContact.is_error === 1) { + return $state.target('org-contact-error'); } } }) @@ -63,7 +84,10 @@ }); } } + }) + .state('org-contact-error', { + templateUrl: '~/orgdash/partials/OrgContactError.html' }); }) diff --git a/ang/orgdash/controllers/Dash.js b/ang/orgdash/controllers/Dash.js deleted file mode 100644 index 19c2ae3..0000000 --- a/ang/orgdash/controllers/Dash.js +++ /dev/null @@ -1,7 +0,0 @@ -(function(angular, $, _) { - - angular.module('orgdash') - .controller('DashCtrl', function() { - }); - -})(angular, CRM.$, CRM._); diff --git a/ang/orgdash/controllers/DashCtrl.js b/ang/orgdash/controllers/DashCtrl.js new file mode 100644 index 0000000..b134c77 --- /dev/null +++ b/ang/orgdash/controllers/DashCtrl.js @@ -0,0 +1,8 @@ +(function(angular, $, _) { + + angular.module('orgdash') + .controller('DashCtrl', function($scope, orgContact) { + $scope.name = orgContact.display_name; + }); + +})(angular, CRM.$, CRM._); diff --git a/ang/orgdash/controllers/OrgCtrl.js b/ang/orgdash/controllers/OrgCtrl.js index a4cc29b..fce88be 100644 --- a/ang/orgdash/controllers/OrgCtrl.js +++ b/ang/orgdash/controllers/OrgCtrl.js @@ -3,9 +3,7 @@ angular.module('orgdash') .controller('OrgCtrl', function($scope, orgId) { $scope.profileId = CRM.vars.orgdash.orgdash_org_profile_id; - $scope.orgContact = { - id: orgId - }; + $scope.orgId = orgId; }); })(angular, CRM.$, CRM._); diff --git a/ang/orgdash/partials/Dash.html b/ang/orgdash/partials/Dash.html index 5150f0f..772c92d 100644 --- a/ang/orgdash/partials/Dash.html +++ b/ang/orgdash/partials/Dash.html @@ -1,4 +1,4 @@ -

TODO: Title this page

+

{{ts('Organization Dashboard for %1', {1: name})}}

diff --git a/ang/orgdash/partials/Org.html b/ang/orgdash/partials/Org.html index b1203e3..a373a41 100644 --- a/ang/orgdash/partials/Org.html +++ b/ang/orgdash/partials/Org.html @@ -1,5 +1,5 @@ + contact-id="orgId"> diff --git a/ang/orgdash/partials/OrgContactError.html b/ang/orgdash/partials/OrgContactError.html new file mode 100644 index 0000000..a37c7c8 --- /dev/null +++ b/ang/orgdash/partials/OrgContactError.html @@ -0,0 +1,8 @@ +

{{ts('Error')}}

+ +

{{ts('Could not access requested organization dashboard. Likely causes:')}}

+ \ No newline at end of file