diff options
-rwxr-xr-x | lib/Travelynx.pm | 34 | ||||
-rw-r--r-- | lib/Travelynx/Command/work.pm | 10 | ||||
-rw-r--r-- | templates/_checked_in.html.ep | 7 |
3 files changed, 49 insertions, 2 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index ea7ab58..2b34b99 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -817,7 +817,6 @@ sub startup { arr_platform => $train->platform, sched_arrival => $train->sched_arrival, real_arrival => $train->arrival, - cancelled => $train->arrival_is_cancelled ? 1 : 0, route => $json->encode( [ $self->route_diff($train) ] ), messages => $json->encode( @@ -861,6 +860,39 @@ sub startup { } $self->invalidate_stats_cache( $cache_ts, $db, $uid ); } + elsif ( defined $train and $train->arrival_is_cancelled ) { + + # This branch is only taken if the deparure was not cancelled, + # i.e., if the train was supposed to go here but got + # redirected or cancelled on the way and not from the start on. + # If the departure itself was cancelled, the user route is + # cancelled_from action -> 'cancelled journey' panel on main page + # -> cancelled_to action -> force checkout (causing the + # previous branch to be taken due to $force) + $journey->{edited} = 0; + $journey->{checkout_time} = $now; + $journey->{cancelled} = 1; + delete $journey->{data}; + $db->insert( 'journeys', $journey ); + + $journey + = $db->select( 'in_transit', ['data'], + { user_id => $uid } )->expand->hash; + $journey->{data}{cancelled_destination} = $train->station; + + $db->update( + 'in_transit', + { + checkout_station_id => undef, + checkout_time => undef, + arr_platform => undef, + sched_arrival => undef, + real_arrival => undef, + data => JSON->new->encode( $journey->{data} ), + }, + { user_id => $uid } + ); + } $tx->commit; }; diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 405716c..9658ff6 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -134,7 +134,15 @@ sub run { checkout_station_id => $arr } ); - $self->app->add_route_timestamps( $uid, $train, 0 ); + if ( $train->arrival_is_cancelled ) { + + # check out (adds a cancelled journey and resets journey state + # to destination selection) + $self->app->checkout( $arr, 0, $uid ); + } + else { + $self->app->add_route_timestamps( $uid, $train, 0 ); + } } elsif ( $entry->{real_arr_ts} ) { my ( undef, $error ) = $self->app->checkout( $arr, 1, $uid ); diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep index 193657f..4edb1a6 100644 --- a/templates/_checked_in.html.ep +++ b/templates/_checked_in.html.ep @@ -163,6 +163,13 @@ </div> </p> % } + % if ($journey->{extra_data}{cancelled_destination}) { + <p style="margin-bottom: 2ex;"> + Der Halt in <b><%= $journey->{extra_data}{cancelled_destination} %></b> + entfällt. Der Zugausfall wurde bereits vermerkt. Bitte wähle ein + neues Reiseziel. + </p> + % } % if (@{$journey->{messages} // []} or @{$journey->{extra_data}{qos_msg} // []}) { <p style="margin-bottom: 2ex;"> <ul> |