-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uiBreadcrumbs: Abstract parents #11
Comments
I did come up with a workaround... but it will only work for my situation since I plan on using my abstract states for each module in a similar fashion.
|
Hi, Good point - I didn't account for abstract states. Thanks for posting your work around, and I'll think about how a general solution could be implemented. If you come up with anything more general, feel free to post it or even do a pull request. |
Idea: Your solution involves re-assigning any breadcrumb of an abstract state to an alternative non-abstract (concrete?) state. In your case, you have a particular convention that makes it work out for you. More generally, we could adapt that concept but make the redirection user-definable in the $state object. Something along the lines of this: $stateProvider
.state('articles', {
url: '',
abstract: true,
template: '<ui-view/>',
resolve: {
loggedin: checkLoggedin
},
data: {
breadcrumbsProxy: 'articles.all'
}
})
.state('articles.all articles', {
url: '/articles',
templateUrl: 'articles/views/list.html',
data: {
displayName: 'Articles'
}
}) So we put a user-defined property called (for example, off the top of my head) When I get a bit of time I'll try to implement something along those lines. |
Michael that sounds like a great plan. I might have some time today to try and implement and test it with my project. |
Micheel, I am new to Angular and am having difficulty understanding how the code is retrieving the displayname property from the data object. I am trying to replicate that functionality for the breadcrumbProxy but am failing miserably. Can you point me in the right direction on the methodology or angularjs functionality to obtain the displayname from the data object in ui-router. |
Reading over the code myself, I even had to take a minute to figure out what was going on, so don't feel bad about not getting it! Here's an explanation of what's going on: function getDisplayName(currentState) {
var i;
var propertyReference;
var propertyArray;
var displayName;
if (!scope.displaynameProperty) {
// if the displayname-property attribute was not specified, default to the state's name
return currentState.name;
}
propertyArray = scope.displaynameProperty.split('.');
propertyReference = currentState;
for (i = 0; i < propertyArray.length; i ++) {
if (angular.isDefined(propertyReference[propertyArray[i]])) {
if (propertyReference[propertyArray[i]] === false) {
return false;
} else {
propertyReference = propertyReference[propertyArray[i]];
}
} else {
// if the specified property was not foundm default to the state's name
return currentState.name;
}
}
// use the $interpolate service to handle any bindings in the propertyReference string.
displayName = $interpolate(propertyReference)(currentState.locals.globals);
return displayName;
} Let's assume the following setup: .state('articles.article by id', {
url: '/articles/:articleId',
templateUrl: 'articles/views/view.html',
data: {
displayName: '{{ article.title }}'
}
}) <ui-breadcrumbs displayname-property="data.displayName"></ui-breadcrumbs>
I hope I made that easy to follow. If you implement something similar, but for the "beadcrumbsProxy" idea, I'd suggest that a bunch of the logic from the above function could be shared by the new function to avoid repetition. Good luck! |
I implemented the fix suggested above - see e7adb82 (plus a few subsequent tweaks) See the updated docs: https://github.com/michaelbromley/angularUtils/tree/master/src/directives/uiBreadcrumbs#working-with-abstract-states The Plunker demo is also updated to demonstrate abstract states: http://plnkr.co/edit/bBgdxgB91Z6323HLWCzF?p=preview |
I got around to implementing your updates. I simplified the updateBreadcrumbsArray() a bit to get the expected output I wanted. I am not concerned about duplicate states and your demo doesn't seem to include the abstract state breadcrumb? Here is my function that I will be using. Thanks for your updates.
|
Hi, okay - looks good. In the Plunker demo, the 'home.users' state is abstract, and it delegates to the 'home.user.list' state. Thus, when you are in the 'home.users.detail' state, clicking on 'Users' in the breadcrumbs will take you to 'users.list'. |
@michaelbromley sorry, yours works great, I was mistaken. Awesome job. |
Sorry for resurrecting this old thread, how can I do if I want to show the abstract state (done) but remove the href from it? making it plain text and non-clickable? |
@dannygoncalves Do do this quickly I would for the uibreadcrumb and create either a custom property or do a simple trick on the displayname. For instance let's say you wanted to have your "Todo" breadcrumb to be only a link then instead of displayName: 'Todo' make it displayName: '[-]Todo' then update the following functions:
Inside updateBreadcrumbsArray..
I tested this out and it works. You could add an additional property like textonlyProperty: '@' and check for that before you push the breadcrumb. |
I am running into an issue with the breadcrumbs when the parent states are abstract. Below is an example using the mean.io boilerplate. I updated the routes to use your breadcrumb directive. The issue I run into is that the "Articles" breadcrumb is an abstract state and therefore be used as a route. I get this error: "Cannot transition to abstract state 'article'" What do you suggest for a workaround? I would think that more devs besides me would want to use abstract states to build the breadcrumbs... Thanks.
The text was updated successfully, but these errors were encountered: