summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-10-13 14:35:05 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-10-13 14:35:05 +0200
commit33fd338bc54f81338d32c6eba6c59f3b35dbe545 (patch)
tree442afe03126eab4370d8c1479309fb260e3230b1 /index.pl
parentec1842054c0057c71d747282a88225621574caa5 (diff)
Only show latest actions on main page
Diffstat (limited to 'index.pl')
-rwxr-xr-xindex.pl53
1 files changed, 27 insertions, 26 deletions
diff --git a/index.pl b/index.pl
index 02fe8fe..24cdc91 100755
--- a/index.pl
+++ b/index.pl
@@ -119,7 +119,7 @@ app->attr(
from user_actions
join stations on station_id = stations.id
where user_id = ?
- order by action_time asc
+ order by action_time desc
}
);
}
@@ -447,9 +447,9 @@ helper 'get_user_travels' => sub {
my $uid = $self->get_user_id;
my $query = $self->app->get_all_actions_query;
- #if ($limit) {
- # $query = $self->app->get_last_actions_query;
- #}
+ if ($limit) {
+ $query = $self->app->get_last_actions_query;
+ }
$query->execute($uid);
my @travels;
@@ -465,38 +465,39 @@ helper 'get_user_travels' => sub {
$raw_route = decode( 'UTF-8', $raw_route );
$raw_messages = decode( 'UTF-8', $raw_messages );
- if ( $action == $action_type{checkin} ) {
+ if ( $action == $action_type{checkout} ) {
push(
@travels,
{
- from_name => $name,
- sched_departure => epoch_to_dt($raw_sched_ts),
- rt_departure => epoch_to_dt($raw_real_ts),
- type => $train_type,
- line => $train_line,
- no => $train_no,
- messages => [ split( qr{[|]}, $raw_messages ) ],
- route => [ split( qr{[|]}, $raw_route ) ],
- completed => 0,
+ to_name => $name,
+ sched_arrival => epoch_to_dt($raw_sched_ts),
+ rt_arrival => epoch_to_dt($raw_real_ts),
+ type => $train_type,
+ line => $train_line,
+ no => $train_no,
+ messages => $raw_messages
+ ? [ split( qr{[|]}, $raw_messages ) ]
+ : undef,
+ route => $raw_route ? [ split( qr{[|]}, $raw_route ) ]
+ : undef,
+ completed => 0,
}
);
}
- elsif ( $action == $action_type{checkout} ) {
+ elsif ( $action == $action_type{checkin} and @travels ) {
my $ref = $travels[-1];
- $ref->{to_name} = $name;
- $ref->{completed} = 1;
-
- # if train_no is undef, we have a forced checkout without data
- if ($train_no) {
- $ref->{sched_arrival} = epoch_to_dt($raw_sched_ts),
- $ref->{rt_arrival} = epoch_to_dt($raw_real_ts),
- $ref->{messages} = [ split( qr{[|]}, $raw_messages ) ];
- }
+ $ref->{from_name} = $name;
+ $ref->{completed} = 1;
+ $ref->{sched_departure} = epoch_to_dt($raw_sched_ts),
+ $ref->{rt_departure} = epoch_to_dt($raw_real_ts),
+ $ref->{type} //= $train_type;
+ $ref->{line} //= $train_line;
+ $ref->{no} //= $train_no;
+ $ref->{messages} //= [ split( qr{[|]}, $raw_messages ) ];
+ $ref->{route} //= [ split( qr{[|]}, $raw_route ) ];
}
}
- @travels = reverse @travels;
-
return @travels;
};