Skip to content
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

Add ncyStateParams property #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 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-03-27
/*! angular-breadcrumb - v0.3.3-dev-2015-04-15
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */

Expand Down Expand Up @@ -143,6 +143,10 @@ function $Breadcrumb() {

$getLastViewScope: function() {
return $lastViewScope;
},

getStateParams: function() {
return $stateParams;
}
};
}];
Expand Down Expand Up @@ -183,14 +187,14 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
var $$templates = {
bootstrap2: '<ul class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'<span class="divider" ng-hide="$last">/</span>' +
'</li>' +
'</ul>',
bootstrap3: '<ol class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'</li>' +
'</ol>'
Expand All @@ -212,6 +216,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
scope.steps = $breadcrumb.getStatesChain();
angular.forEach(scope.steps, function (step) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
viewScope.ncyStateParams = $breadcrumb.getStateParams();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, many thanks for the PR.

I don't understand why you attach the stateParams to the viewScope here : it is the same scope of the one handled by the view controller (where you can already inject $stateParams and use it).

It make more sense if you attach the stateParams to the scope of the directive (scope) in order to use it in custom templates. Maybe, is that you wanted to do ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget an important part:

Before doing anything in your branch history, please can you revert changes on release/angular-breadcrumb.js and release/angular-breadcrumb.min.js ?

I change these file only when I made a new release (it allows users to always have a stable version when they checkout the master).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I use translations in the breadcrumb label, eg. label: {{ 'breadcrumb.login.admin' | translate }} by changing the last part of my translation key from stateParams (admin/company/user). I had some troubles when I tried to inject the stateParams from controller scope and I was getting undefined in some cases.

Revert changes from release directory? If you would like to add this changes to the official repository, of course.

var parseLabel = $interpolate(step.ncyBreadcrumb.label);
step.ncyBreadcrumbLabel = parseLabel(viewScope);
// Watcher for further viewScope updates
Expand Down Expand Up @@ -259,6 +264,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
if(lastStep) {
scope.ncyBreadcrumbLink = lastStep.ncyBreadcrumbLink;
if (lastStep.ncyBreadcrumb && lastStep.ncyBreadcrumb.label) {
viewScope.ncyStateParams = $breadcrumb.getStateParams();
var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
scope.ncyBreadcrumbLabel = parseLabel(viewScope);
// Watcher for further viewScope updates
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.

23 changes: 18 additions & 5 deletions release/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! angular-breadcrumb - v0.3.3
* 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),
force = 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.force){ force = true; }
if(conf.ncyBreadcrumb.skip){ skip = true; }
}
if((!conf.abstract || $$options.includeAbstract || force) && !skip) {
if(ref.paramExpr) {
parentParams = $lastViewScope.$eval(ref.paramExpr);
}
Expand Down Expand Up @@ -136,6 +143,10 @@ function $Breadcrumb() {

$getLastViewScope: function() {
return $lastViewScope;
},

getStateParams: function() {
return $stateParams;
}
};
}];
Expand Down Expand Up @@ -176,14 +187,14 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
var $$templates = {
bootstrap2: '<ul class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'<span class="divider" ng-hide="$last">/</span>' +
'</li>' +
'</ul>',
bootstrap3: '<ol class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'</li>' +
'</ol>'
Expand All @@ -205,6 +216,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
scope.steps = $breadcrumb.getStatesChain();
angular.forEach(scope.steps, function (step) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
viewScope.ncyStateParams = $breadcrumb.getStateParams();
var parseLabel = $interpolate(step.ncyBreadcrumb.label);
step.ncyBreadcrumbLabel = parseLabel(viewScope);
// Watcher for further viewScope updates
Expand Down Expand Up @@ -252,6 +264,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
if(lastStep) {
scope.ncyBreadcrumbLink = lastStep.ncyBreadcrumbLink;
if (lastStep.ncyBreadcrumb && lastStep.ncyBreadcrumb.label) {
viewScope.ncyStateParams = $breadcrumb.getStateParams();
var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
scope.ncyBreadcrumbLabel = parseLabel(viewScope);
// Watcher for further viewScope updates
Expand Down
Loading