summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-11-19 19:46:21 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2019-11-19 19:46:39 +0100
commitb80613b8a8dad252960d90f6a03227503e2ba133 (patch)
treeb861525de6e5bb54ca24ace890423570c8849e96
parent13e59b3aa1504154a90619069c963301e322904a (diff)
allow route input when adding journeys manually (#26)
-rwxr-xr-xlib/Travelynx.pm46
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm6
-rw-r--r--templates/add_journey.html.ep6
-rw-r--r--templates/journey.html.ep6
4 files changed, 51 insertions, 13 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 741af2a..f13dd60 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -304,6 +304,39 @@ sub startup {
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 = {
user_id => $uid,
train_type => $opt{train_type},
@@ -326,18 +359,7 @@ sub startup {
checkout_time => $now,
edited => 0x3fff,
cancelled => $opt{cancelled} ? 1 : 0,
- route => JSON->new->encode(
- [
- [
- $dep_station->[1], undef,
- $opt{sched_departure}->epoch,
- ],
- [
- $arr_station->[1], $opt{sched_arrival}->epoch,
- undef
- ]
- ]
- ),
+ route => JSON->new->encode( \@route ),
};
if ( $opt{comment} ) {
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index f0f1879..c8f975f 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -803,10 +803,14 @@ sub add_journey_form {
$opt{rt_departure} //= $opt{sched_departure};
$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);
}
+ if ( $opt{route} ) {
+ $opt{route} = [ split( qr{\r?\n\r?}, $opt{route} ) ];
+ }
+
my $db = $self->pg->db;
my $tx = $db->begin;
diff --git a/templates/add_journey.html.ep b/templates/add_journey.html.ep
index 58cd68b..c3bc01c 100644
--- a/templates/add_journey.html.ep
+++ b/templates/add_journey.html.ep
@@ -78,6 +78,12 @@
</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="input-field col s12">
%= text_field 'comment'
<label for="comment">Kommentar</label>
</div>
diff --git a/templates/journey.html.ep b/templates/journey.html.ep
index 9b7ad9c..7be4f78 100644
--- a/templates/journey.html.ep
+++ b/templates/journey.html.ep
@@ -113,6 +113,9 @@
% else {
?
% }
+ % if ($journey->{edited} & 0x0010) {
+ ∗
+ % }
</td>
</tr>
<tr>
@@ -174,6 +177,9 @@
% else {
<span style="color: #666666;"><%= $station->[0] %></span>
% }
+ % if ($journey->{edited} & 0x0010) {
+ ∗
+ % }
<br/>
% }
</td>