From 539b45fd2112ab27148e7e7d5b9f17132c5f6a4c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Mar 2016 21:34:30 +0100 Subject: individual list: do not show messages by default --- index.pl | 71 ++++++++++++++++++++++++++-------------- templates/individualform.html.ep | 6 +++- templates/individuallist.html.ep | 7 ++++ 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/index.pl b/index.pl index e712ee8..06fcf9c 100644 --- a/index.pl +++ b/index.pl @@ -721,11 +721,12 @@ get '/bar' => sub { }; get '/individual' => sub { - my $self = shift; - my $where_clause = '1=1'; - my $order_param = $self->param('order_by') || 'scheduled_time.d'; + my $self = shift; + my $where_clause = '1=1'; + my $order_param = $self->param('order_by') || 'scheduled_time.d'; + my $with_messages = $self->param('with_messages'); my $order; - + my $res; my %translation = Travel::Status::DE::IRIS::Result::dump_message_codes(); my ( $filter, $filter_clause ) = $self->parse_filter_args; my $dbh = $self->app->dbh; @@ -742,34 +743,56 @@ get '/individual' => sub { $where_clause .= ' and delay is not null'; } - my $res = $self->app->dbh->selectall_arrayref( - qq{ - select station_codes.name, scheduled_time, delay, is_canceled, - stations.name, train_types.name, train_no, lines.name, platform, + if ($with_messages) { + $res = $self->app->dbh->selectall_arrayref( + qq{ + select station_codes.name, scheduled_time, delay, is_canceled, + stations.name, train_types.name, train_no, lines.name, platform, + } + . join( ', ', map { "msg$_" } ( 1 .. 99 ) ) . qq{ + from departures_with_messages + join station_codes on station = station_codes.id + join stations on destination = stations.id + join train_types on train_type = train_types.id + left outer join lines on line_no = lines.id + where $where_clause + order by $order + limit 100 } - . join( ', ', map { "msg$_" } ( 1 .. 99 ) ) . qq{ - from departures_with_messages - join station_codes on station = station_codes.id - join stations on destination = stations.id - join train_types on train_type = train_types.id - left outer join lines on line_no = lines.id - where $where_clause - order by $order - limit 100 + ); + } + else { + $res = $self->app->dbh->selectall_arrayref( + qq{ + select station_codes.name, scheduled_time, delay, is_canceled, + stations.name, train_types.name, train_no, lines.name, platform + from departures + join station_codes on station = station_codes.id + join stations on destination = stations.id + join train_types on train_type = train_types.id + left outer join lines on line_no = lines.id + where $where_clause + order by $order + limit 100 + } + ); } - ); for my $i ( 0 .. $#{$res} ) { my @messages; my $row = $res->[$i]; - for my $msg ( 1 .. 99 ) { - if ( $row->[ 8 + $msg ] ) { - push( @messages, $translation{$msg} // $msg ); - } - } + $row->[0] = Travel::Status::DE::IRIS::Stations::get_station( $row->[0] )->[1]; - $row->[9] = [@messages]; + + if ($with_messages) { + for my $msg ( 1 .. 99 ) { + if ( $row->[ 8 + $msg ] ) { + push( @messages, $translation{$msg} // $msg ); + } + } + $row->[9] = [@messages]; + } } $self->render( diff --git a/templates/individualform.html.ep b/templates/individualform.html.ep index 6db815c..6e08ac0 100644 --- a/templates/individualform.html.ep +++ b/templates/individualform.html.ep @@ -2,10 +2,14 @@ Details zu individuellen Zugfahrten. Es werden maximal 100 Ergebnisse angezeigt. %= form_for individual => begin
-
+
%= select_field order_by => [['Zeit ↓', 'scheduled_time.d'], ['Zeit ↑', 'scheduled_time.a'], ['Verspätung ↓', 'delay.d'], ['Verspätung ↑', 'delay.a']]
+
+ %= check_box 'with_messages' => 1, id => 'with_messages' + +
%= include 'filterform'; % end diff --git a/templates/individuallist.html.ep b/templates/individuallist.html.ep index f7912b2..06bab3d 100644 --- a/templates/individuallist.html.ep +++ b/templates/individuallist.html.ep @@ -8,7 +8,12 @@ Keine Daten mit diesen Parametern gefunden. % else {
+% if (param('with_messages')) { +% } +% else { + +% } % for my $entry (@{ stash('list') // [] }) { % my ($station, $time, $delay, $canceled, $dest, $train_type, $train_no, $line_no, $platform, $messages) = @{$entry}; @@ -42,11 +47,13 @@ Keine Daten mit diesen Parametern gefunden. +% if (param('with_messages')) { +% } % }
BahnhofZeitZugNummerRichtungMeldungen
BahnhofZeitZugNummerRichtung
%= $dest % for my $msg (@{$messages // []}) { <%= $msg %>
% }
-- cgit v1.2.3