add JSON export for history

This commit is contained in:
Daniel Friesel 2019-03-09 14:35:23 +01:00
parent 6f1b488d26
commit 3ae14d47f9
2 changed files with 56 additions and 38 deletions

View file

@ -1184,7 +1184,16 @@ get '/account' => sub {
get '/history' => sub { get '/history' => sub {
my ($self) = @_; my ($self) = @_;
$self->render('history'); $self->respond_to(
json => { json => [ $self->get_user_travels(0) ] },
any => { template => 'history' }
);
};
get '/history.json' => sub {
my ($self) = @_;
$self->render( json => [ $self->get_user_travels(0) ] );
}; };
get '/export.json' => sub { get '/export.json' => sub {

View file

@ -1,40 +1,49 @@
<h1>Bisherige Fahrten</h1> <h1>Bisherige Fahrten</h1>
<div class="row"> <div class="row">
<table class="striped"> <div class="col s12">
<thead> <ul>
<tr> <li><a href="/history.json">JSON-Export</a> (Das Datenlayout ist noch nicht final)</li>
<th>Datum</th> </ul>
<th>Zug</th> </div>
<th>Strecke</th> </div>
<th>Abfahrt</th> <div class="row">
<th>Ankunft</th> <div class="col s12">
</tr> <table class="striped">
</thead> <thead>
<tbody> <tr>
% for my $travel (get_user_travels(0)) { <th>Datum</th>
% if ($travel->{completed}) { <th>Zug</th>
<tr> <th>Strecke</th>
<td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td> <th>Abfahrt</th>
<td><%= $travel->{type} %> <%= $travel->{line} // '' %> <%= $travel->{no} %></td> <th>Ankunft</th>
<td><%= $travel->{from_name} %> → <%= $travel->{to_name} %></td> </tr>
<td><%= $travel->{rt_departure}->strftime('%H:%M') %> </thead>
% if ($travel->{sched_departure} != $travel->{rt_departure}) { <tbody>
(+<%= ($travel->{rt_departure}->epoch - $travel->{sched_departure}->epoch) / 60 %>) % for my $travel (get_user_travels(0)) {
% } % if ($travel->{completed}) {
</td> <tr>
<td> <td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td>
% if ($travel->{rt_arrival}->epoch == 0 and $travel->{sched_arrival}->epoch == 0) { <td><%= $travel->{type} %> <%= $travel->{line} // '' %> <%= $travel->{no} %></td>
<i class="material-icons">timer_off</i> <td><%= $travel->{from_name} %> → <%= $travel->{to_name} %></td>
% } else { <td><%= $travel->{rt_departure}->strftime('%H:%M') %>
%= $travel->{rt_arrival}->strftime('%H:%M'); % if ($travel->{sched_departure} != $travel->{rt_departure}) {
% if ($travel->{sched_arrival} != $travel->{rt_arrival}) { (+<%= ($travel->{rt_departure}->epoch - $travel->{sched_departure}->epoch) / 60 %>)
(+<%= ($travel->{rt_arrival}->epoch - $travel->{sched_arrival}->epoch) / 60 %>) % }
% } </td>
% } <td>
</td> % if ($travel->{rt_arrival}->epoch == 0 and $travel->{sched_arrival}->epoch == 0) {
</tr> <i class="material-icons">timer_off</i>
% } % } else {
% } %= $travel->{rt_arrival}->strftime('%H:%M');
</tbody> % if ($travel->{sched_arrival} != $travel->{rt_arrival}) {
</table> (+<%= ($travel->{rt_arrival}->epoch - $travel->{sched_arrival}->epoch) / 60 %>)
% }
% }
</td>
</tr>
% }
% }
</tbody>
</table>
</div>
</div> </div>