From 51b52327caa311a851c50951a5c4b9b37ccf0ed8 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Wed, 27 Mar 2024 14:59:20 +0100 Subject: map: support non-DB HAFAS backends, including ÖBB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/DBInfoscreen/Controller/Map.pm | 30 ++++++++++++++++++++++++++++-- lib/DBInfoscreen/Helper/HAFAS.pm | 6 +++++- public/static/js/map-refresh.js | 3 ++- templates/_map_infobox.html.ep | 2 +- templates/_train_details.html.ep | 4 ++-- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm index e552a18..bced612 100644 --- a/lib/DBInfoscreen/Controller/Map.pm +++ b/lib/DBInfoscreen/Controller/Map.pm @@ -314,13 +314,26 @@ sub route { my ($self) = @_; my $trip_id = $self->stash('tripid'); my $line_no = $self->stash('lineno'); + my $hafas = $self->param('hafas'); my $from_name = $self->param('from'); my $to_name = $self->param('to'); $self->render_later; - $self->hafas->get_polyline_p( $trip_id, $line_no )->then( + my $service = 'DB'; + if ( $hafas + and $hafas ne '1' + and Travel::Status::DE::HAFAS::get_service($hafas) ) + { + $service = $hafas; + } + + $self->hafas->get_polyline_p( + id => $trip_id, + line => $line_no, + service => $service + )->then( sub { my ($journey) = @_; @@ -458,12 +471,25 @@ sub ajax_route { my ($self) = @_; my $trip_id = $self->stash('tripid'); my $line_no = $self->stash('lineno'); + my $hafas = $self->param('hafas'); delete $self->stash->{layout}; $self->render_later; - $self->hafas->get_polyline_p( $trip_id, $line_no )->then( + my $service = 'DB'; + if ( $hafas + and $hafas ne '1' + and Travel::Status::DE::HAFAS::get_service($hafas) ) + { + $service = $hafas; + } + + $self->hafas->get_polyline_p( + id => $trip_id, + line => $line_no, + service => $service + )->then( sub { my ($journey) = @_; diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index 302cb9c..148a917 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -161,11 +161,15 @@ sub get_route_p { # Input: (HAFAS TripID, line number) # Output: Promise returning a Travel::Status::DE::HAFAS::Journey instance on success sub get_polyline_p { - my ( $self, $trip_id, $line ) = @_; + my ( $self, %opt ) = @_; + my $trip_id = $opt{id}; + my $line = $opt{line}; + my $service = $opt{service}; my $promise = Mojo::Promise->new; Travel::Status::DE::HAFAS->new_p( + service => $service, journey => { id => $trip_id, name => $line, diff --git a/public/static/js/map-refresh.js b/public/static/js/map-refresh.js index aa5629b..0389323 100644 --- a/public/static/js/map-refresh.js +++ b/public/static/js/map-refresh.js @@ -68,7 +68,8 @@ function dbf_anim_fine() { } function dbf_map_reload() { - $.get('/_ajax_mapinfo/' + j_reqid, function(data) { + const param = new URLSearchParams(window.location.search); + $.get('/_ajax_mapinfo/' + j_reqid + '?hafas=' + param.get('hafas'), function(data) { $('#infobox').html(data); dbf_map_parse(); setTimeout(dbf_map_reload, 61000); diff --git a/templates/_map_infobox.html.ep b/templates/_map_infobox.html.ep index c8936ae..4f9a644 100644 --- a/templates/_map_infobox.html.ep +++ b/templates/_map_infobox.html.ep @@ -1,6 +1,6 @@
diff --git a/templates/_train_details.html.ep b/templates/_train_details.html.ep index f1ddfe0..dca9405 100644 --- a/templates/_train_details.html.ep +++ b/templates/_train_details.html.ep @@ -139,10 +139,10 @@
% if ($departure->{trip_id}) { % if (stash('station_name')) { - <%= l 'Karte' %> + <%= l 'Karte' %> % } % else { - <%= l 'Karte' %> + <%= l 'Karte' %> % } % } % if ($departure->{wr_link}) { -- cgit v1.2.3