Skip to content
Commits on Source (3)
...@@ -279,9 +279,11 @@ sub startup { ...@@ -279,9 +279,11 @@ sub startup {
$r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route'); $r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route');
$r->get('/map/:tripid/:lineno')->to('map#route'); $r->get('/map/:tripid/:lineno')->to('map#route');
$r->get( '/z/:train/*station' => 'train_at_station' ) $r->get( '/z/:train/*station' => [ format => [ 'html', 'json' ] ] )
->to('stationboard#station_train_details'); ->to( 'stationboard#station_train_details', format => undef )
$r->get( '/z/:train' => 'train' )->to('stationboard#train_details'); ->name('train_at_station');
$r->get( '/z/:train' => [ format => [ 'html', 'json' ] ] )
->to( 'stationboard#train_details', format => undef )->name('train');
$self->defaults( layout => 'app' ); $self->defaults( layout => 'app' );
......
...@@ -937,27 +937,36 @@ sub render_train { ...@@ -937,27 +937,36 @@ sub render_train {
# Defer rendering until all requests have completed # Defer rendering until all requests have completed
Mojo::Promise->all(@requests)->then( Mojo::Promise->all(@requests)->then(
sub { sub {
$self->render( $self->respond_to(
$template // '_train_details', json => {
description => sprintf( json => {
'%s %s%s%s nach %s', departure => $departure,
$departure->{train_type}, station_name => $station_name,
$departure->{train_line} // $departure->{train_no}, },
$departure->{origin} ? ' von ' : q{}, },
$departure->{origin} // q{}, any => {
$departure->{destination} // 'unbekannt' template => $template // '_train_details',
), description => sprintf(
departure => $departure, '%s %s%s%s nach %s',
linetype => $linetype, $departure->{train_type},
dt_now => DateTime->now( time_zone => 'Europe/Berlin' ), $departure->{train_line} // $departure->{train_no},
station_name => $station_name, $departure->{origin} ? ' von ' : q{},
nav_link => $departure->{origin} // q{},
$self->url_for( 'station', station => $station_name )->query( $departure->{destination} // 'unbekannt'
{ ),
detailed => $self->param('detailed'), departure => $departure,
hafas => $self->param('hafas') linetype => $linetype,
} dt_now => DateTime->now( time_zone => 'Europe/Berlin' ),
), station_name => $station_name,
nav_link =>
$self->url_for( 'station', station => $station_name )
->query(
{
detailed => $self->param('detailed'),
hafas => $self->param('hafas')
}
),
},
); );
} }
)->wait; )->wait;
...@@ -973,6 +982,10 @@ sub station_train_details { ...@@ -973,6 +982,10 @@ sub station_train_details {
delete $self->stash->{layout}; delete $self->stash->{layout};
} }
if ( $station =~ s{ [.] json $ }{}x ) {
$self->stash( format => 'json' );
}
my %opt = ( my %opt = (
cache_iris_main => $self->app->cache_iris_main, cache_iris_main => $self->app->cache_iris_main,
cache_iris_rt => $self->app->cache_iris_rt, cache_iris_rt => $self->app->cache_iris_rt,
...@@ -1134,7 +1147,10 @@ sub train_details { ...@@ -1134,7 +1147,10 @@ sub train_details {
} }
my $service = 'DB'; my $service = 'DB';
if ( $hafas ne '1' and Travel::Status::DE::HAFAS::get_service($hafas) ) { if ( $hafas
and $hafas ne '1'
and Travel::Status::DE::HAFAS::get_service($hafas) )
{
$opt{service} = $hafas; $opt{service} = $hafas;
} }
...@@ -1300,34 +1316,52 @@ sub train_details { ...@@ -1300,34 +1316,52 @@ sub train_details {
$res->{details} = [@him_details]; $res->{details} = [@him_details];
} }
$self->render( $self->respond_to(
$self->param('ajax') ? '_train_details' : 'train_details', json => {
description => sprintf( json => {
'%s %s%s%s nach %s', journey => $journey,
$res->{train_type}, },
$res->{train_line} // $res->{train_no}, },
$res->{origin} ? ' von ' : q{}, any => {
$res->{origin} // q{}, template => $self->param('ajax')
$res->{destination} // 'unbekannt' ? '_train_details'
), : 'train_details',
departure => $res, description => sprintf(
linetype => $linetype, '%s %s%s%s nach %s',
dt_now => DateTime->now( time_zone => 'Europe/Berlin' ), $res->{train_type},
$res->{train_line} // $res->{train_no},
$res->{origin} ? ' von ' : q{},
$res->{origin} // q{},
$res->{destination} // 'unbekannt'
),
departure => $res,
linetype => $linetype,
dt_now => DateTime->now( time_zone => 'Europe/Berlin' ),
},
); );
} }
)->catch( )->catch(
sub { sub {
my ($e) = @_; my ($e) = @_;
if ($e) { if ($e) {
$self->render( $self->respond_to(
'exception', json => {
message => $e, json => {
exception => undef, error => $e,
snapshot => {} },
status => 500,
},
any => {
template => 'exception',
message => $e,
exception => undef,
snapshot => {},
status => 500,
},
); );
} }
else { else {
$self->render('not_found'); $self->render( 'not_found', status => 404 );
} }
} }
)->wait; )->wait;
......