Skip to content
GitLab
Explore
Sign in
derf
db-infoscreen
Compare revisions
96f17f475f27feaeec13067990c8da9e9203190a to a85266ef8432271d988f00e83da9f5ed350f7097
Commits on Source (3)
Stationboard: Fix uninitialize value warning
· 0a994156
Birte Kristina Friesel
authored
Apr 24, 2024
0a994156
Add JSON output to train details (/z/:train)
· 2d66be08
Birte Kristina Friesel
authored
Apr 24, 2024
2d66be08
Support JSON output for /z/:train/*station
· a85266ef
Birte Kristina Friesel
authored
Apr 24, 2024
Closes #13
a85266ef
Hide whitespace changes
Inline
Side-by-side
lib/DBInfoscreen.pm
View file @
a85266ef
...
...
@@ -279,9 +279,11 @@ sub startup {
$r
->
get
('
/_ajax_mapinfo/:tripid/:lineno
')
->
to
('
map#ajax_route
');
$r
->
get
('
/map/:tripid/:lineno
')
->
to
('
map#route
');
$r
->
get
(
'
/z/:train/*station
'
=>
'
train_at_station
'
)
->
to
('
stationboard#station_train_details
');
$r
->
get
(
'
/z/:train
'
=>
'
train
'
)
->
to
('
stationboard#train_details
');
$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
'
);
...
...
lib/DBInfoscreen/Controller/Stationboard.pm
View file @
a85266ef
...
...
@@ -937,27 +937,36 @@ sub render_train {
# Defer rendering until all requests have completed
Mojo::
Promise
->
all
(
@requests
)
->
then
(
sub
{
$self
->
render
(
$template
//
'
_train_details
',
description
=>
sprintf
(
'
%s %s%s%s nach %s
',
$departure
->
{
train_type
},
$departure
->
{
train_line
}
//
$departure
->
{
train_no
},
$departure
->
{
origin
}
?
'
von
'
:
q{}
,
$departure
->
{
origin
}
//
q{}
,
$departure
->
{
destination
}
//
'
unbekannt
'
),
departure
=>
$departure
,
linetype
=>
$linetype
,
dt_now
=>
DateTime
->
now
(
time_zone
=>
'
Europe/Berlin
'
),
station_name
=>
$station_name
,
nav_link
=>
$self
->
url_for
(
'
station
',
station
=>
$station_name
)
->
query
(
{
detailed
=>
$self
->
param
('
detailed
'),
hafas
=>
$self
->
param
('
hafas
')
}
),
$self
->
respond_to
(
json
=>
{
json
=>
{
departure
=>
$departure
,
station_name
=>
$station_name
,
},
},
any
=>
{
template
=>
$template
//
'
_train_details
',
description
=>
sprintf
(
'
%s %s%s%s nach %s
',
$departure
->
{
train_type
},
$departure
->
{
train_line
}
//
$departure
->
{
train_no
},
$departure
->
{
origin
}
?
'
von
'
:
q{}
,
$departure
->
{
origin
}
//
q{}
,
$departure
->
{
destination
}
//
'
unbekannt
'
),
departure
=>
$departure
,
linetype
=>
$linetype
,
dt_now
=>
DateTime
->
now
(
time_zone
=>
'
Europe/Berlin
'
),
station_name
=>
$station_name
,
nav_link
=>
$self
->
url_for
(
'
station
',
station
=>
$station_name
)
->
query
(
{
detailed
=>
$self
->
param
('
detailed
'),
hafas
=>
$self
->
param
('
hafas
')
}
),
},
);
}
)
->
wait
;
...
...
@@ -973,6 +982,10 @@ sub station_train_details {
delete
$self
->
stash
->
{
layout
};
}
if
(
$station
=~
s{ [.] json $ }{}x
)
{
$self
->
stash
(
format
=>
'
json
'
);
}
my
%opt
=
(
cache_iris_main
=>
$self
->
app
->
cache_iris_main
,
cache_iris_rt
=>
$self
->
app
->
cache_iris_rt
,
...
...
@@ -1134,7 +1147,10 @@ sub train_details {
}
my
$service
=
'
DB
';
if
(
$hafas
ne
'
1
'
and
Travel::Status::DE::HAFAS::
get_service
(
$hafas
)
)
{
if
(
$hafas
and
$hafas
ne
'
1
'
and
Travel::Status::DE::HAFAS::
get_service
(
$hafas
)
)
{
$opt
{
service
}
=
$hafas
;
}
...
...
@@ -1300,34 +1316,52 @@ sub train_details {
$res
->
{
details
}
=
[
@him_details
];
}
$self
->
render
(
$self
->
param
('
ajax
')
?
'
_train_details
'
:
'
train_details
',
description
=>
sprintf
(
'
%s %s%s%s nach %s
',
$res
->
{
train_type
},
$res
->
{
train_line
}
//
$res
->
{
train_no
},
$res
->
{
origin
}
?
'
von
'
:
q{}
,
$res
->
{
origin
}
//
q{}
,
$res
->
{
destination
}
//
'
unbekannt
'
),
departure
=>
$res
,
linetype
=>
$linetype
,
dt_now
=>
DateTime
->
now
(
time_zone
=>
'
Europe/Berlin
'
),
$self
->
respond_to
(
json
=>
{
json
=>
{
journey
=>
$journey
,
},
},
any
=>
{
template
=>
$self
->
param
('
ajax
')
?
'
_train_details
'
:
'
train_details
',
description
=>
sprintf
(
'
%s %s%s%s nach %s
',
$res
->
{
train_type
},
$res
->
{
train_line
}
//
$res
->
{
train_no
},
$res
->
{
origin
}
?
'
von
'
:
q{}
,
$res
->
{
origin
}
//
q{}
,
$res
->
{
destination
}
//
'
unbekannt
'
),
departure
=>
$res
,
linetype
=>
$linetype
,
dt_now
=>
DateTime
->
now
(
time_zone
=>
'
Europe/Berlin
'
),
},
);
}
)
->
catch
(
sub
{
my
(
$e
)
=
@_
;
if
(
$e
)
{
$self
->
render
(
'
exception
',
message
=>
$e
,
exception
=>
undef
,
snapshot
=>
{}
$self
->
respond_to
(
json
=>
{
json
=>
{
error
=>
$e
,
},
status
=>
500
,
},
any
=>
{
template
=>
'
exception
',
message
=>
$e
,
exception
=>
undef
,
snapshot
=>
{},
status
=>
500
,
},
);
}
else
{
$self
->
render
('
not_found
');
$self
->
render
(
'
not_found
'
,
status
=>
404
);
}
}
)
->
wait
;
...
...