Loading index.pl +71 −13 Original line number Diff line number Diff line Loading @@ -36,8 +36,10 @@ my %action_type = ( checkin => 1, checkout => 2, undo => 3, cancelled_from => 4, cancelled_to => 5, ); my @action_types = (qw(checkin checkout undo)); my @action_types = (qw(checkin checkout undo cancelled_from cancelled_to)); my %token_type = ( status => 1, history => 2, Loading Loading @@ -476,7 +478,9 @@ sub get_station { } helper 'checkin' => sub { my ( $self, $station, $train_id ) = @_; my ( $self, $station, $train_id, $action_id ) = @_; $action_id //= $action_type{checkin}; my $status = get_departures($station); if ( $status->{errstr} ) { Loading Loading @@ -504,10 +508,17 @@ helper 'checkin' => sub { # XXX same workaround: We can't checkin immediately after checkout. sleep(1); } elsif ( $user->{cancelled} ) { # Same sleep(1); $self->cancelled_to($station); sleep(1); } my $success = $self->app->action_query->execute( $self->current_user->{id}, $action_type{checkin}, $action_id, $self->get_station_id( ds100 => $status->{station_ds100}, name => $status->{station_name} Loading Loading @@ -563,13 +574,15 @@ helper 'undo' => sub { }; helper 'checkout' => sub { my ( $self, $station, $force ) = @_; my ( $self, $station, $force, $action_id ) = @_; $action_id //= $action_type{checkout}; my $status = get_departures( $station, 180 ); my $user = $self->get_user_status; my $train_id = $user->{train_id}; if ( not $user->{checked_in} ) { if ( not $user->{checked_in} and not $user->{cancelled} ) { return 'You are not checked into any train'; } if ( $status->{errstr} and not $force ) { Loading @@ -582,7 +595,7 @@ helper 'checkout' => sub { if ($force) { my $success = $self->app->action_query->execute( $self->current_user->{id}, $action_type{checkout}, $action_id, $self->get_station_id( ds100 => $status->{station_ds100}, name => $status->{station_name} Loading Loading @@ -892,6 +905,7 @@ helper 'get_user_status' => sub { } return { checked_in => ( $cols[0] == $action_type{checkin} ), cancelled => ( $cols[0] == $action_type{cancelled_from} ), timestamp => $action_ts, timestamp_delta => $now->epoch - $action_ts->epoch, sched_ts => $sched_ts, Loading Loading @@ -1070,7 +1084,10 @@ get '/api/v0/:action/:token' => sub { $self->render( json => { deprecated => \0, checked_in => $status->{checked_in} ? \1 : \0, checked_in => ( $status->{checked_in} or $status->{cancelled} ) ? \1 : \0, station => { ds100 => $status->{station_ds100}, name => $status->{station_name}, Loading Loading @@ -1302,7 +1319,7 @@ post '/action' => sub { if ( $params->{action} eq 'checkin' ) { my ( $train, $error ) = $self->checkin( $params->{station}, $params->{train}, ); = $self->checkin( $params->{station}, $params->{train} ); if ($error) { $self->render( Loading @@ -1321,7 +1338,7 @@ post '/action' => sub { } } elsif ( $params->{action} eq 'checkout' ) { my $error = $self->checkout( $params->{station}, $params->{force}, ); my $error = $self->checkout( $params->{station}, $params->{force} ); if ($error) { $self->render( Loading Loading @@ -1357,6 +1374,47 @@ post '/action' => sub { ); } } elsif ( $params->{action} eq 'cancelled_from' ) { my ( undef, $error ) = $self->checkin( $params->{station}, $params->{train}, $action_type{cancelled_from} ); if ($error) { $self->render( json => { success => 0, error => $error, }, ); } else { $self->render( json => { success => 1, }, ); } } elsif ( $params->{action} eq 'cancelled_to' ) { my $error = $self->checkout( $params->{station}, 1, $action_type{cancelled_to} ); if ($error) { $self->render( json => { success => 0, error => $error, }, ); } else { $self->render( json => { success => 1, }, ); } } else { $self->render( json => { Loading public/static/css/local.css +3 −1 Original line number Diff line number Diff line .action-checkin, .action-checkout, .action-undo { .action-undo, .action-cancelled-from, .action-cancelled-to { cursor: pointer; } Loading public/static/js/travelynx-actions.js +19 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,24 @@ $(document).ready(function() { var req = { action: 'undo', }; tvly_run(link, req, window.location.href); tvly_run(link, req, '/'); }); $('.action-cancelled-from').click(function() { var link = $(this); var req = { action: 'cancelled_from', station: link.data('station'), train: link.data('train'), }; tvly_run(link, req, '/'); }); $('.action-cancelled-to').click(function() { var link = $(this); var req = { action: 'cancelled_to', station: link.data('station'), force: true, }; tvly_run(link, req, '/'); }); }); public/static/js/travelynx-actions.min.js +1 −1 Original line number Diff line number Diff line function tvly_run(n,t,i,a){var c='<i class="material-icons">error</i>',o=$('<div class="progress"><div class="indeterminate"></div></div>');n.hide(),n.after(o),$.post("/action",t,function(t){t.success?$(location).attr("href",i):(M.toast({html:c+" "+t.error}),o.remove(),a&&a(),n.append(" "+c),n.show())})}$(document).ready(function(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")},"/")}),$(".action-checkout").click(function(){var t=$(this),n={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,n,"/s/"+n.station,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){tvly_run($(this),{action:"undo"},window.location.href)})}); function tvly_run(n,t,a,c){var i='<i class="material-icons">error</i>',o=$('<div class="progress"><div class="indeterminate"></div></div>');n.hide(),n.after(o),$.post("/action",t,function(t){t.success?$(location).attr("href",a):(M.toast({html:i+" "+t.error}),o.remove(),c&&c(),n.append(" "+i),n.show())})}$(document).ready(function(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")},"/")}),$(".action-checkout").click(function(){var t=$(this),n={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,n,"/s/"+n.station,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){tvly_run($(this),{action:"undo"},"/")}),$(".action-cancelled-from").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_from",station:t.data("station"),train:t.data("train")},"/")}),$(".action-cancelled-to").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_to",station:t.data("station"),force:!0},"/")})}); templates/departures.html.ep +8 −6 Original line number Diff line number Diff line Loading @@ -52,22 +52,24 @@ </thead> <tbody> % for my $result (@{$results}) { % my $class = ""; % my $td_class = ''; % my $link_class = 'action-checkin'; % if ($result->departure_is_cancelled) { % $class = "cancelled"; % $td_class = "cancelled"; % $link_class = 'action-cancelled-from'; % } <tr> <td> <a class="action-checkin" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <a class="<%= $link_class %>" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <%= $result->line %> </a> </td> <td class="<%= $class %>"> <a class="action-checkin" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <td class="<%= $td_class %>"> <a class="<%= $link_class %>" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <%= $result->destination %> </a> </td> <td class="<%= $class %>"><%= $result->departure->strftime('%H:%M') %> <td class="<%= $td_class %>"><%= $result->departure->strftime('%H:%M') %> % if ($result->departure_delay) { (+<%= $result->departure_delay %>) % } Loading Loading
index.pl +71 −13 Original line number Diff line number Diff line Loading @@ -36,8 +36,10 @@ my %action_type = ( checkin => 1, checkout => 2, undo => 3, cancelled_from => 4, cancelled_to => 5, ); my @action_types = (qw(checkin checkout undo)); my @action_types = (qw(checkin checkout undo cancelled_from cancelled_to)); my %token_type = ( status => 1, history => 2, Loading Loading @@ -476,7 +478,9 @@ sub get_station { } helper 'checkin' => sub { my ( $self, $station, $train_id ) = @_; my ( $self, $station, $train_id, $action_id ) = @_; $action_id //= $action_type{checkin}; my $status = get_departures($station); if ( $status->{errstr} ) { Loading Loading @@ -504,10 +508,17 @@ helper 'checkin' => sub { # XXX same workaround: We can't checkin immediately after checkout. sleep(1); } elsif ( $user->{cancelled} ) { # Same sleep(1); $self->cancelled_to($station); sleep(1); } my $success = $self->app->action_query->execute( $self->current_user->{id}, $action_type{checkin}, $action_id, $self->get_station_id( ds100 => $status->{station_ds100}, name => $status->{station_name} Loading Loading @@ -563,13 +574,15 @@ helper 'undo' => sub { }; helper 'checkout' => sub { my ( $self, $station, $force ) = @_; my ( $self, $station, $force, $action_id ) = @_; $action_id //= $action_type{checkout}; my $status = get_departures( $station, 180 ); my $user = $self->get_user_status; my $train_id = $user->{train_id}; if ( not $user->{checked_in} ) { if ( not $user->{checked_in} and not $user->{cancelled} ) { return 'You are not checked into any train'; } if ( $status->{errstr} and not $force ) { Loading @@ -582,7 +595,7 @@ helper 'checkout' => sub { if ($force) { my $success = $self->app->action_query->execute( $self->current_user->{id}, $action_type{checkout}, $action_id, $self->get_station_id( ds100 => $status->{station_ds100}, name => $status->{station_name} Loading Loading @@ -892,6 +905,7 @@ helper 'get_user_status' => sub { } return { checked_in => ( $cols[0] == $action_type{checkin} ), cancelled => ( $cols[0] == $action_type{cancelled_from} ), timestamp => $action_ts, timestamp_delta => $now->epoch - $action_ts->epoch, sched_ts => $sched_ts, Loading Loading @@ -1070,7 +1084,10 @@ get '/api/v0/:action/:token' => sub { $self->render( json => { deprecated => \0, checked_in => $status->{checked_in} ? \1 : \0, checked_in => ( $status->{checked_in} or $status->{cancelled} ) ? \1 : \0, station => { ds100 => $status->{station_ds100}, name => $status->{station_name}, Loading Loading @@ -1302,7 +1319,7 @@ post '/action' => sub { if ( $params->{action} eq 'checkin' ) { my ( $train, $error ) = $self->checkin( $params->{station}, $params->{train}, ); = $self->checkin( $params->{station}, $params->{train} ); if ($error) { $self->render( Loading @@ -1321,7 +1338,7 @@ post '/action' => sub { } } elsif ( $params->{action} eq 'checkout' ) { my $error = $self->checkout( $params->{station}, $params->{force}, ); my $error = $self->checkout( $params->{station}, $params->{force} ); if ($error) { $self->render( Loading Loading @@ -1357,6 +1374,47 @@ post '/action' => sub { ); } } elsif ( $params->{action} eq 'cancelled_from' ) { my ( undef, $error ) = $self->checkin( $params->{station}, $params->{train}, $action_type{cancelled_from} ); if ($error) { $self->render( json => { success => 0, error => $error, }, ); } else { $self->render( json => { success => 1, }, ); } } elsif ( $params->{action} eq 'cancelled_to' ) { my $error = $self->checkout( $params->{station}, 1, $action_type{cancelled_to} ); if ($error) { $self->render( json => { success => 0, error => $error, }, ); } else { $self->render( json => { success => 1, }, ); } } else { $self->render( json => { Loading
public/static/css/local.css +3 −1 Original line number Diff line number Diff line .action-checkin, .action-checkout, .action-undo { .action-undo, .action-cancelled-from, .action-cancelled-to { cursor: pointer; } Loading
public/static/js/travelynx-actions.js +19 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,24 @@ $(document).ready(function() { var req = { action: 'undo', }; tvly_run(link, req, window.location.href); tvly_run(link, req, '/'); }); $('.action-cancelled-from').click(function() { var link = $(this); var req = { action: 'cancelled_from', station: link.data('station'), train: link.data('train'), }; tvly_run(link, req, '/'); }); $('.action-cancelled-to').click(function() { var link = $(this); var req = { action: 'cancelled_to', station: link.data('station'), force: true, }; tvly_run(link, req, '/'); }); });
public/static/js/travelynx-actions.min.js +1 −1 Original line number Diff line number Diff line function tvly_run(n,t,i,a){var c='<i class="material-icons">error</i>',o=$('<div class="progress"><div class="indeterminate"></div></div>');n.hide(),n.after(o),$.post("/action",t,function(t){t.success?$(location).attr("href",i):(M.toast({html:c+" "+t.error}),o.remove(),a&&a(),n.append(" "+c),n.show())})}$(document).ready(function(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")},"/")}),$(".action-checkout").click(function(){var t=$(this),n={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,n,"/s/"+n.station,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){tvly_run($(this),{action:"undo"},window.location.href)})}); function tvly_run(n,t,a,c){var i='<i class="material-icons">error</i>',o=$('<div class="progress"><div class="indeterminate"></div></div>');n.hide(),n.after(o),$.post("/action",t,function(t){t.success?$(location).attr("href",a):(M.toast({html:i+" "+t.error}),o.remove(),c&&c(),n.append(" "+i),n.show())})}$(document).ready(function(){$(".action-checkin").click(function(){var t=$(this);tvly_run(t,{action:"checkin",station:t.data("station"),train:t.data("train")},"/")}),$(".action-checkout").click(function(){var t=$(this),n={action:"checkout",station:t.data("station"),force:t.data("force")};tvly_run(t,n,"/s/"+n.station,function(){t.append(" – Ohne Echtzeitdaten auschecken?"),t.data("force",!0)})}),$(".action-undo").click(function(){tvly_run($(this),{action:"undo"},"/")}),$(".action-cancelled-from").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_from",station:t.data("station"),train:t.data("train")},"/")}),$(".action-cancelled-to").click(function(){var t=$(this);tvly_run(t,{action:"cancelled_to",station:t.data("station"),force:!0},"/")})});
templates/departures.html.ep +8 −6 Original line number Diff line number Diff line Loading @@ -52,22 +52,24 @@ </thead> <tbody> % for my $result (@{$results}) { % my $class = ""; % my $td_class = ''; % my $link_class = 'action-checkin'; % if ($result->departure_is_cancelled) { % $class = "cancelled"; % $td_class = "cancelled"; % $link_class = 'action-cancelled-from'; % } <tr> <td> <a class="action-checkin" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <a class="<%= $link_class %>" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <%= $result->line %> </a> </td> <td class="<%= $class %>"> <a class="action-checkin" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <td class="<%= $td_class %>"> <a class="<%= $link_class %>" data-station="<%= $ds100 %>" data-train="<%= $result->train_id %>"> <%= $result->destination %> </a> </td> <td class="<%= $class %>"><%= $result->departure->strftime('%H:%M') %> <td class="<%= $td_class %>"><%= $result->departure->strftime('%H:%M') %> % if ($result->departure_delay) { (+<%= $result->departure_delay %>) % } Loading