summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DBInfoscreen.pm')
-rw-r--r--lib/DBInfoscreen.pm64
1 files changed, 16 insertions, 48 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm
index 836f94e..c784e96 100644
--- a/lib/DBInfoscreen.pm
+++ b/lib/DBInfoscreen.pm
@@ -1,6 +1,6 @@
package DBInfoscreen;
-# Copyright (C) 2011-2020 Daniel Friesel
+# Copyright (C) 2011-2020 Birte Kristina Friesel
#
# SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,12 +12,9 @@ use DBInfoscreen::Helper::HAFAS;
use DBInfoscreen::Helper::Wagonorder;
use File::Slurp qw(read_file);
use JSON;
-use Travel::Status::DE::IRIS::Stations;
use utf8;
-no if $] >= 5.018, warnings => 'experimental::smartmatch';
-
sub startup {
my ($self) = @_;
@@ -39,6 +36,7 @@ sub startup {
);
chomp $self->config->{version};
+ $self->defaults( version => $self->config->{version} // 'UNKNOWN' );
# Generally, the reverse proxy handles compression.
# Also, Mojolicious compression breaks legacy callback-based JSON endpoints
@@ -49,15 +47,14 @@ sub startup {
before_dispatch => sub {
my ($self) = @_;
- # The "theme" cookie is set client-side if the theme we delivered was
- # changed by dark mode detection or by using the theme switcher. It's
- # not part of Mojolicious' session data (and can't be, due to
- # signing and HTTPOnly), so we need to add it here.
+ # The "theme" cookie is set client-side if the theme we delivered was
+ # changed by dark mode detection or by using the theme switcher. It's
+ # not part of Mojolicious' session data (and can't be, due to
+ # signing and HTTPOnly), so we need to add it here.
for my $cookie ( @{ $self->req->cookies } ) {
if ( $cookie->name eq 'theme' ) {
$self->session( theme => $cookie->value );
- return;
}
}
}
@@ -88,36 +85,6 @@ sub startup {
);
$self->attr(
- ice_type_map => sub {
- if ( -r 'share/zugbildungsplan.json' ) {
- my $ice_type_map = JSON->new->utf8->decode(
- scalar read_file('share/zugbildungsplan.json') );
- my $ret = {};
- while ( my ( $k, $v ) = each %{ $ice_type_map->{train} } ) {
- if ( $v->{type} ) {
- $ret->{$k} = [
- $v->{type}, $v->{shortType},
- exists $v->{wagons} ? 1 : 0
- ];
- }
- }
- return $ret;
- }
- return {};
- }
- );
-
- $self->attr(
- train_details_db => sub {
- if ( -r 'share/zugbildungsplan.json' ) {
- return JSON->new->utf8->decode(
- scalar read_file('share/zugbildungsplan.json') )->{train};
- }
- return {};
- }
- );
-
- $self->attr(
dbdb_wagon => sub {
return JSON->new->utf8->decode(
scalar read_file('share/dbdb_wagen.json') );
@@ -290,7 +257,7 @@ sub startup {
my $r = $self->routes;
- $r->get('/_redirect')->to('static#redirect');
+ $r->get('/_redirect')->to('stationboard#redirect_to_station');
# legacy entry point
$r->get('/_auto')->to('static#geostop');
@@ -305,24 +272,25 @@ sub startup {
$r->get('/_impressum')->to('static#imprint');
+ $r->get('/dyn/:av/autocomplete.js')->to('stationboard#autocomplete');
+
$r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung');
- $r->get('/wr/:train')->to('wagenreihung#zugbildung_db');
$r->get('/w/*wagon')->to('wagenreihung#wagen');
$r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route');
$r->get('/map/:tripid/:lineno')->to('map#route');
- $r->get('/intersection/:trips')->to('map#intersection');
- $r->get('/z/:train/*station')->to('stationboard#station_train_details');
- $r->get('/z/:train')->to('stationboard#train_details');
-
- $r->get('/map')->to('map#search_form');
- $r->get('/_trainsearch')->to('map#search');
+ $r->get( '/z/:train/*station' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#station_train_details', format => undef )
+ ->name('train_at_station');
+ $r->get( '/z/:train' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#train_details', format => undef )->name('train');
$self->defaults( layout => 'app' );
$r->get('/')->to('stationboard#handle_request');
$r->get('/multi/*station')->to('stationboard#handle_request');
- $r->get('/*station')->to('stationboard#handle_request');
+ $r->get( '/*station' => [ format => [ 'html', 'json' ] ] )
+ ->to( 'stationboard#handle_request', format => undef );
$self->types->type( json => 'application/json; charset=utf-8' );