Skip to content

Commit

Permalink
feat(addStateInChain) : Add showAbstract to ncyBreadcrumb options
Browse files Browse the repository at this point in the history
Give ability to show specific abstract states, even if options.includeAbstract is turned off in configuration
  • Loading branch information
KodeShark committed Mar 21, 2015
1 parent 884d9ac commit 31125a3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
15 changes: 11 additions & 4 deletions dist/angular-breadcrumb.js
@@ -1,6 +1,6 @@
/*! angular-breadcrumb - v0.3.2-dev-2014-12-14
/*! angular-breadcrumb - v0.3.3-dev-2015-03-21
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2014 Nicolas Cuillery; Licensed MIT */
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */

(function (window, angular, undefined) {
'use strict';
Expand Down Expand Up @@ -56,7 +56,9 @@ function $Breadcrumb() {
var $$addStateInChain = function(chain, stateRef) {
var conf,
parentParams,
ref = parseStateRef(stateRef);
ref = parseStateRef(stateRef),
showAbstract = false,
skip = false;

for(var i=0, l=chain.length; i<l; i+=1) {
if (chain[i].name === ref.state) {
Expand All @@ -65,7 +67,12 @@ function $Breadcrumb() {
}

conf = $state.get(ref.state);
if((!conf.abstract || $$options.includeAbstract) && !(conf.ncyBreadcrumb && conf.ncyBreadcrumb.skip)) {
// Get breadcrumb options
if(conf.ncyBreadcrumb) {
if(conf.ncyBreadcrumb.showAbstract){ showAbstract = true; }
if(conf.ncyBreadcrumb.skip){ skip = true; }
}
if((!conf.abstract || $$options.includeAbstract || showAbstract) && !skip) {
if(ref.paramExpr) {
parentParams = $lastViewScope.$eval(ref.paramExpr);
}
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-breadcrumb.min.js

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

11 changes: 9 additions & 2 deletions src/angular-breadcrumb.js
Expand Up @@ -51,7 +51,9 @@ function $Breadcrumb() {
var $$addStateInChain = function(chain, stateRef) {
var conf,
parentParams,
ref = parseStateRef(stateRef);
ref = parseStateRef(stateRef),
showAbstract = false,
skip = false;

for(var i=0, l=chain.length; i<l; i+=1) {
if (chain[i].name === ref.state) {
Expand All @@ -60,7 +62,12 @@ function $Breadcrumb() {
}

conf = $state.get(ref.state);
if((!conf.abstract || $$options.includeAbstract) && !(conf.ncyBreadcrumb && conf.ncyBreadcrumb.skip)) {
// Get breadcrumb options
if(conf.ncyBreadcrumb) {
if(conf.ncyBreadcrumb.showAbstract){ showAbstract = true; }
if(conf.ncyBreadcrumb.skip){ skip = true; }
}
if((!conf.abstract || $$options.includeAbstract || showAbstract) && !skip) {
if(ref.paramExpr) {
parentParams = $lastViewScope.$eval(ref.paramExpr);
}
Expand Down
4 changes: 3 additions & 1 deletion test/mock/test-modules.js
Expand Up @@ -27,7 +27,9 @@ angular.module('ncy-abstract-conf', []).config(function($stateProvider) {
.state('D.E', {url: '/e', abstract: true, ncyBreadcrumb: {label: 'State E'}})
.state('D.E.F', {url: '/f', ncyBreadcrumb: {label: 'State F'}})
.state('G', {url: '/g', abstract: true, ncyBreadcrumb: {label: 'State G', skip: true}})
.state('G.H', {url: '/h', ncyBreadcrumb: {label: 'State H'}});
.state('G.H', {url: '/h', ncyBreadcrumb: {label: 'State H'}})
.state('I', {url: '/i', abstract: true, ncyBreadcrumb: {label: 'State I', showAbstract: true}})
.state('I.J', {url: '/j', ncyBreadcrumb: {label: 'State J'}});
});

/**
Expand Down
6 changes: 6 additions & 0 deletions test/spec/service-abstract-test.js
Expand Up @@ -26,6 +26,12 @@ describe('Service with abstract conf', function() {
expect(stringifyStateChain(statesChain)).toBe('G.H');
}));

it('should return a two step route to I.J', inject(function($breadcrumb) {
goToState('I.J');
var statesChain = $breadcrumb.getStatesChain();
expect(stringifyStateChain(statesChain)).toBe('I --> I.J');
}));

});

describe('with abstract state inclusion', function() {
Expand Down

0 comments on commit 31125a3

Please sign in to comment.