summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-19 10:32:57 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-19 10:32:57 +0200
commitd9d3aac79200ca7d896d753c897e1651517ecf36 (patch)
tree87194b7a8b67b7b09bd2dc357e5239099dd60430 /lib
parent7960114f71720f2c2fa86e74be4b80812edaef36 (diff)
allow checkin from connections view
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm19
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm16
2 files changed, 29 insertions, 6 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 9e00d3f..ff75898 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -176,6 +176,12 @@ sub startup {
);
$self->helper(
+ 'now' => sub {
+ return DateTime->now( time_zone => 'Europe/Berlin' );
+ }
+ );
+
+ $self->helper(
'numify_skipped_stations' => sub {
my ( $self, $count ) = @_;
@@ -1489,7 +1495,7 @@ sub startup {
my $uid = $opt{uid} // $self->current_user->{id};
my $threshold = $opt{threshold}
// DateTime->now( time_zone => 'Europe/Berlin' )
- ->subtract( weeks => 60 );
+ ->subtract( weeks => 6 );
my $db = $opt{db} // $self->pg->db;
my $journey = $db->select( 'in_transit', ['checkout_station_id'],
@@ -1504,7 +1510,7 @@ sub startup {
},
{
limit => 1,
- order_by => { -desc => 'real_dep_ts' }
+ order_by => { -desc => 'real_departure' }
}
)->hash;
}
@@ -1547,11 +1553,14 @@ sub startup {
}
my @destinations = $self->get_connection_targets(%opt);
- my $stationboard
- = $self->get_departures( $status->{arr_ds100}, 0, 60 );
-
@destinations = grep { $_ ne $status->{dep_name} } @destinations;
+ if ( not @destinations ) {
+ return;
+ }
+
+ my $stationboard
+ = $self->get_departures( $status->{arr_ds100}, 0, 60 );
if ( $stationboard->{errstr} ) {
return;
}
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 3d2bb0c..4e4b069 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -145,6 +145,7 @@ sub log_action {
my ( $train, $error )
= $self->checkin( $params->{station}, $params->{train} );
+ my $destination = $params->{dest};
if ($error) {
$self->render(
@@ -154,7 +155,7 @@ sub log_action {
},
);
}
- else {
+ elsif ( not $destination ) {
$self->render(
json => {
success => 1,
@@ -162,6 +163,19 @@ sub log_action {
},
);
}
+ else {
+ # Silently ignore errors -- if they are permanent, the user will see
+ # them when selecting the destination manually.
+ my ( $still_checked_in, undef )
+ = $self->checkout( $destination, 0 );
+ my $station_link = '/s/' . $destination;
+ $self->render(
+ json => {
+ success => 1,
+ redirect_to => $still_checked_in ? '/' : $station_link,
+ },
+ );
+ }
}
elsif ( $params->{action} eq 'checkout' ) {
my ( $still_checked_in, $error )