Skip to content

Commit 934c552

Browse files
author
kazinov
committed
feat: add the scope-based ncyBreadcrumbIgnore flag
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 ncuillery#42 ncuillery#62
1 parent da3fecd commit 934c552

5 files changed

+175
-17
lines changed

dist/angular-breadcrumb.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-breadcrumb - v0.3.3-dev-2015-05-02
1+
/*! angular-breadcrumb - v0.4.0-dev-2015-08-06
22
* http://ncuillery.github.io/angular-breadcrumb
33
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
44

@@ -39,7 +39,8 @@ function $Breadcrumb() {
3939
// Early catch of $viewContentLoaded event
4040
$rootScope.$on('$viewContentLoaded', function (event) {
4141
// With nested views, the event occur several times, in "wrong" order
42-
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
42+
if(!event.targetScope.ncyBreadcrumbIgnore &&
43+
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
4344
$lastViewScope = event.targetScope;
4445
}
4546
});
@@ -224,8 +225,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
224225
});
225226
};
226227

227-
$rootScope.$on('$viewContentLoaded', function () {
228-
renderBreadcrumb();
228+
$rootScope.$on('$viewContentLoaded', function (event) {
229+
if(!event.targetScope.ncyBreadcrumbIgnore) {
230+
renderBreadcrumb();
231+
}
229232
});
230233

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

277-
$rootScope.$on('$viewContentLoaded', function () {
278-
renderLabel();
280+
$rootScope.$on('$viewContentLoaded', function (event) {
281+
if(!event.targetScope.ncyBreadcrumbIgnore) {
282+
renderLabel();
283+
}
279284
});
280285

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

343-
$rootScope.$on('$viewContentLoaded', function () {
344-
renderLabel();
348+
$rootScope.$on('$viewContentLoaded', function (event) {
349+
if(!event.targetScope.ncyBreadcrumbIgnore) {
350+
renderLabel();
351+
}
345352
});
346353

347354
// View(s) may be already loaded while the directive's linking

dist/angular-breadcrumb.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-breadcrumb.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function $Breadcrumb() {
3434
// Early catch of $viewContentLoaded event
3535
$rootScope.$on('$viewContentLoaded', function (event) {
3636
// With nested views, the event occur several times, in "wrong" order
37-
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
37+
if(!event.targetScope.ncyBreadcrumbIgnore &&
38+
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
3839
$lastViewScope = event.targetScope;
3940
}
4041
});
@@ -219,8 +220,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
219220
});
220221
};
221222

222-
$rootScope.$on('$viewContentLoaded', function () {
223-
renderBreadcrumb();
223+
$rootScope.$on('$viewContentLoaded', function (event) {
224+
if(!event.targetScope.ncyBreadcrumbIgnore) {
225+
renderBreadcrumb();
226+
}
224227
});
225228

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

272-
$rootScope.$on('$viewContentLoaded', function () {
273-
renderLabel();
275+
$rootScope.$on('$viewContentLoaded', function (event) {
276+
if(!event.targetScope.ncyBreadcrumbIgnore) {
277+
renderLabel();
278+
}
274279
});
275280

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

338-
$rootScope.$on('$viewContentLoaded', function () {
339-
renderLabel();
343+
$rootScope.$on('$viewContentLoaded', function (event) {
344+
if(!event.targetScope.ncyBreadcrumbIgnore) {
345+
renderLabel();
346+
}
340347
});
341348

342349
// View(s) may be already loaded while the directive's linking

test/mock/test-modules.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,35 @@ angular.module('ncy-sample-conf', ['ncy-sample', 'ngMock']).config(function($url
117117
$httpBackend.when('GET', 'views/room_detail.html').respond('dummy room_detail view');
118118
$httpBackend.when('GET', 'views/room_form.html').respond('dummy room_form view');
119119
});
120+
121+
/**
122+
* Module with abstract state with footer view
123+
*/
124+
angular.module('ncy-abstract-interpolation-conf', []).config(function($stateProvider) {
125+
$stateProvider
126+
.state('A', {
127+
abstract: true,
128+
url: '/a',
129+
views: {
130+
'a@': {
131+
template: '<div>View A</div>',
132+
controller: 'ACtrl'
133+
}
134+
}
135+
})
136+
.state('A.B', {
137+
url: '/b',
138+
views: {
139+
'b@': {
140+
template: '<div>View B</div>',
141+
controller: 'BCtrl'
142+
}
143+
},
144+
ncyBreadcrumb: {
145+
label: 'State {{tripleB}}'
146+
}
147+
});
148+
}).controller('ACtrl', function() {
149+
}).controller('BCtrl', function($scope) {
150+
$scope.tripleB = 'BBB';
151+
});
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*jshint undef: false */
2+
3+
4+
var element, scope;
5+
6+
describe('Breadcrumb directive with abstract-interpolation conf', function() {
7+
8+
beforeEach(function () {
9+
module('ncy-abstract-interpolation-conf');
10+
});
11+
12+
describe('when ncyBreadcrumbIgnore is undefined on parent view scope', function () {
13+
describe('when the parent view located before child view ', function () {
14+
beforeEach(inject(function ($rootScope, $compile) {
15+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
16+
var compile = $compile(element);
17+
scope = $rootScope.$new();
18+
compile(scope);
19+
scope.$digest();
20+
}));
21+
22+
it('renders the correct state chain and views content', inject(function () {
23+
goToState('A.B');
24+
scope.$emit('$viewContentLoaded');
25+
scope.$digest();
26+
27+
console.info('Directive content : ' + element.text());
28+
29+
expect(element.text()).toContain('State BBBView AView B');
30+
}));
31+
});
32+
33+
describe('when the parent view located after child view ', function () {
34+
beforeEach(inject(function ($rootScope, $compile) {
35+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
36+
var compile = $compile(element);
37+
scope = $rootScope.$new();
38+
compile(scope);
39+
scope.$digest();
40+
}));
41+
42+
it('renders the incorrect state chain', inject(function () {
43+
goToState('A.B');
44+
scope.$emit('$viewContentLoaded');
45+
scope.$digest();
46+
47+
console.info('Directive content : ' + element.text());
48+
49+
expect(element.text()).not.toContain('State BBB');
50+
}));
51+
});
52+
});
53+
});
54+
55+
describe('Breadcrumb directive with abstract-interpolation conf', function() {
56+
var controller;
57+
58+
beforeEach(function () {
59+
module('ncy-abstract-interpolation-conf', function ($controllerProvider) {
60+
$controllerProvider.register('ACtrl', function ($scope) {
61+
$scope.ncyBreadcrumbIgnore = true;
62+
});
63+
});
64+
});
65+
66+
describe('when ncyBreadcrumbIgnore property equals true on parent view scope', function () {
67+
describe('when the parent view located before child view ', function () {
68+
beforeEach(inject(function ($rootScope, $compile, $controller) {
69+
controller = $controller;
70+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
71+
var compile = $compile(element);
72+
scope = $rootScope.$new();
73+
74+
compile(scope);
75+
scope.$digest();
76+
}));
77+
78+
it('renders the correct state chain and views content', inject(function () {
79+
goToState('A.B');
80+
scope.$emit('$viewContentLoaded');
81+
scope.$digest();
82+
83+
console.info('Directive content : ' + element.text());
84+
85+
expect(element.text()).toContain('State BBBView AView B');
86+
}));
87+
});
88+
89+
describe('when the parent view located after child view ', function () {
90+
beforeEach(inject(function ($rootScope, $compile, $controller) {
91+
controller = $controller;
92+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
93+
var compile = $compile(element);
94+
scope = $rootScope.$new();
95+
96+
compile(scope);
97+
scope.$digest();
98+
}));
99+
100+
it('renders the correct state chain and views content', inject(function () {
101+
goToState('A.B');
102+
scope.$emit('$viewContentLoaded');
103+
scope.$digest();
104+
105+
console.info('Directive content : ' + element.text());
106+
107+
expect(element.text()).toContain('State BBBView BView A');
108+
}));
109+
});
110+
});
111+
112+
});

0 commit comments

Comments
 (0)