diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2019-04-08 21:20:04 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2019-04-08 21:20:04 +0200 | 
| commit | c0c7b1a589b51b9fe27980ff7b5c80e56a77eb01 (patch) | |
| tree | 7aec58d2d32418578e0e785f19f787629e5a27c1 /lib/Travelynx | |
| parent | beb17acb8440bb44f1070c2fb3b2e6cf7521f800 (diff) | |
Work-in-progress journey editor. Not ready for deployment.
Diffstat (limited to 'lib/Travelynx')
| -rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 67 | 
1 files changed, 59 insertions, 8 deletions
| diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 83036ba..ce7d1d4 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -2,6 +2,7 @@ package Travelynx::Controller::Traveling;  use Mojo::Base 'Mojolicious::Controller';  use DateTime; +use DateTime::Format::Strptime;  use Travel::Status::DE::IRIS::Stations;  sub homepage { @@ -427,14 +428,12 @@ sub edit_journey {  		return;  	} -	my @journeys = $self->get_user_travels( +	my $journey = $self->get_journey(  		uid         => $uid, -		checkout_id => $checkout_id, +		checkout_id => $checkout_id  	); -	if (   @journeys == 0 -		or not $journeys[0]{completed} -		or $journeys[0]{ids}[1] != $checkout_id ) -	{ + +	if ( not $journey ) {  		$self->render(  			'edit_journey',  			error   => 'notfound', @@ -443,7 +442,59 @@ sub edit_journey {  		return;  	} -	my $journey = $journeys[0]; +	my $error = undef; + +	if ( $self->param('action') and $self->param('action') eq 'cancel' ) { +		$self->redirect_to("/journey/${uid}-${checkout_id}"); +		return; +	} + +	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' +		); + +		$self->app->dbh->begin_work; + +		for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) +		{ +			my $datetime = $parser->parse_datetime( $self->param($key) ); +			if ( $datetime and $datetime->epoch ne $journey->{$key}->epoch ) { +				$error = $self->update_journey_part( +					$journey->{ids}[0], +					$journey->{ids}[1], +					$key, $datetime->epoch +				); +				if ($error) { +					last; +				} +			} +		} + +		if ($error) { +			$self->app->dbh->rollback; +		} +		else { +			$journey = $self->get_journey( +				uid         => $uid, +				checkout_id => $checkout_id, +				verbose     => 1 +			); +			$error = $self->journey_sanity_check($journey); +			if ($error) { +				$self->app->dbh->rollback; +			} +			else { +				$self->invalidate_stats_cache( $journey->{checkout} ); +				$self->app->dbh->commit; +				$self->redirect_to("/journey/${uid}-${checkout_id}"); +				return; +			} +		} + +	}  	for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) {  		if ( $journey->{$key} and $journey->{$key}->epoch ) { @@ -458,7 +509,7 @@ sub edit_journey {  	$self->render(  		'edit_journey', -		error   => undef, +		error   => $error,  		journey => $journey  	);  } | 
