resolve unknown/ambiguous stop into list of stops
This commit is contained in:
parent
d23283329d
commit
d313ca7fc1
4 changed files with 74 additions and 11 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -64,3 +64,10 @@ h3 {
|
|||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
ul.suggestions {
|
||||
li {
|
||||
padding-top: 0.5rem;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
|
20
templates/disambiguation.html.ep
Normal file
20
templates/disambiguation.html.ep
Normal file
|
@ -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>
|
Loading…
Reference in a new issue