From 3feabf250947d12e66a238654df43df81fc0d3b2 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 5 May 2019 01:30:20 +0200 Subject: 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) --- lib/DBInfoscreen/Controller/Stationboard.pm | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib') 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( -- cgit v1.2.3