summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-03-29 21:39:05 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-03-29 21:39:05 +0200
commitdd87d4e438674c86c11221617e5273f7534fc865 (patch)
treea30cdddd6e60a5b20ac0bf22969b73a87edee9dc
parentf8aa6ff141ac37aa8655277c102f1b58cfc776ad (diff)
add list of individual arrivals / departures
-rw-r--r--index.pl49
-rw-r--r--public/css/default.css24
-rw-r--r--templates/individualform.html.ep9
-rw-r--r--templates/individuallist.html.ep49
-rw-r--r--templates/intro.html.ep2
5 files changed, 133 insertions, 0 deletions
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 @@
+<div>
+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';
+<br/>
+%= 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) {
+<div class="error">
+Keine Daten mit diesen Parametern gefunden.
+</div>
+% }
+% else {
+<div class="individuallist">
+<table>
+<tr><th>Bahnhof</th><th>Zeit</th><th>Zug</th><th>Nummer</th><th>Richtung</th></tr>
+% for my $entry (@{ stash('list') // [] }) {
+% my ($station, $time, $delay, $canceled, $dest, $train_type, $train_no, $line_no, $platform) = @{$entry};
+<tr>
+<td class="station">
+%= $station
+</td>
+<td class="time">
+%= $time
+% if (defined $delay) {
+% if ($delay < 0) {
+<span class="undelay"><%= $delay %></span>
+% }
+% elsif ($delay == 0) {
+<span class="delay0">+0</span>
+% }
+% else {
+<span class="delay">+<%= $delay %></span>
+% }
+% }
+</td>
+<td class="train">
+%= $train_type;
+
+% if ($line_no) {
+%= $line_no;
+%}
+</td>
+<td class="train_no">
+%= $train_no
+</td>
+<td class="destination">
+%= $dest
+</td>
+</tr>
+% }
+</table>
+</div>
+% }
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
<br/>
<b>Top-Liste</b>:
%= include 'topform';
+<b>Einzelne Züge</b>
+%= include 'individualform';
</div>