Skip to content

Commit

Permalink
feat($breadcrumb): add a configuration property for skipping a state …
Browse files Browse the repository at this point in the history
…in the breadcrumb

A state with 'data.ncyBreadcrumbSkip = true' is not included in the chain of states.

Closes #9
  • Loading branch information
ncuillery committed May 8, 2014
1 parent 7a9bedd commit dd255d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
11 changes: 7 additions & 4 deletions dist/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-breadcrumb - v0.1.0 - 2014-05-01
/*! angular-breadcrumb - v0.1.0 - 2014-05-08
* https://github.com/ncuillery/angular-breadcrumb
* Copyright (c) 2014 Nicolas Cuillery; Licensed MIT */

Expand Down Expand Up @@ -54,7 +54,12 @@ function $Breadcrumb() {
stateAlreadyInChain = true;
}
});
if(!stateAlreadyInChain && !state.abstract) {

var skipStep = angular.isDefined(state.data) &&
state.data.ncyBreadcrumbSkip &&
!$$isInherited(state, 'ncyBreadcrumbSkip');

if(!stateAlreadyInChain && !state.abstract && !skipStep) {
// Insert at first or second index.
if(prefixStateInserted) {
chain.splice(1, 0, state);
Expand Down Expand Up @@ -125,7 +130,6 @@ function $Breadcrumb() {
}
};
}];

}

function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
Expand Down Expand Up @@ -182,5 +186,4 @@ BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
angular.module('ncy-angular-breadcrumb', ['ui.router.state'])
.provider('$breadcrumb', $Breadcrumb)
.directive('ncyBreadcrumb', BreadcrumbDirective);

})(window, window.angular);
4 changes: 2 additions & 2 deletions dist/angular-breadcrumb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ angular.module('ncy-sample', ['ui.router.state', 'ui.bootstrap', 'ncy-angular-br
}, function(result) {
return $state.go("^");
});
},
data: {
ncyBreadcrumbSkip: true
}
})
.state('room', {
Expand Down
7 changes: 6 additions & 1 deletion src/angular-breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function $Breadcrumb() {
stateAlreadyInChain = true;
}
});
if(!stateAlreadyInChain && !state.abstract) {

var skipStep = angular.isDefined(state.data) &&
state.data.ncyBreadcrumbSkip &&
!$$isInherited(state, 'ncyBreadcrumbSkip');

if(!stateAlreadyInChain && !state.abstract && !skipStep) {
// Insert at first or second index.
if(prefixStateInserted) {
chain.splice(1, 0, state);
Expand Down
4 changes: 3 additions & 1 deletion test/mock/test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ angular.module('ncy-basic-conf', []).config(function($stateProvider) {
.state('A', {url: '/a', data: {ncyBreadcrumbLabel: 'State A'}})
.state('A.B', {url: '/b', data: {ncyBreadcrumbLabel: 'State B'}})
.state('A.B.C', {url: '/c', data: {ncyBreadcrumbLabel: 'State C'}})
.state('D', {parent: 'A.B.C', url: '/d', data: {ncyBreadcrumbLabel: 'State D'}}); // Explicit parent
.state('D', {parent: 'A.B.C', url: '/d', data: {ncyBreadcrumbLabel: 'State D'}}) // Explicit parent
.state('D.E', {url: '/e', data: {ncyBreadcrumbLabel: 'State E', ncyBreadcrumbSkip: true}})
.state('D.E.F', {url: '/f', data: {ncyBreadcrumbLabel: 'State F'}});
});

/**
Expand Down
13 changes: 13 additions & 0 deletions test/spec/service-basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ describe('Service with basic conf', function() {
expect(statesChain[2].ncyBreadcrumbLink).toBe('#/a/b/c');
expect(statesChain[3].ncyBreadcrumbLink).toBe('#/a/b/c/d');
}));

it('should not return the step for E state', inject(function($breadcrumb) {
goToState('D.E');
var statesChain = $breadcrumb.getStatesChain();
expect(stringifyStateChain(statesChain)).toBe('A --> A.B --> A.B.C --> D');
}));

it('should have a 5-step route to F state (E skipped)', inject(function($breadcrumb) {
goToState('D.E.F');
var statesChain = $breadcrumb.getStatesChain();
expect(stringifyStateChain(statesChain)).toBe('A --> A.B --> A.B.C --> D --> D.E.F');
}));

});

0 comments on commit dd255d9

Please sign in to comment.