From dd87d4e438674c86c11221617e5273f7534fc865 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 29 Mar 2015 21:39:05 +0200 Subject: add list of individual arrivals / departures --- index.pl | 49 ++++++++++++++++++++++++++++++++++++++++ public/css/default.css | 24 ++++++++++++++++++++ templates/individualform.html.ep | 9 ++++++++ templates/individuallist.html.ep | 49 ++++++++++++++++++++++++++++++++++++++++ templates/intro.html.ep | 2 ++ 5 files changed, 133 insertions(+) create mode 100644 templates/individualform.html.ep create mode 100644 templates/individuallist.html.ep diff --git a/index.pl b/index.pl index 3334f72..50a0c19 100644 --- a/index.pl +++ b/index.pl @@ -641,6 +641,55 @@ get '/bar' => sub { return; }; +get '/individual' => sub { + my $self = shift; + my $where_clause = '1=1'; + my $order_param = $self->param('order_by') || 'scheduled_time.d'; + my $order; + + my ( $filter, $filter_clause ) = $self->parse_filter_args; + my $dbh = $self->app->dbh; + $where_clause .= $filter_clause; + + given ($order_param) { + when ('scheduled_time.d') { $order = 'scheduled_time desc' } + when ('scheduled_time.a') { $order = 'scheduled_time asc' } + when ('delay.d') { $order = 'delay desc' } + when ('delay.a') { $order = 'delay asc' } + } + + if ( $order_param =~ m{ ^ delay }x ) { + $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 + 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 1000 + } + ); + + for my $row ( @{$res} ) { + $row->[0] + = Travel::Status::DE::IRIS::Stations::get_station( $row->[0] )->[1]; + $row->[4] = decode( 'utf-8', $row->[4] ); + } + + $self->render( + 'individuallist', + title => 'foo', + list => $res, + ); +}; + get '/top' => sub { my $self = shift; my $where_clause = '1=1'; diff --git a/public/css/default.css b/public/css/default.css index 2b081e2..b6f7ac8 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -50,6 +50,30 @@ div.field div.desc { padding-right: 0.5em; } +div.individuallist table { + margin-top: 1em; + border-collapse: collapse; +} + +div.individuallist th, +div.individuallist td { + border: 1px solid #bbbbbb; + margin: 0; + padding: 0.2em; +} + +div.individuallist span.undelay { + color: #008800; +} + +div.individuallist span.delay0 { + color: #888888; +} + +div.individuallist span.delay { + color: #880000; +} + svg { font: 10px sans-serif; } diff --git a/templates/individualform.html.ep b/templates/individualform.html.ep new file mode 100644 index 0000000..2e5119f --- /dev/null +++ b/templates/individualform.html.ep @@ -0,0 +1,9 @@ +
+Es werden nur maximal 1000 Ergebnisse angezeigt. +%= form_for individual => begin +Sortieren nach: +%= select_field order_by => [['Zeit ↓', 'scheduled_time.d'], ['Zeit ↑', 'scheduled_time.a'], ['Verspätung ↓', 'delay.d'], ['Verspätung ↑', 'delay.a']] +%= submit_button 'Go'; +
+%= include 'filterform'; +% end diff --git a/templates/individuallist.html.ep b/templates/individuallist.html.ep new file mode 100644 index 0000000..2c57ca3 --- /dev/null +++ b/templates/individuallist.html.ep @@ -0,0 +1,49 @@ +%= include 'individualform'; + +% if (@{$list} == 0) { +
+Keine Daten mit diesen Parametern gefunden. +
+% } +% else { +
+ + +% for my $entry (@{ stash('list') // [] }) { +% my ($station, $time, $delay, $canceled, $dest, $train_type, $train_no, $line_no, $platform) = @{$entry}; + + + + + + + +% } +
BahnhofZeitZugNummerRichtung
+%= $station + +%= $time +% if (defined $delay) { +% if ($delay < 0) { +<%= $delay %> +% } +% elsif ($delay == 0) { ++0 +% } +% else { ++<%= $delay %> +% } +% } + +%= $train_type; + +% if ($line_no) { +%= $line_no; +%} + +%= $train_no + +%= $dest +
+
+% } diff --git a/templates/intro.html.ep b/templates/intro.html.ep index 0ddbf4e..9ce6f6f 100644 --- a/templates/intro.html.ep +++ b/templates/intro.html.ep @@ -57,4 +57,6 @@ dabei ist ein Zug durchschnittlich
Top-Liste: %= include 'topform'; +Einzelne Züge +%= include 'individualform';
-- cgit v1.2.3