show cancelled trains in history
This commit is contained in:
parent
01df965d66
commit
531f3b0a68
3 changed files with 80 additions and 19 deletions
33
index.pl
33
index.pl
|
@ -808,6 +808,11 @@ helper 'get_user_travels' => sub {
|
||||||
else {
|
else {
|
||||||
$query->execute($uid);
|
$query->execute($uid);
|
||||||
}
|
}
|
||||||
|
my @match_actions = ( $action_type{checkout}, $action_type{checkin} );
|
||||||
|
if ( $opt{cancelled} ) {
|
||||||
|
@match_actions
|
||||||
|
= ( $action_type{cancelled_to}, $action_type{cancelled_from} );
|
||||||
|
}
|
||||||
|
|
||||||
my @travels;
|
my @travels;
|
||||||
my $prev_action = 0;
|
my $prev_action = 0;
|
||||||
|
@ -823,7 +828,9 @@ helper 'get_user_travels' => sub {
|
||||||
$raw_route = decode( 'UTF-8', $raw_route );
|
$raw_route = decode( 'UTF-8', $raw_route );
|
||||||
$raw_messages = decode( 'UTF-8', $raw_messages );
|
$raw_messages = decode( 'UTF-8', $raw_messages );
|
||||||
|
|
||||||
if ( $action == $action_type{checkout} ) {
|
if ( $action == $match_actions[0]
|
||||||
|
or ( $opt{checkout_epoch} and $raw_ts == $opt{checkout_epoch} ) )
|
||||||
|
{
|
||||||
push(
|
push(
|
||||||
@travels,
|
@travels,
|
||||||
{
|
{
|
||||||
|
@ -843,8 +850,13 @@ helper 'get_user_travels' => sub {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
elsif ( $action == $action_type{checkin}
|
elsif (
|
||||||
and $prev_action == $action_type{checkout} )
|
(
|
||||||
|
$action == $match_actions[1]
|
||||||
|
and $prev_action == $match_actions[0]
|
||||||
|
)
|
||||||
|
or ( $opt{checkin_epoch} and $raw_ts == $opt{checkin_epoch} )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
my $ref = $travels[-1];
|
my $ref = $travels[-1];
|
||||||
$ref->{from_name} = $name;
|
$ref->{from_name} = $name;
|
||||||
|
@ -866,6 +878,11 @@ helper 'get_user_travels' => sub {
|
||||||
}
|
}
|
||||||
$ref->{messages} = [ reverse @parsed_messages ];
|
$ref->{messages} = [ reverse @parsed_messages ];
|
||||||
}
|
}
|
||||||
|
if ( $opt{checkin_epoch}
|
||||||
|
and $action == $action_type{cancelled_from} )
|
||||||
|
{
|
||||||
|
$ref->{cancelled} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$prev_action = $action;
|
$prev_action = $action;
|
||||||
}
|
}
|
||||||
|
@ -1442,17 +1459,21 @@ get '/account' => sub {
|
||||||
|
|
||||||
get '/history' => sub {
|
get '/history' => sub {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
my $cancelled = $self->param('cancelled') ? 1 : 0;
|
||||||
|
|
||||||
$self->respond_to(
|
$self->respond_to(
|
||||||
json => { json => [ $self->get_user_travels ] },
|
json =>
|
||||||
any => { template => 'history' }
|
{ json => [ $self->get_user_travels( cancelled => $cancelled ) ] },
|
||||||
|
any => { template => 'history' }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
get '/history.json' => sub {
|
get '/history.json' => sub {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
my $cancelled = $self->param('cancelled') ? 1 : 0;
|
||||||
|
|
||||||
$self->render( json => [ $self->get_user_travels ] );
|
$self->render(
|
||||||
|
json => [ $self->get_user_travels( cancelled => $cancelled ) ] );
|
||||||
};
|
};
|
||||||
|
|
||||||
get '/journey/:id' => sub {
|
get '/journey/:id' => sub {
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
|
% if (param('cancelled')) {
|
||||||
|
<h1>Ausgefallene Fahrten</h1>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s12">
|
||||||
|
<ul>
|
||||||
|
<li><a href="/history.json?cancelled=1">JSON-Export</a> (Das Datenlayout ist noch nicht final)</li>
|
||||||
|
<li><a href="/history">Reguläre Zugfahrten</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
% }
|
||||||
|
% else {
|
||||||
<h1>Bisherige Fahrten</h1>
|
<h1>Bisherige Fahrten</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/history.json">JSON-Export</a> (Das Datenlayout ist noch nicht final)</li>
|
<li><a href="/history.json">JSON-Export</a> (Das Datenlayout ist noch nicht final)</li>
|
||||||
|
<li><a href="/history?cancelled=1">Ausgefallene Züge</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
% }
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<table class="striped">
|
<table class="striped">
|
||||||
|
@ -19,25 +33,36 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
% for my $travel (get_user_travels()) {
|
% for my $travel (get_user_travels(cancelled => (param('cancelled') ? 1 : 0))) {
|
||||||
% if ($travel->{completed}) {
|
% if ($travel->{completed}) {
|
||||||
% my $detail_link = '/journey/' . current_user()->{id} . '-' . $travel->{checkin}->epoch . '-' . $travel->{checkout}->epoch;
|
% my $detail_link = '/journey/' . current_user()->{id} . '-' . $travel->{checkin}->epoch . '-' . $travel->{checkout}->epoch;
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td>
|
<td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td>
|
||||||
<td><a href="<%= $detail_link %>"><%= $travel->{type} %> <%= $travel->{line} // '' %> <%= $travel->{no} %></a></td>
|
<td><a href="<%= $detail_link %>"><%= $travel->{type} %> <%= $travel->{line} // '' %> <%= $travel->{no} %></a></td>
|
||||||
<td><a href="<%= $detail_link %>"><%= $travel->{from_name} %> → <%= $travel->{to_name} %></a></td>
|
<td><a href="<%= $detail_link %>"><%= $travel->{from_name} %> → <%= $travel->{to_name} %></a></td>
|
||||||
<td><%= $travel->{rt_departure}->strftime('%H:%M') %>
|
<td>
|
||||||
% if ($travel->{sched_departure} != $travel->{rt_departure}) {
|
% if (param('cancelled')) {
|
||||||
(+<%= ($travel->{rt_departure}->epoch - $travel->{sched_departure}->epoch) / 60 %>)
|
%= $travel->{sched_departure}->strftime('%H:%M')
|
||||||
|
% }
|
||||||
|
% else {
|
||||||
|
<%= $travel->{rt_departure}->strftime('%H:%M') %>
|
||||||
|
% if ($travel->{sched_departure} != $travel->{rt_departure}) {
|
||||||
|
(+<%= ($travel->{rt_departure}->epoch - $travel->{sched_departure}->epoch) / 60 %>)
|
||||||
|
% }
|
||||||
% }
|
% }
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
% if ($travel->{rt_arrival}->epoch == 0 and $travel->{sched_arrival}->epoch == 0) {
|
% if (param('cancelled') and $travel->{sched_arrival}->epoch != 0) {
|
||||||
<i class="material-icons">timer_off</i>
|
%= $travel->{sched_arrival}->strftime('%H:%M')
|
||||||
% } else {
|
% }
|
||||||
%= $travel->{rt_arrival}->strftime('%H:%M');
|
% else {
|
||||||
% if ($travel->{sched_arrival} != $travel->{rt_arrival}) {
|
% if ($travel->{rt_arrival}->epoch == 0 and $travel->{sched_arrival}->epoch == 0) {
|
||||||
(+<%= ($travel->{rt_arrival}->epoch - $travel->{sched_arrival}->epoch) / 60 %>)
|
<i class="material-icons">timer_off</i>
|
||||||
|
% } else {
|
||||||
|
%= $travel->{rt_arrival}->strftime('%H:%M');
|
||||||
|
% if ($travel->{sched_arrival} != $travel->{rt_arrival}) {
|
||||||
|
(+<%= ($travel->{rt_arrival}->epoch - $travel->{sched_arrival}->epoch) / 60 %>)
|
||||||
|
% }
|
||||||
% }
|
% }
|
||||||
% }
|
% }
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -14,7 +14,12 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<p>
|
<p>
|
||||||
Fahrt von
|
% if ($journey->{cancelled}) {
|
||||||
|
Ausgefallene Fahrt von
|
||||||
|
% }
|
||||||
|
% else {
|
||||||
|
Fahrt von
|
||||||
|
% }
|
||||||
<b><%= $journey->{from_name} %></b>
|
<b><%= $journey->{from_name} %></b>
|
||||||
nach
|
nach
|
||||||
<b><%= $journey->{to_name} %></b>
|
<b><%= $journey->{to_name} %></b>
|
||||||
|
@ -34,7 +39,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Abfahrt</th>
|
<th scope="row">Abfahrt</th>
|
||||||
<td>
|
<td>
|
||||||
% if ($journey->{rt_departure} != $journey->{sched_departure}) {
|
% if ($journey->{cancelled}) {
|
||||||
|
<i class="material-icons">cancel</i>
|
||||||
|
(Plan: <%= $journey->{sched_departure}->strftime('%H:%M'); %>)
|
||||||
|
% }
|
||||||
|
% elsif ($journey->{rt_departure} != $journey->{sched_departure}) {
|
||||||
%= $journey->{rt_departure}->strftime('%H:%M');
|
%= $journey->{rt_departure}->strftime('%H:%M');
|
||||||
(+<%= ($journey->{rt_departure}->epoch - $journey->{sched_departure}->epoch) / 60 %>,
|
(+<%= ($journey->{rt_departure}->epoch - $journey->{sched_departure}->epoch) / 60 %>,
|
||||||
Plan: <%= $journey->{sched_departure}->strftime('%H:%M'); %>)
|
Plan: <%= $journey->{sched_departure}->strftime('%H:%M'); %>)
|
||||||
|
@ -47,7 +56,13 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Ankunft</th>
|
<th scope="row">Ankunft</th>
|
||||||
<td>
|
<td>
|
||||||
% if ($journey->{rt_arrival}->epoch == 0 and $journey->{sched_arrival}->epoch == 0) {
|
% if ($journey->{cancelled}) {
|
||||||
|
<i class="material-icons">cancel</i>
|
||||||
|
% if ($journey->{sched_arrival}->epoch != 0) {
|
||||||
|
(Plan: <%= $journey->{sched_arrival}->strftime('%H:%M'); %>)
|
||||||
|
% }
|
||||||
|
% }
|
||||||
|
% elsif ($journey->{rt_arrival}->epoch == 0 and $journey->{sched_arrival}->epoch == 0) {
|
||||||
<i class="material-icons">timer_off</i>
|
<i class="material-icons">timer_off</i>
|
||||||
% }
|
% }
|
||||||
% elsif ($journey->{rt_arrival} != $journey->{sched_arrival}) {
|
% elsif ($journey->{rt_arrival} != $journey->{sched_arrival}) {
|
||||||
|
|
Loading…
Reference in a new issue