Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
(#65) fixed navigation being broken when parameter values were missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Wilden committed Sep 8, 2014
1 parent dc22018 commit e1b2f35
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Last Changes

- [#65](https://github.com/LaxarJS/laxar/issues/65): fixed navigation being broken when parameter values were missing.
- [#66](https://github.com/LaxarJS/laxar/issues/66): prevented endless navigation ping pong in flow controller


Expand Down
22 changes: 10 additions & 12 deletions lib/portal/modules/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,7 @@ define( [
var placeParameters = {};
var params = place.fixedParameters || $routeParams;
object.forEach( place.expectedParameters, function( parameterName ) {
if( typeof params[ parameterName ] === 'undefined' ) {
placeParameters[ parameterName ] = null;
}
else {
placeParameters[ parameterName ] = decodePlaceParameter( params[ parameterName ] );
}
placeParameters[ parameterName ] = decodePlaceParameter( params[ parameterName ] );
} );

return placeParameters;
Expand All @@ -272,10 +267,7 @@ define( [
var location = '/' + placeName;

object.forEach( place.expectedParameters, function( parameterName ) {
location += '/';
if( parameterName in parameters && parameters[ parameterName ] !== null ) {
location += encodePlaceParameter( parameters[ parameterName ] );
}
location += '/' + encodePlaceParameter( parameters[ parameterName ] );
} );

return location;
Expand Down Expand Up @@ -346,10 +338,10 @@ define( [
if( placeName ) {
var targetPlace = places_[ placeName ];
var uri = placeName;
var parameters = entryPoint.parameters || {};

object.forEach( targetPlace.expectedParameters, function( parameterName ) {
var param = entryPoint.parameters[ parameterName ] || '';
uri += '/' + encodePlaceParameter( param );
uri += '/' + encodePlaceParameter( parameters[ parameterName ] );
} );

return uri;
Expand Down Expand Up @@ -421,12 +413,18 @@ define( [
///////////////////////////////////////////////////////////////////////////////////////////////////////////

function encodePlaceParameter( value ) {
if( value == null ) {
return '_';
}
return typeof value === 'string' ? value.replace( /\//g, '%2F' ) : value;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

function decodePlaceParameter( value ) {
if( value == null || value === '' || value === '_' ) {
return null;
}
return typeof value === 'string' ? value.replace( /%2F/g, '/' ) : value;
}

Expand Down
37 changes: 37 additions & 0 deletions lib/portal/modules/spec/flow_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,43 @@ define( [

///////////////////////////////////////////////////////////////////////////////////////////////

it( 'encodes null parameters as underscore (#65)', function() {
eventBus.publish( 'navigateRequest.previous', {
target: 'previous',
data: {
taskId: null
}
} );
jasmine.Clock.tick( 0 );

expect( $location.path ).toHaveBeenCalledWith( '/stepOne/_' );
} );

///////////////////////////////////////////////////////////////////////////////////////////////

it( 'decodes underscores as null (#65)', function() {
eventBus.publish.reset();
$controller( 'portal.FlowController', {
EventBus: eventBus,
place: $route.routes[ '/stepOne' ].resolve.place(),
// for everything apart from / we can rely on angular js to do the encoding
$routeParams: { taskId: '_' },
ThemeManager: {
getTheme: function() { return 'myTheme'; }
}
} );
jasmine.Clock.tick( 0 );

expect( eventBus.publish )
.toHaveBeenCalledWith( 'didNavigate.previous', {
target: 'previous',
place: 'stepOne/:taskId',
data: { taskId: null }
}, { sender: 'FlowController' } );
} );

///////////////////////////////////////////////////////////////////////////////////////////////

describe( 'to the currently active place again', function() {

beforeEach( function() {
Expand Down

0 comments on commit e1b2f35

Please sign in to comment.