From d23bfb57e201f70329e896fb07429b4913e5148a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 31 Aug 2022 18:09:12 +0200 Subject: train details: replace HAFAS 'Information'/'Störung' messages with icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/DBInfoscreen/Controller/Stationboard.pm | 44 ++++++++++++++++++++++------- templates/_train_details.html.ep | 12 ++++++-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 24df23e..b986ff7 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -8,11 +8,11 @@ use Mojo::Base 'Mojolicious::Controller'; use DateTime; use DateTime::Format::Strptime; -use Encode qw(decode encode); -use File::Slurp qw(read_file write_file); -use List::Util qw(max uniq); +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); use Mojo::Promise; use Mojo::UserAgent; use Travel::Status::DE::IRIS; @@ -507,7 +507,7 @@ sub format_iris_result_info { if ( $template ne 'json' ) { push( @{$moreinfo}, - [ 'Außerplanmäßiger Halt in', $additional_line ] + [ 'Außerplanmäßiger Halt in', { text => $additional_line } ] ); } } @@ -517,7 +517,7 @@ sub format_iris_result_info { $info = 'Ohne Halt in: ' . $cancel_line . ( $info ? ' +++ ' : q{} ) . $info; if ( $template ne 'json' ) { - push( @{$moreinfo}, [ 'Ohne Halt in', $cancel_line ] ); + push( @{$moreinfo}, [ 'Ohne Halt in', { text => $cancel_line } ] ); } } @@ -781,8 +781,12 @@ sub render_train { $departure->{messages}{him} = $him; for my $message ( @{$him} ) { if ( $message->{display} ) { - push( @him_messages, - [ $message->{header}, $message->{lead} ] ); + push( + @him_messages, + [ + $message->{header}, { text => $message->{lead} } + ] + ); if ( $message->{lead} =~ m{zuginfo.nrw/?\?msg=(\d+)} ) { push( @{ $departure->{links} }, @@ -800,6 +804,14 @@ sub render_train { = grep { $_->[0] !~ m{Information\. $m\.$} } @him_messages; } + for my $m (@him_messages) { + if ( $m->[0] =~ s{: Information.}{: } ) { + $m->[1]{icon} = 'info_outline'; + } + if ( $m->[0] =~ s{: Störung.}{: } ) { + $m->[1]{icon} = 'warning'; + } + } unshift( @{ $departure->{moreinfo} }, @him_messages ); } } @@ -1053,8 +1065,12 @@ sub train_details { my @him_messages; for my $message ( @{$him} ) { if ( $message->{display} ) { - push( @him_messages, - [ $message->{header}, $message->{lead} ] ); + push( + @him_messages, + [ + $message->{header}, { text => $message->{lead} } + ] + ); if ( $message->{lead} =~ m{zuginfo.nrw/?\?msg=(\d+)} ) { push( @{ $res->{links} }, @@ -1066,6 +1082,14 @@ sub train_details { } } } + for my $m (@him_messages) { + if ( $m->[0] =~ s{: Information.}{:} ) { + $m->[1]{icon} = 'info_outline'; + } + if ( $m->[0] =~ s{: Störung.}{: } ) { + $m->[1]{icon} = 'warning'; + } + } $res->{moreinfo} = [@him_messages]; } diff --git a/templates/_train_details.html.ep b/templates/_train_details.html.ep index 7ef2138..bcef76c 100644 --- a/templates/_train_details.html.ep +++ b/templates/_train_details.html.ep @@ -173,16 +173,22 @@ % else { %= $pair->[0]->strftime('%H:%M') % } + +%= $pair->[1] + % } % else { +% if ($pair->[1]{icon}) { + <%= $pair->[1]{icon} %> +% } %= $pair->[0] % if (length($pair->[0]) > 25) {
% } + +%= $pair->[1]{text} + % } - -%= $pair->[1] - % } % if ($departure->{route_info}) { -- cgit v1.2.3