summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-13 10:43:05 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-13 10:43:05 +0200
commit1ee185d26bbfb9c7ef37aa6405645c8049d56f53 (patch)
tree7eeb83f545f7452cdbfea2654f35ce2c872d5958 /lib/Travelynx
parent863a33b111506e66850ccf1dcfde9e42584f52ab (diff)
work-in-progress manual journey entry. incomplete and not enabled yet.
Diffstat (limited to 'lib/Travelynx')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm74
1 files changed, 70 insertions, 4 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index ce7d1d4..0ace304 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -8,7 +8,11 @@ use Travel::Status::DE::IRIS::Stations;
sub homepage {
my ($self) = @_;
if ( $self->is_user_authenticated ) {
- $self->render( 'landingpage', with_geolocation => 1 );
+ $self->render(
+ 'landingpage',
+ with_autocomplete => 1,
+ with_geolocation => 1
+ );
}
else {
$self->render( 'landingpage', intro => 1 );
@@ -216,8 +220,9 @@ sub station {
if ( $status->{errstr} ) {
$self->render(
'landingpage',
- with_geolocation => 1,
- error => $status->{errstr}
+ with_autocomplete => 1,
+ with_geolocation => 1,
+ error => $status->{errstr}
);
}
else {
@@ -517,7 +522,68 @@ sub edit_journey {
sub add_journey_form {
my ($self) = @_;
- $self->render( 'add_journey', error => undef );
+ if ( $self->param('action') and $self->param('action') eq 'save' ) {
+ my $parser = DateTime::Format::Strptime->new(
+ pattern => '%d.%m.%Y %H:%M',
+ locale => 'de_DE',
+ time_zone => 'Europe/Berlin'
+ );
+ my %opt;
+
+ my @parts = split( qr{\s+}, $self->param('train') );
+
+ if ( @parts == 2 ) {
+ @opt{ 'train_type', 'train_no' } = @parts;
+ }
+ elsif ( @parts == 3 ) {
+ @opt{ 'train_type', 'train_line', 'train_no' } = @parts;
+ }
+ else {
+ $self->render(
+ 'add_journey',
+ with_autocomplete => 1,
+ error =>
+'Zug muss als „Typ Nummer“ oder „Typ Linie Nummer“ eingegeben werden.'
+ );
+ return;
+ }
+
+ for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival))
+ {
+ my $datetime = $parser->parse_datetime( $self->param($key) );
+ if ( not $datetime ) {
+ $self->render(
+ 'add_journey',
+ with_autocomplete => 1,
+ error => "${key}: Ungültiges Datums-/Zeitformat"
+ );
+ return;
+ }
+ $opt{$key} = $datetime;
+ }
+
+ for my $key (qw(dep_station arr_station)) {
+ $opt{$key} = $self->param($key);
+ }
+
+ $self->app->dbh->begin_work;
+
+ my ( $checkin_id, $checkout_id, $error ) = $self->add_journey(%opt);
+
+ $self->app->dbh->rollback;
+ $self->render(
+ 'add_journey',
+ with_autocomplete => 1,
+ error => $error
+ );
+ return;
+ }
+
+ $self->render(
+ 'add_journey',
+ with_autocomplete => 1,
+ error => undef
+ );
}
1;