From eb3f4aed05d31509e0544ff29b382759ba31b9c2 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 1 Feb 2020 16:15:20 +0100 Subject: allow checkin and checkout station to be edited --- lib/Travelynx.pm | 49 ++++++++++++++++++++++++++++++++--- lib/Travelynx/Controller/Traveling.pm | 22 +++++++++++++--- templates/edit_journey.html.ep | 24 ++++++++++++----- templates/journey.html.ep | 6 +++++ 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 46911d8..aeb09d1 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -43,13 +43,22 @@ sub epoch_to_dt { } sub get_station { - my ($station_name) = @_; + my ( $station_name, $exact_match ) = @_; my @candidates = Travel::Status::DE::IRIS::Stations::get_station($station_name); if ( @candidates == 1 ) { - return $candidates[0]; + if ( not $exact_match ) { + return $candidates[0]; + } + if ( $candidates[0][0] eq $station_name + or $candidates[0][1] eq $station_name + or $candidates[0][2] eq $station_name ) + { + return $candidates[0]; + } + return undef; } return undef; } @@ -187,10 +196,12 @@ sub startup { return { sched_departure => 0x0001, real_departure => 0x0002, + from_station => 0x0004, route => 0x0010, is_cancelled => 0x0020, sched_arrival => 0x0100, real_arrival => 0x0200, + to_station => 0x0400, }; } ); @@ -912,7 +923,39 @@ sub startup { ); eval { - if ( $key eq 'sched_departure' ) { + if ( $key eq 'from_name' ) { + my $from_station = get_station( $value, 1 ); + if ( not $from_station ) { + die("Unbekannter Startbahnhof\n"); + } + $rows = $db->update( + 'journeys', + { + checkin_station_id => $from_station->[2], + edited => $journey->{edited} | 0x0004, + }, + { + id => $journey_id, + } + )->rows; + } + elsif ( $key eq 'to_name' ) { + my $to_station = get_station( $value, 1 ); + if ( not $to_station ) { + die("Unbekannter Zielbahnhof\n"); + } + $rows = $db->update( + 'journeys', + { + checkout_station_id => $to_station->[2], + edited => $journey->{edited} | 0x0400, + }, + { + id => $journey_id, + } + )->rows; + } + elsif ( $key eq 'sched_departure' ) { $rows = $db->update( 'journeys', { diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index e294c8c..b08864e 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -894,6 +894,17 @@ sub edit_journey { } } } + for my $key (qw(from_name to_name)) { + if ( defined $self->param($key) + and $self->param($key) ne $journey->{$key} ) + { + $error = $self->update_journey_part( $db, $journey->{id}, $key, + $self->param($key) ); + if ($error) { + last; + } + } + } for my $key (qw(comment)) { if ( defined $self->param($key) @@ -919,7 +930,7 @@ sub edit_journey { } } { - my $cancelled_old = $journey->{cancelled}; + my $cancelled_old = $journey->{cancelled} // 0; my $cancelled_new = $self->param('cancelled') // 0; if ( $cancelled_old != $cancelled_new ) { $error @@ -955,7 +966,9 @@ sub edit_journey { $self->param( route => join( "\n", map { $_->[0] } @{ $journey->{route} } ) ); - $self->param( cancelled => $journey->{cancelled} ); + $self->param( cancelled => $journey->{cancelled} ? 1 : 0 ); + $self->param( from_name => $journey->{from_name} ); + $self->param( to_name => $journey->{to_name} ); for my $key (qw(comment)) { if ( $journey->{user_data} and $journey->{user_data}{$key} ) { @@ -965,8 +978,9 @@ sub edit_journey { $self->render( 'edit_journey', - error => $error, - journey => $journey + with_autocomplete => 1, + error => $error, + journey => $journey ); } diff --git a/templates/edit_journey.html.ep b/templates/edit_journey.html.ep index 0eb8a99..c9aaa64 100644 --- a/templates/edit_journey.html.ep +++ b/templates/edit_journey.html.ep @@ -60,39 +60,51 @@ + + Start: + + %= text_field 'from_name', id => 'from_name', class => 'autocomplete validate', required => undef + + Geplante Abfahrt - + %= text_field 'sched_departure', id => 'sched_departure', class => 'validate', required => undef, pattern => '[0-9][0-9]?[.][0-9][0-9]?[.][0-9][0-9][0-9][0-9] +[0-9][0-9]:[0-9][0-9]' Tatsächliche Abfahrt - + %= text_field 'rt_departure', id => 'real_departure', class => 'validate', pattern => '[0-9][0-9]?[.][0-9][0-9]?[.][0-9][0-9][0-9][0-9] +[0-9][0-9]:[0-9][0-9]' + + Ziel: + + %= text_field 'to_name', id => 'to_name', class => 'autocomplete validate', required => undef + + Geplante Ankunft - + %= text_field 'sched_arrival', id => 'sched_arrival', class => 'validate', required => undef, pattern => '[0-9][0-9]?[.][0-9][0-9]?[.][0-9][0-9][0-9][0-9] +[0-9][0-9]:[0-9][0-9]' Tatsächliche Ankunft - + %= text_field 'rt_arrival', id => 'real_arrival', class => 'validate', pattern => '[0-9][0-9]?[.][0-9][0-9]?[.][0-9][0-9][0-9][0-9] +[0-9][0-9]:[0-9][0-9]' Route - + %= text_area 'route', id => 'route', class => 'materialize-textarea' Kommentar - + %= text_field 'comment' diff --git a/templates/journey.html.ep b/templates/journey.html.ep index 3a27194..ae8f750 100644 --- a/templates/journey.html.ep +++ b/templates/journey.html.ep @@ -25,8 +25,14 @@ % } von <%= $journey->{from_name} %> + % if ($journey->{edited} & 0x0004) { + ∗ + % } nach <%= $journey->{to_name} %> + % if ($journey->{edited} & 0x0400) { + ∗ + % } am <%= $journey->{sched_departure}->strftime('%d.%m.%Y') %>

-- cgit v1.2.3