diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 86f85d8684e269261d48089585fa19e45c1bdf6b..251bc1552cded74453bcca05b2b8b66ec81734a6 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -1074,20 +1074,54 @@ sub station { )->catch( sub { my ( $err, $status ) = @_; - if ($status) { + if ( $status and $status->{suggestions} ) { $self->render( - 'landingpage', - with_autocomplete => 1, - with_geolocation => 1, - error => $status->{errstr}, - status => 400, + 'disambiguation', + suggestions => $status->{suggestions}, + status => 300, ); } + elsif ( $use_hafas and $status and $status->errcode eq 'LOCATION' ) + { + $status->similar_stops_p->then( + sub { + my @suggestions = @_; + if ( @suggestions == 1 ) { + $self->redirect_to( + '/s/' . $suggestions[0]->{id} . '?hafas=1' ); + } + else { + $self->render( + 'disambiguation', + suggestions => [ + map { + { + name => $_->{name}, + eva => $_->{id} + } + } @suggestions + ], + status => 300, + ); + } + } + )->catch( + sub { + my ($err2) = @_; + $self->render( + 'exception', + exception => + "StopFinder threw '$err2' when handling '$err'", + status => 502 + ); + } + )->wait; + } else { $self->render( 'exception', exception => $err, - status => 500 + status => 502 ); } } diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm index 4c286cbaaea73266f1cce3d36234e41923b82211..a529e282bca2c411d94fef72c001f6205d94e28d 100644 --- a/lib/Travelynx/Helper/IRIS.pm +++ b/lib/Travelynx/Helper/IRIS.pm @@ -153,10 +153,12 @@ sub get_departures_p { return Mojo::Promise->reject( 'ambiguous station name', { - results => [], - errstr => - "Mehrdeutiger Stationsname: '$station'. Mögliche Eingaben: " - . join( q{, }, map { $_->[1] } @station_matches ), + results => [], + errstr => "Mehrdeutiger Stationsname: '$station'", + suggestions => [ + map { { name => $_->[1], eva => $_->[2] } } + @station_matches + ], } ); } diff --git a/sass/src/common/local.scss b/sass/src/common/local.scss index b9362dfc63f016fe22a81ee4cf38604acb99afe2..a8024749283bb543e86b8e3b47f59f49c363bb4f 100644 --- a/sass/src/common/local.scss +++ b/sass/src/common/local.scss @@ -64,3 +64,10 @@ h3 { font-size: 16px; } } + +ul.suggestions { + li { + padding-top: 0.5rem; + padding-bottom: 0.5rem; + } +} diff --git a/templates/disambiguation.html.ep b/templates/disambiguation.html.ep new file mode 100644 index 0000000000000000000000000000000000000000..270aa9995bb3e852f99e539f081d7d9258f2f6ad --- /dev/null +++ b/templates/disambiguation.html.ep @@ -0,0 +1,20 @@ +
+
+
+
+ Mehrdeutige Eingabe +

„<%= $station %>“ ist nicht eindeutig. Bitte wähle eine der folgenden Optionen aus.

+
+
+
+
+ +
+
+ +
+