diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-26 08:32:42 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-26 08:32:42 +0200 |
commit | 6824e6bcf881c83091f844f55fcfed0c5f4de826 (patch) | |
tree | 8c3b6fdfa1b17c91caa5e6adff54ce38e02cdf41 /lib | |
parent | 8360f1f3953be284f3f4ff51a6717cc8f4c00176 (diff) |
generate autocomplete list dynamically from installed IRIS module
Diffstat (limited to 'lib')
-rw-r--r-- | lib/DBInfoscreen.pm | 2 | ||||
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index fd3ed0b..4618059 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -305,6 +305,8 @@ 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'); diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 8fb57a2..eb2badb 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -12,7 +12,7 @@ use Encode qw(decode encode); use File::Slurp qw(read_file write_file); use List::Util qw(max uniq); use List::MoreUtils qw(); -use Mojo::JSON qw(decode_json); +use Mojo::JSON qw(decode_json encode_json); use Mojo::Promise; use Mojo::UserAgent; use Travel::Status::DE::HAFAS; @@ -1836,4 +1836,24 @@ sub stations_by_coordinates { } } +sub autocomplete { + my $self = shift; + + $self->res->headers->cache_control('max-age=31536000, immutable'); + + my $output = '$(function(){const stations='; + $output + .= encode_json( + [ map { $_->[1] } Travel::Status::DE::IRIS::Stations::get_stations() ] + ); + $output .= ";\n"; + $output + .= "\$('input.station').autocomplete({delay:0,minLength:3,source:stations});});\n"; + + $self->render( + format => 'js', + data => $output + ); +} + 1; |