Skip to content
Snippets Groups Projects
Commit 57f47d2a authored by Daniel Friesel's avatar Daniel Friesel
Browse files

allow routes to be edited after recording a journey

parent 7b0a8ad4
No related branches found
No related tags found
No related merge requests found
...@@ -817,6 +817,19 @@ sub startup { ...@@ -817,6 +817,19 @@ sub startup {
} }
)->rows; )->rows;
} }
elsif ( $key eq 'route' ) {
my @new_route = map { [ $_, {}, undef ] } @{$value};
$rows = $db->update(
'journeys',
{
route => JSON->new->encode( \@new_route ),
edited => $journey->{edited} | 0x0010,
},
{
id => $journey_id,
}
)->rows;
}
elsif ( $key eq 'comment' ) { elsif ( $key eq 'comment' ) {
$journey->{user_data}{comment} = $value; $journey->{user_data}{comment} = $value;
$rows = $db->update( $rows = $db->update(
...@@ -871,6 +884,23 @@ sub startup { ...@@ -871,6 +884,23 @@ sub startup {
{ {
return 'Die Zugfahrt ist länger als 24 Stunden.'; return 'Die Zugfahrt ist länger als 24 Stunden.';
} }
if ( $journey->{kmh_route} > 500 or $journey->{kmh_beeline} > 500 )
{
return 'Zugfahrten mit über 500 km/h? Schön wär\'s.';
}
if ( $journey->{edited} & 0x0010 ) {
my @unknown_stations;
for my $station ( @{ $journey->{route} } ) {
my $station_info = get_station( $station->[0] );
if ( not $station_info ) {
push( @unknown_stations, $station->[0] );
}
}
if (@unknown_stations) {
return 'Unbekannte Stationen: '
. join( ', ', @unknown_stations );
}
}
return undef; return undef;
} }
......
...@@ -719,6 +719,16 @@ sub edit_journey { ...@@ -719,6 +719,16 @@ sub edit_journey {
} }
} }
} }
if ( defined $self->param('route') ) {
my @route_old = map { $_->[0] } @{ $journey->{route} };
my @route_new = split( qr{\r?\n\r?}, $self->param('route') );
@route_new = grep { $_ ne '' } @route_new;
if ( join( '|', @route_old ) ne join( '|', @route_new ) ) {
$error
= $self->update_journey_part( $db, $journey->{id}, 'route',
[@route_new] );
}
}
if ( not $error ) { if ( not $error ) {
$journey = $self->get_journey( $journey = $self->get_journey(
...@@ -742,6 +752,10 @@ sub edit_journey { ...@@ -742,6 +752,10 @@ sub edit_journey {
$key => $journey->{$key}->strftime('%d.%m.%Y %H:%M') ); $key => $journey->{$key}->strftime('%d.%m.%Y %H:%M') );
} }
} }
$self->param(
route => join( "\n", map { $_->[0] } @{ $journey->{route} } ) );
for my $key (qw(comment)) { for my $key (qw(comment)) {
if ( $journey->{user_data} and $journey->{user_data}{$key} ) { if ( $journey->{user_data} and $journey->{user_data}{$key} ) {
$self->param( $key => $journey->{user_data}{$key} ); $self->param( $key => $journey->{user_data}{$key} );
......
...@@ -75,6 +75,12 @@ ...@@ -75,6 +75,12 @@
%= 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]' %= 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]'
</td> </td>
</tr> </tr>
<tr>
<th scope="row">Route</th>
<td>
%= text_area 'route', id => 'route', class => 'materialize-textarea'
</td>
</tr>
<tr> <tr>
<th scope="row">Kommentar</th> <th scope="row">Kommentar</th>
<td> <td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment