Re-add force checkout to frontend
This commit is contained in:
parent
2113533713
commit
8e817e5d60
2 changed files with 64 additions and 64 deletions
79
index.pl
79
index.pl
|
@ -299,39 +299,17 @@ helper 'checkout' => sub {
|
||||||
my $user = $self->get_user_status;
|
my $user = $self->get_user_status;
|
||||||
my $train_id = $user->{train_id};
|
my $train_id = $user->{train_id};
|
||||||
|
|
||||||
if ( $status->{errstr} and not $force ) {
|
|
||||||
return $status->{errstr};
|
|
||||||
}
|
|
||||||
if ( not $user->{checked_in} ) {
|
if ( not $user->{checked_in} ) {
|
||||||
return 'You are not checked into any train';
|
return 'You are not checked into any train';
|
||||||
}
|
}
|
||||||
else {
|
if ( $status->{errstr} and not $force ) {
|
||||||
my ($train)
|
return $status->{errstr};
|
||||||
= first { $_->train_id eq $train_id } @{ $status->{results} };
|
}
|
||||||
if ( not defined $train ) {
|
|
||||||
if ($force) {
|
my ($train)
|
||||||
my $success = $self->app->checkout_query->execute(
|
= first { $_->train_id eq $train_id } @{ $status->{results} };
|
||||||
$self->get_user_id,
|
if ( not defined $train ) {
|
||||||
$self->get_station_id(
|
if ($force) {
|
||||||
ds100 => $status->{station_ds100},
|
|
||||||
name => $status->{station_name}
|
|
||||||
),
|
|
||||||
DateTime->now( time_zone => 'Europe/Berlin' )->epoch,
|
|
||||||
undef, undef, undef, undef, undef,
|
|
||||||
undef, undef, undef
|
|
||||||
);
|
|
||||||
if ( defined $success ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 'INSERT failed';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "Train ${train_id} not found";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
my $success = $self->app->checkout_query->execute(
|
my $success = $self->app->checkout_query->execute(
|
||||||
$self->get_user_id,
|
$self->get_user_id,
|
||||||
$self->get_station_id(
|
$self->get_station_id(
|
||||||
|
@ -339,16 +317,8 @@ helper 'checkout' => sub {
|
||||||
name => $status->{station_name}
|
name => $status->{station_name}
|
||||||
),
|
),
|
||||||
DateTime->now( time_zone => 'Europe/Berlin' )->epoch,
|
DateTime->now( time_zone => 'Europe/Berlin' )->epoch,
|
||||||
$train->type,
|
undef, undef, undef, undef, undef,
|
||||||
$train->line_no,
|
undef, undef, undef
|
||||||
$train->train_no,
|
|
||||||
$train->train_id,
|
|
||||||
$train->sched_arrival ? $train->sched_arrival->epoch : undef,
|
|
||||||
$train->arrival ? $train->arrival->epoch : undef,
|
|
||||||
join( '|', $train->route ),
|
|
||||||
join( '|',
|
|
||||||
map { ( $_->[0] ? $_->[0]->epoch : q{} ) . ':' . $_->[1] }
|
|
||||||
$train->messages )
|
|
||||||
);
|
);
|
||||||
if ( defined $success ) {
|
if ( defined $success ) {
|
||||||
return;
|
return;
|
||||||
|
@ -357,6 +327,35 @@ helper 'checkout' => sub {
|
||||||
return 'INSERT failed';
|
return 'INSERT failed';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return "Train ${train_id} not found";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $success = $self->app->checkout_query->execute(
|
||||||
|
$self->get_user_id,
|
||||||
|
$self->get_station_id(
|
||||||
|
ds100 => $status->{station_ds100},
|
||||||
|
name => $status->{station_name}
|
||||||
|
),
|
||||||
|
DateTime->now( time_zone => 'Europe/Berlin' )->epoch,
|
||||||
|
$train->type,
|
||||||
|
$train->line_no,
|
||||||
|
$train->train_no,
|
||||||
|
$train->train_id,
|
||||||
|
$train->sched_arrival ? $train->sched_arrival->epoch : undef,
|
||||||
|
$train->arrival ? $train->arrival->epoch : undef,
|
||||||
|
join( '|', $train->route ),
|
||||||
|
join( '|',
|
||||||
|
map { ( $_->[0] ? $_->[0]->epoch : q{} ) . ':' . $_->[1] }
|
||||||
|
$train->messages )
|
||||||
|
);
|
||||||
|
if ( defined $success ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 'INSERT failed';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,42 @@
|
||||||
$(document).ready(function() {
|
function travelynx_run_action(link, req, redir, err_callback) {
|
||||||
var error_icon = '<i class="material-icons">error</i>';
|
var error_icon = '<i class="material-icons">error</i>';
|
||||||
|
var progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
|
||||||
|
link.hide();
|
||||||
|
link.after(progressbar);
|
||||||
|
$.post('/action', req, function(data) {
|
||||||
|
if (data.success) {
|
||||||
|
$(location).attr('href', redir);
|
||||||
|
} else {
|
||||||
|
M.toast({html: error_icon + ' ' + data.error});
|
||||||
|
progressbar.remove();
|
||||||
|
if (err_callback) {
|
||||||
|
err_callback();
|
||||||
|
}
|
||||||
|
link.append(' ' + error_icon);
|
||||||
|
link.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$(document).ready(function() {
|
||||||
$('.action-checkin').click(function() {
|
$('.action-checkin').click(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
req = {
|
var req = {
|
||||||
action: 'checkin',
|
action: 'checkin',
|
||||||
station: link.data('station'),
|
station: link.data('station'),
|
||||||
train: link.data('train'),
|
train: link.data('train'),
|
||||||
};
|
};
|
||||||
progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
|
travelynx_run_action(link, req, '/');
|
||||||
link.replaceWith(progressbar);
|
|
||||||
$.post('/action', req, function(data) {
|
|
||||||
if (data.success) {
|
|
||||||
$(location).attr('href', '/');
|
|
||||||
} else {
|
|
||||||
M.toast({html: error_icon + ' ' + data.error});
|
|
||||||
link.append(' ' + error_icon);
|
|
||||||
progressbar.replaceWith(link);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
$('.action-checkout').click(function() {
|
$('.action-checkout').click(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
req = {
|
var req = {
|
||||||
action: 'checkout',
|
action: 'checkout',
|
||||||
station: link.data('station'),
|
station: link.data('station'),
|
||||||
force: link.data('force'),
|
force: link.data('force'),
|
||||||
};
|
};
|
||||||
progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
|
travelynx_run_action(link, req, '/' + req.station, function() {
|
||||||
link.replaceWith(progressbar);
|
link.append(' – Keine Echtzeitdaten vorhanden')
|
||||||
$.post('/action', req, function(data) {
|
link.data('force', true);
|
||||||
if (data.success) {
|
|
||||||
$(location).attr('href', '/' + req.station);
|
|
||||||
} else {
|
|
||||||
M.toast({html: error_icon + ' ' + data.error});
|
|
||||||
link.append(' ' + error_icon);
|
|
||||||
progressbar.replaceWith(link);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue