diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-05-05 01:30:20 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-05-05 01:30:20 +0200 |
commit | 3feabf250947d12e66a238654df43df81fc0d3b2 (patch) | |
tree | 3b7969141fe6923a1d1a9f21fa672e967a2fa45e /lib/DBInfoscreen/Controller | |
parent | 7ee9f881343a9452885c7fd30edbad14150fda42 (diff) |
Move moreinfo to ajax-requested sub-template
This decreases the DOM size and allows for future speed improvements
(the backend no longer needs to precalculate routes etc for all trains)
Diffstat (limited to 'lib/DBInfoscreen/Controller')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index c13ed48..18c137f 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -5,6 +5,7 @@ use Mojo::Base 'Mojolicious::Controller'; # License: 2-Clause BSD use Cache::File; +use DateTime; use File::Slurp qw(read_file write_file); use List::Util qw(max); use List::MoreUtils qw(); @@ -783,6 +784,45 @@ sub handle_request { format => 'text', ); } + elsif ( my $train = $self->param('train') ) { + delete $self->stash->{layout}; + + my ($departure) = grep { + $train eq ( $_->{train_type} // '' ) . ' ' + . ( $_->{train_no} // $_->{train} // '' ) + } @departures; + + if ($departure) { + + my $linetype = 'bahn'; + if ( $departure->{train_type} eq 'S' ) { + $linetype = 'sbahn'; + } + elsif ($departure->{train_type} eq 'IC' + or $departure->{train_type} eq 'ICE' + or $departure->{train_type} eq 'EC' + or $departure->{train_type} eq 'EN' ) + { + $linetype = 'fern'; + } + elsif ($departure->{train_type} eq 'THA' + or $departure->{train_type} eq 'FLX' + or $departure->{train_type} eq 'NJ' ) + { + $linetype = 'ext'; + } + + $self->render( + '_train_details', + departure => $departure, + linetype => $linetype, + dt_now => DateTime->now( time_zone => 'Europe/Berlin' ), + ); + } + else { + $self->render('not_found'); + } + } else { my $station_name = $data->{station_name} // $station; $self->render( |