summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm48
-rw-r--r--lib/Travelynx/Helper/IRIS.pm10
-rw-r--r--sass/src/common/local.scss7
-rw-r--r--templates/disambiguation.html.ep20
4 files changed, 74 insertions, 11 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 86f85d8..251bc15 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 4c286cb..a529e28 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 b9362df..a802474 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 0000000..270aa99
--- /dev/null
+++ b/templates/disambiguation.html.ep
@@ -0,0 +1,20 @@
+<div class="row">
+ <div class="col s12">
+ <div class="card info-color">
+ <div class="card-content">
+ <span class="card-title">Mehrdeutige Eingabe</span>
+ <p>„<%= $station %>“ ist nicht eindeutig. Bitte wähle eine der folgenden Optionen aus.</p>
+ </div>
+ </div>
+ </div>
+</div>
+
+<div class="row">
+ <div class="col s12">
+ <ul class="suggestions">
+ % for my $suggestion (@{$suggestions // []}) {
+ <li><a href="<%= url_for('station' => $suggestion->{eva}) . (param('hafas') ? '?hafas=1' : q{}) %>"><%= $suggestion->{name} %></a></li>
+ % }
+ </ul>
+ </div>
+</div>