summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Travelynx.pm2
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm58
-rw-r--r--templates/add_journey.html.ep63
-rw-r--r--templates/edit_journey.html.ep94
-rw-r--r--templates/journey.html.ep10
5 files changed, 224 insertions, 3 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 7cab531..7c1c1df 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1475,8 +1475,10 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
$authed_r->get('/history')->to('traveling#history');
$authed_r->get('/history/:year')->to('traveling#yearly_history');
$authed_r->get('/history/:year/:month')->to('traveling#monthly_history');
+ $authed_r->get('/journey/add')->to('traveling#add_journey_form');
$authed_r->get('/journey/:id')->to('traveling#journey_details');
$authed_r->get('/s/*station')->to('traveling#station');
+ $authed_r->post('/journey/edit')->to('traveling#edit_journey');
$authed_r->post('/change_password')->to('account#change_password');
$authed_r->post('/delete')->to('account#delete');
$authed_r->post('/logout')->to('account#do_logout');
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index bbbc214..83036ba 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -378,6 +378,8 @@ sub journey_details {
my ($self) = @_;
my ( $uid, $checkout_id ) = split( qr{-}, $self->stash('id') );
+ $self->param( journey_id => $checkout_id );
+
if ( not( $uid == $self->current_user->{id} and $checkout_id ) ) {
$self->render(
'journey',
@@ -411,4 +413,60 @@ sub journey_details {
);
}
+sub edit_journey {
+ my ($self) = @_;
+ my $checkout_id = $self->param('journey_id');
+ my $uid = $self->current_user->{id};
+
+ if ( not( $uid == $self->current_user->{id} and $checkout_id ) ) {
+ $self->render(
+ 'edit_journey',
+ error => 'notfound',
+ journey => {}
+ );
+ return;
+ }
+
+ my @journeys = $self->get_user_travels(
+ uid => $uid,
+ checkout_id => $checkout_id,
+ );
+ if ( @journeys == 0
+ or not $journeys[0]{completed}
+ or $journeys[0]{ids}[1] != $checkout_id )
+ {
+ $self->render(
+ 'edit_journey',
+ error => 'notfound',
+ journey => {}
+ );
+ return;
+ }
+
+ my $journey = $journeys[0];
+
+ for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) {
+ if ( $journey->{$key} and $journey->{$key}->epoch ) {
+ $self->param(
+ $key => $journey->{$key}->strftime('%d.%m.%Y %H:%M') );
+ }
+ }
+
+ if ( $journey->{route} ) {
+ $self->param( route => join( "\n", @{ $journey->{route} } ) );
+ }
+
+ $self->render(
+ 'edit_journey',
+ error => undef,
+ journey => $journey
+ );
+}
+
+sub add_journey_form {
+ my ($self) = @_;
+
+ $self->render( 'add_journey', error => undef );
+}
+
1;
diff --git a/templates/add_journey.html.ep b/templates/add_journey.html.ep
new file mode 100644
index 0000000..9ef00f5
--- /dev/null
+++ b/templates/add_journey.html.ep
@@ -0,0 +1,63 @@
+<h1>Zugfahrt eingeben</h1>
+% if ($error) {
+ <div class="row">
+ <div class="col s12">
+ <div class="card red darken-4">
+ <div class="card-content white-text">
+ <span class="card-title">Ungültige Eingabe</span>
+ <p><%= $error %></p>
+ </div>
+ </div>
+ </div>
+ </div>
+% }
+<div class="row">
+ <div class="col s12">
+ <ul>
+ <li>Eingabe des Zugs als „Zug Typ Nummer“ oder „Zug Nummer“, z.B.
+ „ICE 100“, „S 1 31133“ oder „ABR RE11 26720“</li>
+ <li>Zeitangaben im Format DD.MM.YYYY HH:MM</li>
+ </ul>
+ </div>
+</div>
+%= form_for '/journey/add' => (method => 'POST') => begin
+ %= csrf_field
+ <div class="row">
+ <div class="input-field col s12">
+ %= text_field 'train', id => 'train', class => 'validate', required => undef, pattern => '[0-9a-zA-Z]+ +[0-9a-zA-Z]* *[0-9]+'
+ <label for="train">Zug (Typ Linie Nummer)</label>
+ </div>
+ </div>
+ <div class="row">
+ <div class="input-field col s12">
+ %= 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]'
+ <label for="sched_departure">Geplante Abfahrt</label>
+ </div>
+ <div class="input-field col s12">
+ %= text_field 'rt_departure', id => 'rt_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]'
+ <label for="rt_departure">Tatsächliche Abfahrt (optional)</label>
+ </div>
+ </div>
+ <div class="row">
+ <div class="input-field col s12">
+ %= 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]'
+ <label for="sched_arrival">Geplante Ankunft</label>
+ </div>
+ <div class="input-field col s12">
+ %= text_field 'rt_arrival', id => 'rt_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]'
+ <label for="rt_arrival">Tatsächliche Ankunft (optional)</label>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col s3 m3 l3">
+ </div>
+ <div class="col s6 m6 l6 center-align">
+ <button class="btn waves-effect waves-light" type="submit" name="action" value="save">
+ Hinzufügen
+ <i class="material-icons right">send</i>
+ </button>
+ </div>
+ <div class="col s3 m3 l3">
+ </div>
+ </div>
+%= end
diff --git a/templates/edit_journey.html.ep b/templates/edit_journey.html.ep
new file mode 100644
index 0000000..8fdc5b6
--- /dev/null
+++ b/templates/edit_journey.html.ep
@@ -0,0 +1,94 @@
+% if ($error and $error eq 'notfound') {
+ <div class="row">
+ <div class="col s12">
+ <div class="card red darken-4">
+ <div class="card-content white-text">
+ <span class="card-title">Fehler</span>
+ <p>Zugfahrt nicht gefunden.</p>
+ </div>
+ </div>
+ </div>
+ </div>
+% }
+% else {
+ % if ($error) {
+ <div class="row">
+ <div class="col s12">
+ <div class="card red darken-4">
+ <div class="card-content white-text">
+ <span class="card-title">Ungültige Eingabe</span>
+ <p><%= $error %></p>
+ </div>
+ </div>
+ </div>
+ </div>
+ % }
+ %= form_for '/journey/edit' => (method => 'POST') => begin
+ %= csrf_field
+ <div class="row">
+ <div class="col s12">
+ <p>
+ Fahrt von
+ <b><%= $journey->{from_name} %></b>
+ nach
+ <b><%= $journey->{to_name} %></b>
+ am
+ <b><%= $journey->{sched_departure}->strftime('%d.%m.%Y') %></b>
+ </p>
+ <table class="striped">
+ <tr>
+ <th scope="row">Zug</th>
+ <td>
+ <%= $journey->{type} %> <%= $journey->{no} %>
+ % if ($journey->{line}) {
+ (Linie <%= $journey->{line} %>)
+ % }
+ </td>
+ </tr>
+ <tr>
+ <th scope="row">Geplante Abfahrt</th>
+ <td>
+ %= 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>
+ </tr>
+ <tr>
+ <th scope="row">Tatsächliche Abfahrt</th>
+ <td>
+ %= 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>
+ </tr>
+ <tr>
+ <th scope="row">Geplante Ankunft</th>
+ <td>
+ %= 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>
+ </tr>
+ <tr>
+ <th scope="row">Tatsächliche Ankunft</th>
+ <td>
+ %= 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>
+ </tr>
+ <tr>
+ <th scope="row">Route</th>
+ <td>
+ %= text_area 'route', id => 'route', cols => 40, rows => 20
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col s3 m3 l3">
+ </div>
+ <div class="col s6 m6 l6 center-align">
+ <button class="btn waves-effect waves-light" type="submit" name="action" value="save">
+ Speichern
+ <i class="material-icons right">send</i>
+ </button>
+ </div>
+ <div class="col s3 m3 l3">
+ </div>
+ </div>
+ %= end
+% }
diff --git a/templates/journey.html.ep b/templates/journey.html.ep
index 7483a14..3b84d67 100644
--- a/templates/journey.html.ep
+++ b/templates/journey.html.ep
@@ -129,8 +129,6 @@
</div>
</div>
<div class="row">
- <div class="col s3 m3 l3">
- </div>
<div class="col s6 m6 l6 center-align">
<a class="waves-effect waves-light red btn action-delete"
data-id="<%= join(q{,}, @{$journey->{ids}}) %>"
@@ -140,7 +138,13 @@
Löschen
</a>
</div>
- <div class="col s3 m3 l3">
+ <div class="col s6 m6 l6 center-align">
+ %= form_for '/journey/edit' => (method => 'POST') => begin
+ %= hidden_field 'journey_id' => param('journey_id')
+ <button class="btn waves-effect waves-light" type="submit" name="action" value="edit" disabled="disabled">
+ Bearbeiten
+ </button>
+ %= end
</div>
</div>
% }