diff options
author | Daniel Friesel <derf@finalrewind.org> | 2012-08-12 23:13:46 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2012-08-12 23:13:46 +0200 |
commit | 56289eb50022a543af172a7896c1fed4aa27d6cb (patch) | |
tree | 47d47a356f6befc70c75851a3a2490e1f140adf0 | |
parent | 6457471f225e446e52601ebe66208a4e7a3bef4e (diff) |
allow filtering by platform
-rw-r--r-- | cgi/index.pl | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/cgi/index.pl b/cgi/index.pl index 0520561..7bc3587 100644 --- a/cgi/index.pl +++ b/cgi/index.pl @@ -30,6 +30,8 @@ sub handle_request { my $station = $self->stash('station'); my $via = $self->stash('via'); + my @platforms = split(/,/, $self->param('platforms') // q{}); + $self->stash( departures => [] ); $self->stash( title => 'db-fakedisplay' ); $self->stash( version => $VERSION ); @@ -48,12 +50,16 @@ sub handle_request { } for my $result (@results) { + my $platform = ( split( / /, $result->platform ) )[0]; if ($via) { my @route = $result->route; if (not( grep { $_ =~ m{$via}io } @route )) { next; } } + if (@platforms and not grep { $_ eq $platform } @platforms) { + next; + } push( @departures, { @@ -61,7 +67,7 @@ sub handle_request { train => $result->train, via => [ $result->route_interesting(3) ], destination => $result->destination, - platform => ( split( / /, $result->platform ) )[0], + platform => $platform, info => $result->info, } ); @@ -79,12 +85,24 @@ get '/_redirect' => sub { my $self = shift; my $station = $self->param('station'); my $via = $self->param('via'); + my $params = $self->req->params; + + $params->remove('station'); + $params->remove('via'); + + for my $param (qw(platforms)) { + if (not $params->param($param)) { + $params->remove($param); + } + } + + $params = $params->to_string; if ($via) { - $self->redirect_to("/${station}/${via}"); + $self->redirect_to("/${station}/${via}?${params}"); } else { - $self->redirect_to("/${station}"); + $self->redirect_to("/${station}?${params}"); } }; @@ -307,6 +325,10 @@ __DATA__ <span class="fielddesc fieldoptional">only display routes via</span> <%= text_field 'via' %> (optional) + <br/> + <span class="fielddesc fieldoptional">on platforms</span> + <%= text_field 'platforms' %> + (optional) <%= submit_button 'Display' %> </p> <% end %> |