summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-04-04 22:26:02 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-04-04 22:26:02 +0200
commit2f63f255028f770c75482402c1b2ff1366c793f5 (patch)
tree8d8f26fb8144b48280b4253c1033d4de32f5cf86
parente49274d8f8194d8a2817ecc8a0c8557fe3c9b7a9 (diff)
dbris: ajax support
-rw-r--r--lib/DBInfoscreen/Controller/Map.pm83
-rw-r--r--public/static/js/map-refresh.js2
2 files changed, 83 insertions, 2 deletions
diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm
index 44b7740..adcb362 100644
--- a/lib/DBInfoscreen/Controller/Map.pm
+++ b/lib/DBInfoscreen/Controller/Map.pm
@@ -567,7 +567,7 @@ sub route_dbris {
title => $journey->train,
hide_opts => 1,
with_map => 1,
- ajax_req => $trip_id,
+ ajax_req => "${trip_id}/0",
ajax_route => route_to_ajax(
map {
{
@@ -912,6 +912,84 @@ sub ajax_route_efa {
)->wait;
}
+sub ajax_route_dbris {
+ my ($self) = @_;
+ my $trip_id = $self->stash('tripid');
+
+ $self->dbris->get_polyline_p( id => $trip_id )->then(
+ sub {
+ my ($journey) = @_;
+
+ my $now = DateTime->now( time_zone => 'Europe/Berlin' );
+
+ my @route = $journey->route;
+ my @polyline = $journey->polyline;
+
+ my $train_pos = $self->estimate_train_positions2(
+ now => $now,
+ route => [
+ map {
+ {
+ name => $_->name,
+ arr => $_->arr,
+ dep => $_->dep,
+ arr_delay => $_->arr_delay,
+ dep_delay => $_->dep_delay,
+ lat => $_->lat,
+ lon => $_->lon
+ }
+ } @route
+ ],
+ polyline => \@polyline,
+ );
+
+ $self->render(
+ '_map_infobox',
+ ajax_req => "${trip_id}/0",
+ ajax_route => route_to_ajax(
+ map {
+ {
+ name => $_->name,
+ platform => $_->platform,
+ arr => $_->arr,
+ arr_cancelled => $_->is_cancelled,
+ arr_delay => $_->arr_delay,
+ dep => $_->dep,
+ dep_cancelled => $_->is_cancelled,
+ dep_delay => $_->dep_delay,
+ }
+ } @route
+ ),
+ ajax_polyline => join(
+ '|',
+ map { join( ';', @{$_} ) } @{ $train_pos->{positions} }
+ ),
+ origin => {
+ name => ( $journey->route )[0]->name,
+ ts => ( $journey->route )[0]->dep,
+ },
+ destination => {
+ name => ( $journey->route )[-1]->name,
+ ts => ( $journey->route )[-1]->arr,
+ },
+ train_no => $journey->number
+ ? ( $journey->type . ' ' . $journey->number )
+ : undef,
+ next_stop => $train_pos->{next_stop},
+ platform_type => q{},
+ );
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->render(
+ '_error',
+ error => $err,
+ );
+ }
+ )->wait;
+}
+
sub ajax_route {
my ($self) = @_;
@@ -919,6 +997,9 @@ sub ajax_route {
$self->render_later;
+ if ( $self->param('dbris') ) {
+ return $self->ajax_route_dbris;
+ }
if ( $self->param('efa') ) {
return $self->ajax_route_efa;
}
diff --git a/public/static/js/map-refresh.js b/public/static/js/map-refresh.js
index c54f428..6dbbde5 100644
--- a/public/static/js/map-refresh.js
+++ b/public/static/js/map-refresh.js
@@ -69,7 +69,7 @@ function dbf_anim_fine() {
function dbf_map_reload() {
const param = new URLSearchParams(window.location.search);
- $.get('/_ajax_mapinfo/' + j_reqid + '?efa=' + (param.get('efa') || '') + '&amp;hafas=' + (param.get('hafas') || ''), function(data) {
+ $.get('/_ajax_mapinfo/' + j_reqid + '?dbris=' + (param.get('dbris') || '') + '&amp;efa=' + (param.get('efa') || '') + '&amp;hafas=' + (param.get('hafas') || ''), function(data) {
$('#infobox').html(data);
dbf_map_parse();
setTimeout(dbf_map_reload, 61000);