Skip to content

Commit

Permalink
Added resolve dependency to the parent dashboard state to make the
Browse files Browse the repository at this point in the history
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 civicrm/civicrm-core#13337).
- Updated file name for DashCtrl to match conventions.
  • Loading branch information
universalhandle committed Dec 20, 2018
1 parent ac9fe95 commit 1d73ae1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
1 change: 0 additions & 1 deletion CRM/Orgdash/Page/Angular.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions ang/orgdash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
})
Expand Down Expand Up @@ -63,7 +84,10 @@
});
}
}
})

.state('org-contact-error', {
templateUrl: '~/orgdash/partials/OrgContactError.html'
});
})

Expand Down
7 changes: 0 additions & 7 deletions ang/orgdash/controllers/Dash.js

This file was deleted.

8 changes: 8 additions & 0 deletions ang/orgdash/controllers/DashCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(function(angular, $, _) {

angular.module('orgdash')
.controller('DashCtrl', function($scope, orgContact) {
$scope.name = orgContact.display_name;
});

})(angular, CRM.$, CRM._);
4 changes: 1 addition & 3 deletions ang/orgdash/controllers/OrgCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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._);
2 changes: 1 addition & 1 deletion ang/orgdash/partials/Dash.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 crm-page-title>TODO: Title this page</h1>
<h1 crm-page-title>{{ts('Organization Dashboard for %1', {1: name})}}</h1>

<!-- TODO: this nav is probably placeholder -->
<div class="crm-tabset ui-tabs ui-corner-all ui-widget ui-widget-content">
Expand Down
2 changes: 1 addition & 1 deletion ang/orgdash/partials/Org.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<crm-profile-form
name="orgDetails"
profile-id="profileId"
contact-id="orgContact.id">
contact-id="orgId">
</crm-profile-form>
8 changes: 8 additions & 0 deletions ang/orgdash/partials/OrgContactError.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1 crm-page-title>{{ts('Error')}}</h1>

<p>{{ts('Could not access requested organization dashboard. Likely causes:')}}</p>
<ul>
<li>{{ts('The contact does not exist.')}}</li>
<li>{{ts("The contact exists but does not represent an organization.")}}</li>
<li>{{ts("The contact exists, but you don't have permission to access it.")}}</li>
</ul>

0 comments on commit 1d73ae1

Please sign in to comment.