allow route input when adding journeys manually (#26)

This commit is contained in:
Daniel Friesel 2019-11-19 19:46:21 +01:00
parent 13e59b3aa1
commit b80613b8a8
4 changed files with 51 additions and 13 deletions

View file

@ -304,6 +304,39 @@ sub startup {
return ( undef, 'Unbekannter Zielbahnhof' ); return ( undef, 'Unbekannter Zielbahnhof' );
} }
my @route = ( [ $dep_station->[1], {}, undef ] );
if ( $opt{route} ) {
my @unknown_stations;
for my $station ( @{ $opt{route} } ) {
my $station_info = get_station($station);
if ( not $station_info ) {
push( @unknown_stations, $station );
}
push( @route, [ $station_info->[1], {}, undef ] );
}
if ( @unknown_stations == 1 ) {
return ( undef,
"Unbekannter Unterwegshalt: $unknown_stations[0]" );
}
elsif (@unknown_stations) {
return ( undef,
'Unbekannte Unterwegshalte: '
. join( ', ', @unknown_stations ) );
}
}
push( @route, [ $arr_station->[1], {}, undef ] );
if ( $route[0][0] eq $route[1][0] ) {
shift(@route);
}
if ( $route[-2][0] eq $route[-1][0] ) {
pop(@route);
}
my $entry = { my $entry = {
user_id => $uid, user_id => $uid,
train_type => $opt{train_type}, train_type => $opt{train_type},
@ -326,18 +359,7 @@ sub startup {
checkout_time => $now, checkout_time => $now,
edited => 0x3fff, edited => 0x3fff,
cancelled => $opt{cancelled} ? 1 : 0, cancelled => $opt{cancelled} ? 1 : 0,
route => JSON->new->encode( route => JSON->new->encode( \@route ),
[
[
$dep_station->[1], undef,
$opt{sched_departure}->epoch,
],
[
$arr_station->[1], $opt{sched_arrival}->epoch,
undef
]
]
),
}; };
if ( $opt{comment} ) { if ( $opt{comment} ) {

View file

@ -803,10 +803,14 @@ sub add_journey_form {
$opt{rt_departure} //= $opt{sched_departure}; $opt{rt_departure} //= $opt{sched_departure};
$opt{rt_arrival} //= $opt{sched_arrival}; $opt{rt_arrival} //= $opt{sched_arrival};
for my $key (qw(dep_station arr_station cancelled comment)) { for my $key (qw(dep_station arr_station route cancelled comment)) {
$opt{$key} = $self->param($key); $opt{$key} = $self->param($key);
} }
if ( $opt{route} ) {
$opt{route} = [ split( qr{\r?\n\r?}, $opt{route} ) ];
}
my $db = $self->pg->db; my $db = $self->pg->db;
my $tx = $db->begin; my $tx = $db->begin;

View file

@ -76,6 +76,12 @@
<label for="rt_arrival">Tatsächliche Ankunft (wenn leer: pünktlich)</label> <label for="rt_arrival">Tatsächliche Ankunft (wenn leer: pünktlich)</label>
</div> </div>
</div> </div>
<div class="row">
<div class="input-field col s12">
%= text_area 'route', id => 'route', class => 'materialize-textarea'
<label for="route">Unterwegshalte (optional, eine Station pro Zeile, DS100 möglich)</label>
</div>
</div>
<div class="row"> <div class="row">
<div class="input-field col s12"> <div class="input-field col s12">
%= text_field 'comment' %= text_field 'comment'

View file

@ -113,6 +113,9 @@
% else { % else {
? ?
% } % }
% if ($journey->{edited} & 0x0010) {
% }
</td> </td>
</tr> </tr>
<tr> <tr>
@ -174,6 +177,9 @@
% else { % else {
<span style="color: #666666;"><%= $station->[0] %></span> <span style="color: #666666;"><%= $station->[0] %></span>
% } % }
% if ($journey->{edited} & 0x0010) {
% }
<br/> <br/>
% } % }
</td> </td>