allow checkin and checkout station to be edited

This commit is contained in:
Daniel Friesel 2020-02-01 16:15:20 +01:00
parent 5439dbad34
commit eb3f4aed05
4 changed files with 88 additions and 13 deletions

View file

@ -43,14 +43,23 @@ sub epoch_to_dt {
} }
sub get_station { sub get_station {
my ($station_name) = @_; my ( $station_name, $exact_match ) = @_;
my @candidates my @candidates
= Travel::Status::DE::IRIS::Stations::get_station($station_name); = Travel::Status::DE::IRIS::Stations::get_station($station_name);
if ( @candidates == 1 ) { if ( @candidates == 1 ) {
if ( not $exact_match ) {
return $candidates[0]; 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; return undef;
} }
@ -187,10 +196,12 @@ sub startup {
return { return {
sched_departure => 0x0001, sched_departure => 0x0001,
real_departure => 0x0002, real_departure => 0x0002,
from_station => 0x0004,
route => 0x0010, route => 0x0010,
is_cancelled => 0x0020, is_cancelled => 0x0020,
sched_arrival => 0x0100, sched_arrival => 0x0100,
real_arrival => 0x0200, real_arrival => 0x0200,
to_station => 0x0400,
}; };
} }
); );
@ -912,7 +923,39 @@ sub startup {
); );
eval { 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( $rows = $db->update(
'journeys', 'journeys',
{ {

View file

@ -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)) { for my $key (qw(comment)) {
if ( if (
defined $self->param($key) 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; my $cancelled_new = $self->param('cancelled') // 0;
if ( $cancelled_old != $cancelled_new ) { if ( $cancelled_old != $cancelled_new ) {
$error $error
@ -955,7 +966,9 @@ sub edit_journey {
$self->param( $self->param(
route => join( "\n", map { $_->[0] } @{ $journey->{route} } ) ); 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)) { for my $key (qw(comment)) {
if ( $journey->{user_data} and $journey->{user_data}{$key} ) { if ( $journey->{user_data} and $journey->{user_data}{$key} ) {
@ -965,6 +978,7 @@ sub edit_journey {
$self->render( $self->render(
'edit_journey', 'edit_journey',
with_autocomplete => 1,
error => $error, error => $error,
journey => $journey journey => $journey
); );

View file

@ -60,39 +60,51 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<th scope="row">Start:</th>
<td class="input-field">
%= text_field 'from_name', id => 'from_name', class => 'autocomplete validate', required => undef
</td>
</tr>
<tr> <tr>
<th scope="row">Geplante Abfahrt</th> <th scope="row">Geplante Abfahrt</th>
<td> <td class="input-field">
%= 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]' %= 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]'
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row">Tatsächliche Abfahrt</th> <th scope="row">Tatsächliche Abfahrt</th>
<td> <td class="input-field">
%= 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]' %= 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]'
</td> </td>
</tr> </tr>
<tr>
<th scope="row">Ziel:</th>
<td class="input-field">
%= text_field 'to_name', id => 'to_name', class => 'autocomplete validate', required => undef
</td>
</tr>
<tr> <tr>
<th scope="row">Geplante Ankunft</th> <th scope="row">Geplante Ankunft</th>
<td> <td class="input-field">
%= 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]' %= 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]'
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row">Tatsächliche Ankunft</th> <th scope="row">Tatsächliche Ankunft</th>
<td> <td class="input-field">
%= 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> <tr>
<th scope="row">Route</th> <th scope="row">Route</th>
<td> <td class="input-field">
%= text_area 'route', id => 'route', class => 'materialize-textarea' %= text_area 'route', id => 'route', class => 'materialize-textarea'
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row">Kommentar</th> <th scope="row">Kommentar</th>
<td> <td class="input-field">
%= text_field 'comment' %= text_field 'comment'
</td> </td>
</tr> </tr>

View file

@ -25,8 +25,14 @@
% } % }
von von
<b><%= $journey->{from_name} %></b> <b><%= $journey->{from_name} %></b>
% if ($journey->{edited} & 0x0004) {
% }
nach nach
<b><%= $journey->{to_name} %></b> <b><%= $journey->{to_name} %></b>
% if ($journey->{edited} & 0x0400) {
% }
am am
<b><%= $journey->{sched_departure}->strftime('%d.%m.%Y') %></b> <b><%= $journey->{sched_departure}->strftime('%d.%m.%Y') %></b>
</p> </p>