summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-11-05 21:35:30 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-11-05 21:35:30 +0100
commit042a59c865ab5a319bee0844368fd42df2e502b9 (patch)
treeb4f60c4989e11042b65d623e7fce72af7505c3c4
parent16d9f3a07c37a5e741c185be36077e7d0523c985 (diff)
EFA departure board: add JSON interface
-rw-r--r--lib/DBInfoscreen/Controller/Stationboard.pm50
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm
index ae3f1ae..0e1c6aa 100644
--- a/lib/DBInfoscreen/Controller/Stationboard.pm
+++ b/lib/DBInfoscreen/Controller/Stationboard.pm
@@ -1695,6 +1695,11 @@ sub handle_efa {
for my $result ( $efa->results ) {
my $time;
+ if ( $template eq 'json' ) {
+ push( @departures, $result );
+ next;
+ }
+
if ( $show_realtime and $result->rt_datetime ) {
$time = $result->rt_datetime->strftime('%H:%M');
}
@@ -1764,23 +1769,34 @@ sub handle_efa {
);
}
- $self->render(
- $template,
- description => "Abfahrtstafel $station_name",
- departures => \@departures,
- station => $efa->stop->name,
- version => $self->config->{version},
- title => $efa->stop->name // $station_name,
- refresh_interval => $template eq 'app' ? 0 : 120,
- hide_opts => $hide_opts,
- hide_low_delay => $hide_low_delay,
- show_realtime => $show_realtime,
- load_marquee => (
- $template eq 'single'
- or $template eq 'multi'
- ),
- force_mobile => ( $template eq 'app' ),
- );
+ if ( $template eq 'json' ) {
+ $self->res->headers->access_control_allow_origin(q{*});
+ my $json = {
+ departures => \@departures,
+ };
+ $self->render(
+ json => $json,
+ );
+ }
+ else {
+ $self->render(
+ $template,
+ description => "Abfahrtstafel $station_name",
+ departures => \@departures,
+ station => $efa->stop->name,
+ version => $self->config->{version},
+ title => $efa->stop->name // $station_name,
+ refresh_interval => $template eq 'app' ? 0 : 120,
+ hide_opts => $hide_opts,
+ hide_low_delay => $hide_low_delay,
+ show_realtime => $show_realtime,
+ load_marquee => (
+ $template eq 'single'
+ or $template eq 'multi'
+ ),
+ force_mobile => ( $template eq 'app' ),
+ );
+ }
}
sub handle_result {