11/**
22 * UI-Router Extras: Sticky states, Future States, Deep State Redirect, Transition promise
33 * Monolithic build (all modules)
4- * @version 0.1.2
4+ * @version 0.1.3
55 * @link http://christopherthielen.github.io/ui-router-extras/
66 * @license MIT License, http://www.opensource.org/licenses/MIT
77 */
@@ -201,7 +201,7 @@ angular.module('ct.ui.router.extras.dsr', [ 'ct.ui.router.extras.core' ]).config
201201 $provide . decorator ( "$state" , [ '$delegate' , '$q' , function ( $state , $q ) {
202202 $state_transitionTo = $state . transitionTo ;
203203 $state . transitionTo = function ( to , toParams , options ) {
204- if ( options . ignoreDsr ) {
204+ if ( options && options . ignoreDsr ) {
205205 ignoreDsr = options . ignoreDsr ;
206206 }
207207
@@ -333,7 +333,12 @@ angular.module('ct.ui.router.extras.dsr').service("$deepStateRedirect", [ '$root
333333 computeDeepStateStatus ( state )
334334 var cfg = getConfig ( state ) ;
335335 var key = getParamsString ( params , cfg . params ) ;
336- var redirect = lastSubstate [ state . name ] [ key ] || cfg [ 'default' ] ;
336+ var redirect = lastSubstate [ state . name ] ;
337+ if ( redirect && redirect [ key ] ) {
338+ redirect = redirect [ key ] ;
339+ } else {
340+ redirect = cfg [ 'default' ] ;
341+ }
337342 return redirect ;
338343 } ,
339344 reset : function ( stateOrName , params ) {
@@ -511,10 +516,13 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) {
511516 } ;
512517 }
513518
519+ function sortByStateDepth ( a , b ) {
520+ return a . name . split ( "." ) . length - b . name . split ( "." ) . length ;
521+ }
514522
515523 var stickySupport = {
516524 getInactiveStates : function ( ) {
517- return map ( inactiveStates , angular . identity ) ;
525+ return map ( inactiveStates , angular . identity ) . sort ( sortByStateDepth ) ;
518526 } ,
519527 getInactiveStatesByParent : function ( ) {
520528 return mapInactives ( ) ;
@@ -532,7 +540,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) {
532540 // }
533541 processTransition : function ( transition ) {
534542 var treeChanges = calcTreeChanges ( transition ) ;
535- var currentInactives = map ( inactiveStates , angular . identity ) ;
543+ var currentInactives = stickySupport . getInactiveStates ( ) ;
536544 var futureInactives , exitingTypes , enteringTypes ;
537545 var keep = treeChanges . keep ;
538546
@@ -620,7 +628,7 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) {
620628 . reduce ( flattenReduce , [ ] )
621629 . concat ( orphanedRoots )
622630 // Sort by depth to exit orphans in proper order
623- . sort ( function ( a , b ) { return a . name . split ( "." ) . length - b . name . split ( "." ) . length ; } ) ;
631+ . sort ( sortByStateDepth ) ;
624632
625633 // Add them to the list of states being exited.
626634 var exitOrOrphaned = exitingTypes
@@ -634,7 +642,8 @@ function $StickyStateProvider($stateProvider, uirextras_coreProvider) {
634642 futureInactives = currentInactives
635643 . filter ( notIn ( exitOrOrphaned ) )
636644 . filter ( notIn ( treeChanges . entering ) )
637- . concat ( exitingTypes . filter ( typeIs ( "inactivate" ) ) . map ( prop ( "state" ) ) ) ;
645+ . concat ( exitingTypes . filter ( typeIs ( "inactivate" ) ) . map ( prop ( "state" ) ) )
646+ . sort ( sortByStateDepth ) ;
638647
639648 return {
640649 keep : keep ,
@@ -1254,30 +1263,36 @@ angular.module("ct.ui.router.extras.sticky").config(
12541263 return s . self . name ;
12551264 } ) ) ;
12561265
1257- var viewMsg = function ( local , name ) {
1258- return "'" + name + "' (" + local . $$state . name + ")" ;
1259- } ;
12601266 var statesOnly = function ( local , name ) {
12611267 return name != 'globals' && name != 'resolve' ;
12621268 } ;
1269+
12631270 var viewsForState = function ( state ) {
1264- var views = map ( filterObj ( state . locals , statesOnly ) , viewMsg ) . join ( ", " ) ;
1265- return "(" + ( state . self . name ? state . self . name : "root" ) + ".locals" + ( views . length ? ": " + views : "" ) + ")" ;
1271+ var viewLocals = filterObj ( state . locals , statesOnly ) ;
1272+
1273+ if ( ! Object . keys ( viewLocals ) . length ) {
1274+ viewLocals [ '' ] = { $$state : { name : null } } ;
1275+ }
1276+
1277+ return map ( viewLocals , function ( local , name ) {
1278+ return {
1279+ localsFor : state . self . name ? state . self . name : "(root)" ,
1280+ uiViewName : name || null ,
1281+ filledByState : local . $$state . name
1282+ } ;
1283+ } ) ;
12661284 } ;
12671285
1268- var message = viewsForState ( currentState ) ;
1286+ var viewsByState = viewsForState ( currentState ) ;
12691287 var parent = currentState . parent ;
12701288 while ( parent && parent !== currentState ) {
1271- if ( parent . self . name === "" ) {
1272- // Show the __inactives before showing root state.
1273- message = viewsForState ( $state . $current . path [ 0 ] ) + " / " + message ;
1274- }
1275- message = viewsForState ( parent ) + " / " + message ;
1289+ viewsByState = viewsByState . concat ( viewsForState ( parent ) ) ;
12761290 currentState = parent ;
12771291 parent = currentState . parent ;
12781292 }
12791293
1280- $log . debug ( "Views: " + message ) ;
1294+ $log . debug ( "Views active on each state:" ) ;
1295+ console . table ( viewsByState . reverse ( ) ) ;
12811296 }
12821297 }
12831298 ]
0 commit comments