Skip to content

Commit

Permalink
feat: add the scope-based ncyBreadcrumbIgnore flag
Browse files Browse the repository at this point in the history
Provide the way to ignore some views when rendering breadcrumbs. To achieve this the property ncyBreadcrumbIgnore should be set to true on the view controller scope.

Closes #42 #62
  • Loading branch information
kazinov committed Aug 7, 2015
1 parent da3fecd commit 934c552
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 17 deletions.
23 changes: 15 additions & 8 deletions dist/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-breadcrumb - v0.3.3-dev-2015-05-02
/*! angular-breadcrumb - v0.4.0-dev-2015-08-06
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */

Expand Down Expand Up @@ -39,7 +39,8 @@ function $Breadcrumb() {
// Early catch of $viewContentLoaded event
$rootScope.$on('$viewContentLoaded', function (event) {
// With nested views, the event occur several times, in "wrong" order
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
if(!event.targetScope.ncyBreadcrumbIgnore &&
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
$lastViewScope = event.targetScope;
}
});
Expand Down Expand Up @@ -224,8 +225,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
});
};

$rootScope.$on('$viewContentLoaded', function () {
renderBreadcrumb();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderBreadcrumb();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down Expand Up @@ -274,8 +277,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};

$rootScope.$on('$viewContentLoaded', function () {
renderLabel();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down Expand Up @@ -340,8 +345,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};

$rootScope.$on('$viewContentLoaded', function () {
renderLabel();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down
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.

21 changes: 14 additions & 7 deletions src/angular-breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function $Breadcrumb() {
// Early catch of $viewContentLoaded event
$rootScope.$on('$viewContentLoaded', function (event) {
// With nested views, the event occur several times, in "wrong" order
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
if(!event.targetScope.ncyBreadcrumbIgnore &&
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
$lastViewScope = event.targetScope;
}
});
Expand Down Expand Up @@ -219,8 +220,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
});
};

$rootScope.$on('$viewContentLoaded', function () {
renderBreadcrumb();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderBreadcrumb();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down Expand Up @@ -269,8 +272,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};

$rootScope.$on('$viewContentLoaded', function () {
renderLabel();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down Expand Up @@ -335,8 +340,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};

$rootScope.$on('$viewContentLoaded', function () {
renderLabel();
$rootScope.$on('$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
});

// View(s) may be already loaded while the directive's linking
Expand Down
32 changes: 32 additions & 0 deletions test/mock/test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,35 @@ angular.module('ncy-sample-conf', ['ncy-sample', 'ngMock']).config(function($url
$httpBackend.when('GET', 'views/room_detail.html').respond('dummy room_detail view');
$httpBackend.when('GET', 'views/room_form.html').respond('dummy room_form view');
});

/**
* Module with abstract state with footer view
*/
angular.module('ncy-abstract-interpolation-conf', []).config(function($stateProvider) {
$stateProvider
.state('A', {
abstract: true,
url: '/a',
views: {
'a@': {
template: '<div>View A</div>',
controller: 'ACtrl'
}
}
})
.state('A.B', {
url: '/b',
views: {
'b@': {
template: '<div>View B</div>',
controller: 'BCtrl'
}
},
ncyBreadcrumb: {
label: 'State {{tripleB}}'
}
});
}).controller('ACtrl', function() {
}).controller('BCtrl', function($scope) {
$scope.tripleB = 'BBB';
});
112 changes: 112 additions & 0 deletions test/spec/directive-ncyBreadcrumbIgnore-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*jshint undef: false */


var element, scope;

describe('Breadcrumb directive with abstract-interpolation conf', function() {

beforeEach(function () {
module('ncy-abstract-interpolation-conf');
});

describe('when ncyBreadcrumbIgnore is undefined on parent view scope', function () {
describe('when the parent view located before child view ', function () {
beforeEach(inject(function ($rootScope, $compile) {
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
var compile = $compile(element);
scope = $rootScope.$new();
compile(scope);
scope.$digest();
}));

it('renders the correct state chain and views content', inject(function () {
goToState('A.B');
scope.$emit('$viewContentLoaded');
scope.$digest();

console.info('Directive content : ' + element.text());

expect(element.text()).toContain('State BBBView AView B');
}));
});

describe('when the parent view located after child view ', function () {
beforeEach(inject(function ($rootScope, $compile) {
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
var compile = $compile(element);
scope = $rootScope.$new();
compile(scope);
scope.$digest();
}));

it('renders the incorrect state chain', inject(function () {
goToState('A.B');
scope.$emit('$viewContentLoaded');
scope.$digest();

console.info('Directive content : ' + element.text());

expect(element.text()).not.toContain('State BBB');
}));
});
});
});

describe('Breadcrumb directive with abstract-interpolation conf', function() {
var controller;

beforeEach(function () {
module('ncy-abstract-interpolation-conf', function ($controllerProvider) {
$controllerProvider.register('ACtrl', function ($scope) {
$scope.ncyBreadcrumbIgnore = true;
});
});
});

describe('when ncyBreadcrumbIgnore property equals true on parent view scope', function () {
describe('when the parent view located before child view ', function () {
beforeEach(inject(function ($rootScope, $compile, $controller) {
controller = $controller;
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
var compile = $compile(element);
scope = $rootScope.$new();

compile(scope);
scope.$digest();
}));

it('renders the correct state chain and views content', inject(function () {
goToState('A.B');
scope.$emit('$viewContentLoaded');
scope.$digest();

console.info('Directive content : ' + element.text());

expect(element.text()).toContain('State BBBView AView B');
}));
});

describe('when the parent view located after child view ', function () {
beforeEach(inject(function ($rootScope, $compile, $controller) {
controller = $controller;
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
var compile = $compile(element);
scope = $rootScope.$new();

compile(scope);
scope.$digest();
}));

it('renders the correct state chain and views content', inject(function () {
goToState('A.B');
scope.$emit('$viewContentLoaded');
scope.$digest();

console.info('Directive content : ' + element.text());

expect(element.text()).toContain('State BBBView BView A');
}));
});
});

});

0 comments on commit 934c552

Please sign in to comment.