From 536ee9240fa3fc73a4b38d862d317b1806a45911 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 28 Sep 2015 22:56:39 +0200 Subject: candidate foo --- index.pl | 30 ++++++++++++++++++++---------- templates/main.html.ep | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/index.pl b/index.pl index 79c1470..e53c063 100644 --- a/index.pl +++ b/index.pl @@ -128,6 +128,10 @@ sub get_results { if ( $status->can('identified_data') ) { ( $data->{id_name}, $data->{id_stop} ) = $status->identified_data; } + if ( $status->errstr and $status->can('name_candidates') ) { + $data->{name_candidates} = [ $status->name_candidates ]; + $data->{place_candidates} = [ $status->place_candidates ]; + } $cache->freeze( $sstr, $data ); } @@ -142,11 +146,12 @@ sub handle_request { my $no_lines = $self->param('no_lines'); my $frontend = $self->param('frontend') // 'png'; my $backend = $self->param('backend') // $default{backend}; - my $errstr; + my ( $data, $errstr ); if ( ( $city and $stop ) or ( $backend eq 'aseag' and $stop ) ) { - $errstr = get_results( $self->param('backend') // $default{backend}, - $city, $stop )->{errstr}; + ( $data, $errstr ) + = get_results( $self->param('backend') // $default{backend}, + $city, $stop ); } if ( not $no_lines or $no_lines < 1 or $no_lines > 40 ) { @@ -162,12 +167,14 @@ sub handle_request { $self->render( 'main', - city => $city, - stop => $stop, - version => $VERSION, - frontend => $frontend, - errstr => $errstr, - title => $stop + city => $city, + stop => $stop, + version => $VERSION, + frontend => $frontend, + errstr => $errstr, + name_candidates => $data->{name_candidates}, + place_candidates => $data->{place_candidates}, + title => $stop ? "departures for ${city} ${stop}" : "vrr-infoscreen ${VERSION}", ); @@ -496,7 +503,7 @@ sub render_image { my ( $line, $destination, $etr, undef ) = @{$d}; - $line = substr($line, 0, 4); + $line = substr( $line, 0, 4 ); $png->draw_at( 0, $line ); $png->draw_at( 25, $destination ); @@ -540,6 +547,9 @@ helper 'hafas_service_list' => sub { return @hafas_services; }; +helper 'handle_no_results' => sub { +}; + get '/_redirect' => sub { my $self = shift; my $city = $self->param('city') // q{}; diff --git a/templates/main.html.ep b/templates/main.html.ep index 589f690..7ecc456 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -105,13 +105,25 @@ other German transit networks.
Stadt
- %= text_field 'city' + % if (stash('place_candidates') and @{ stash('place_candidates') } ) { + % my @candidates = map { [ $_, $_ ] } @{ stash('place_candidates') }; + %= select_field city => \@candidates + % } + % else { + %= text_field 'city' + % }
Haltestelle
- %= text_field 'stop' + % if (stash('name_candidates') and @{ stash('name_candidates') } ) { + % my @candidates = map { [ $_, $_ ] } @{ stash('name_candidates') }; + %= select_field stop => \@candidates + % } + % else { + %= text_field 'stop' + % } %= submit_button 'Display'
-- cgit v1.2.3 From c3395f3e7a17c8455742f2b9d505342a0f5e21ac Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 28 Sep 2015 23:06:43 +0200 Subject: well, that was stupid --- index.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.pl b/index.pl index e53c063..687804d 100644 --- a/index.pl +++ b/index.pl @@ -146,11 +146,10 @@ sub handle_request { my $no_lines = $self->param('no_lines'); my $frontend = $self->param('frontend') // 'png'; my $backend = $self->param('backend') // $default{backend}; - my ( $data, $errstr ); + my $data; if ( ( $city and $stop ) or ( $backend eq 'aseag' and $stop ) ) { - ( $data, $errstr ) - = get_results( $self->param('backend') // $default{backend}, + $data = get_results( $self->param('backend') // $default{backend}, $city, $stop ); } @@ -171,7 +170,7 @@ sub handle_request { stop => $stop, version => $VERSION, frontend => $frontend, - errstr => $errstr, + errstr => $data->{errstr}, name_candidates => $data->{name_candidates}, place_candidates => $data->{place_candidates}, title => $stop -- cgit v1.2.3