summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-03-21 21:34:30 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-03-21 21:34:30 +0100
commit539b45fd2112ab27148e7e7d5b9f17132c5f6a4c (patch)
tree1e8bce36f90fcbdecbed97f5ebef071bf16ce6d0
parent698107a69aad086344897618e050d018a3829af5 (diff)
individual list: do not show messages by default
-rw-r--r--index.pl71
-rw-r--r--templates/individualform.html.ep6
-rw-r--r--templates/individuallist.html.ep7
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
<div class="row">
- <div class="input-field col s12">
+ <div class="input-field col s6">
<label class="active">Sortierung</label>
%= select_field order_by => [['Zeit ↓', 'scheduled_time.d'], ['Zeit ↑', 'scheduled_time.a'], ['Verspätung ↓', 'delay.d'], ['Verspätung ↑', 'delay.a']]
</div>
+ <div class="input-field col s6 checkbox">
+ %= check_box 'with_messages' => 1, id => 'with_messages'
+ <label for="with_messages">Meldungen anzeigen</label>
+ </div>
</div>
%= 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 {
<div class="individuallist">
<table>
+% if (param('with_messages')) {
<tr><th>Bahnhof</th><th>Zeit</th><th>Zug</th><th>Nummer</th><th>Richtung</th><th>Meldungen</th></tr>
+% }
+% else {
+<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, $messages) = @{$entry};
<tr>
@@ -42,11 +47,13 @@ Keine Daten mit diesen Parametern gefunden.
<td class="destination">
%= $dest
</td>
+% if (param('with_messages')) {
<td class="messages">
% for my $msg (@{$messages // []}) {
<%= $msg %><br/>
% }
</td>
+% }
</tr>
% }
</table>