Only show latest travels on landing page

This commit is contained in:
Daniel Friesel 2018-10-07 13:47:32 +02:00
parent 74fd97b4b8
commit 147e6ae849
2 changed files with 14 additions and 8 deletions

View file

@ -131,7 +131,9 @@ app->attr(
return $self->app->dbh->prepare( return $self->app->dbh->prepare(
qq{ qq{
select action_id, action_time, stations.ds100, stations.name, select action_id, action_time, stations.ds100, stations.name,
train_type, train_line, train_no, train_id, route train_type, train_line, train_no, train_id,
sched_time, real_time,
route, messages
from user_actions from user_actions
join stations on station_id = stations.id join stations on station_id = stations.id
where user_id = ? where user_id = ?
@ -441,14 +443,18 @@ helper 'get_user_id' => sub {
}; };
helper 'get_user_travels' => sub { helper 'get_user_travels' => sub {
my ($self) = @_; my ( $self, $limit ) = @_;
my $uid = $self->get_user_id; my $uid = $self->get_user_id;
$self->app->get_all_actions_query->execute($uid); my $query = $self->app->get_all_actions_query;
if ($limit) {
$query = $self->app->get_last_actions_query;
}
$query->execute($uid);
my @travels; my @travels;
while ( my @row = $self->app->get_all_actions_query->fetchrow_array ) { while ( my @row = $query->fetchrow_array ) {
my ( my (
$action, $raw_ts, $ds100, $name, $action, $raw_ts, $ds100, $name,
$train_type, $train_line, $train_no, $train_id, $train_type, $train_line, $train_no, $train_id,
@ -505,7 +511,7 @@ helper 'get_user_status' => sub {
my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $now = DateTime->now( time_zone => 'Europe/Berlin' );
my $ts = epoch_to_dt( $rows->[0][1] ); my $ts = epoch_to_dt( $rows->[0][1] );
my $checkin_station_name = decode( 'UTF-8', $rows->[0][3] ); my $checkin_station_name = decode( 'UTF-8', $rows->[0][3] );
my @route = split( qr{[|]}, decode( 'UTF-8', $rows->[0][8] // q{} ) ); my @route = split( qr{[|]}, decode( 'UTF-8', $rows->[0][10] // q{} ) );
my @route_after; my @route_after;
my $is_after = 0; my $is_after = 0;
for my $station (@route) { for my $station (@route) {

View file

@ -34,7 +34,7 @@
% } % }
</div> </div>
</div> </div>
<h1>Bisherige Fahrten</h1> <h1>Letzte Fahrten</h1>
<div class="row"> <div class="row">
<table class="striped"> <table class="striped">
<thead> <thead>
@ -46,7 +46,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
% for my $travel (get_user_travels()) { % for my $travel (get_user_travels(1)) {
% if ($travel->{completed}) { % if ($travel->{completed}) {
<tr> <tr>
<td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td> <td><%= $travel->{sched_departure}->strftime('%d.%m.%Y') %></td>