Skip to content

Commit

Permalink
Refactored states so that each tab of the application is a child of
Browse files Browse the repository at this point in the history
a parent state which provides the page chrome as well as universally
needed resolves.
  • Loading branch information
universalhandle committed Dec 20, 2018
1 parent 55d8bd7 commit ac9fe95
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 33 deletions.
36 changes: 29 additions & 7 deletions ang/orgdash.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
(function(angular, $, _) {
angular.module('orgdash', CRM.angRequires('orgdash'))
.config(function($stateProvider) {
.config(function($stateProvider, $urlRouterProvider) {

// Redirect to the organization detail route if the abstract parent is
// accessed directly.
$urlRouterProvider.when('/:id', '/:id/org');

$stateProvider
.state('org', {
url: '/org/:id',
// Abstract parent state for all pages; provides the page "chrome" and
// universally needed resolves.
.state('dash', {
abstract: true,
url: '/:id',
templateUrl: '~/orgdash/partials/Dash.html',
controller: 'DashCtrl',
resolve: {
orgId: function ($stateParams) {
return $stateParams.id;
}
}
})

// Organization detail
.state('dash.org', {
url: '/org',
templateUrl: '~/orgdash/partials/Org.html',
controller: 'OrgCtrl'
})
.state('contacts', {
url: '/contacts/:id',

// Contact list and detail
.state('dash.contacts', {
url: '/contacts',
templateUrl: '~/orgdash/partials/Contacts.html',
controller: 'ContactsCtrl',
resolve: {
profileId: function () {
return CRM.vars.orgdash.orgdash_single_contact_profile;
},
relatedContacts: function($stateParams, RelatedContactService, profileId, relTypeIds) {
relatedContacts: function(RelatedContactService, orgId, profileId, relTypeIds) {
const relTypes = _.union(relTypeIds.benefits, relTypeIds.contacts, relTypeIds.highlighted);

return RelatedContactService.fetch(
$stateParams.id,
orgId,
relTypes,
profileId
);
Expand Down
7 changes: 7 additions & 0 deletions ang/orgdash/controllers/Dash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function(angular, $, _) {

angular.module('orgdash')
.controller('DashCtrl', function() {
});

})(angular, CRM.$, CRM._);
4 changes: 2 additions & 2 deletions ang/orgdash/controllers/OrgCtrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function(angular, $, _) {

angular.module('orgdash')
.controller('OrgCtrl', function($scope, $stateParams) {
.controller('OrgCtrl', function($scope, orgId) {
$scope.profileId = CRM.vars.orgdash.orgdash_org_profile_id;
$scope.orgContact = {
id: $stateParams.id
id: orgId
};
});

Expand Down
23 changes: 23 additions & 0 deletions ang/orgdash/partials/Dash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1 crm-page-title>TODO: Title this page</h1>

<!-- TODO: this nav is probably placeholder -->
<div class="crm-tabset ui-tabs ui-corner-all ui-widget ui-widget-content">
<ul role="tablist" class="ui-tabs-nav ui-corner-all ui-helper-reset ui-helper-clearfix ui-widget-header">
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref=".org" role="presentation" tabindex="-1">
{{ts('Organization Details')}}
</a>
</li>
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref=".contacts" role="presentation" tabindex="-1">
{{ts('Contacts and Benefits')}}
</a>
</li>
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref=".txn" role="presentation" tabindex="-1">
{{ts('Transaction History')}}
</a>
</li>
</ul>
</div>
<div ui-view></div>
26 changes: 2 additions & 24 deletions templates/CRM/Orgdash/Page/Angular.tpl
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
{literal}
<div ng-app="orgdash">
<h1 crm-page-title>TODO: Title this page</h1>

<!-- TODO: this nav is probably placeholder -->
<div class="crm-tabset ui-tabs ui-corner-all ui-widget ui-widget-content">
<ul role="tablist" class="ui-tabs-nav ui-corner-all ui-helper-reset ui-helper-clearfix ui-widget-header">
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref="org" role="presentation" tabindex="-1">
{{ts('Organization Details')}}
</a>
</li>
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref="contacts" role="presentation" tabindex="-1">
{{ts('Contacts and Benefits')}}
</a>
</li>
<li class="ui-corner-all crm-tab-button ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" role="tab" tabindex="0">
<a ui-sref="txn" role="presentation" tabindex="-1">
{{ts('Transaction History')}}
</a>
</li>
</ul>
<div ui-view></div>
</div>
<div ui-view></div>
</div>
{/literal}
{/literal}

0 comments on commit ac9fe95

Please sign in to comment.