summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Controller
diff options
context:
space:
mode:
authorDerf Null <derf@finalrewind.org>2023-04-18 22:51:57 +0200
committerDerf Null <derf@finalrewind.org>2023-04-18 22:51:57 +0200
commitdfdf32b357ba057325fb02f6363706d18733a418 (patch)
tree0a06e4ba4aac4818800cddb251f3e152734cbc83 /lib/DBInfoscreen/Controller
parentabb12f02c6b45eea4d553da8e4b719e78d18606a (diff)
stop search: add hafas support
Diffstat (limited to 'lib/DBInfoscreen/Controller')
-rw-r--r--lib/DBInfoscreen/Controller/Static.pm15
-rw-r--r--lib/DBInfoscreen/Controller/Stationboard.pm39
2 files changed, 52 insertions, 2 deletions
diff --git a/lib/DBInfoscreen/Controller/Static.pm b/lib/DBInfoscreen/Controller/Static.pm
index e30b34f..63b3b8c 100644
--- a/lib/DBInfoscreen/Controller/Static.pm
+++ b/lib/DBInfoscreen/Controller/Static.pm
@@ -42,8 +42,23 @@ sub redirect {
sub geostop {
my ($self) = @_;
+ my ( $api_link, $api_text, $api_icon );
+ if ( $self->param('hafas') ) {
+ $api_link = '/_autostop';
+ $api_text = 'Auf Bahnverkehr wechseln';
+ $api_icon = 'directions_bus';
+ }
+ else {
+ $api_link = '/_autostop?hafas=1';
+ $api_text = 'Auf Nahverkehr wechseln';
+ $api_icon = 'train';
+ }
+
$self->render(
'geostop',
+ api_link => $api_link,
+ api_text => $api_text,
+ api_icon => $api_icon,
with_geostop => 1,
hide_opts => 1
);
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm
index ef33699..d2cca8d 100644
--- a/lib/DBInfoscreen/Controller/Stationboard.pm
+++ b/lib/DBInfoscreen/Controller/Stationboard.pm
@@ -1763,12 +1763,46 @@ sub handle_result {
sub stations_by_coordinates {
my $self = shift;
- my $lon = $self->param('lon');
- my $lat = $self->param('lat');
+ my $lon = $self->param('lon');
+ my $lat = $self->param('lat');
+ my $hafas = $self->param('hafas');
if ( not $lon or not $lat ) {
$self->render( json => { error => 'Invalid lon/lat received' } );
}
+ if ($hafas) {
+ $self->render_later;
+ Travel::Status::DE::HAFAS->new_p(
+ promise => 'Mojo::Promise',
+ user_agent => $self->ua,
+ geoSearch => {
+ lat => $lat,
+ lon => $lon
+ }
+ )->then(
+ sub {
+ my ($hafas) = @_;
+ my @candidates = map {
+ {
+ name => $_->name,
+ eva => $_->eva,
+ distance => $_->distance_m / 1000,
+ hafas => 1
+ }
+ } $hafas->results;
+ $self->render(
+ json => {
+ candidates => [@candidates],
+ }
+ );
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->render( json => { error => $err } );
+ }
+ )->wait;
+ }
else {
my @candidates = map {
{
@@ -1778,6 +1812,7 @@ sub stations_by_coordinates {
lon => $_->[0][3],
lat => $_->[0][4],
distance => $_->[1],
+ hafas => 0,
}
} Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon,
$lat, 10 );