diff options
| author | Daniel Friesel <daniel.friesel@uos.de> | 2022-08-31 18:09:12 +0200 | 
|---|---|---|
| committer | Daniel Friesel <daniel.friesel@uos.de> | 2022-08-31 18:09:12 +0200 | 
| commit | d23bfb57e201f70329e896fb07429b4913e5148a (patch) | |
| tree | 568199f36448218ef030a733fc7041ee726dfaa4 | |
| parent | 76c1bffa6c8eef6f9579131d33fc761aee87231c (diff) | |
train details: replace HAFAS 'Information'/'Störung' messages with icons
| -rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 44 | ||||
| -rw-r--r-- | 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')  %         } +          <span class="reason"> +%=        $pair->[1] +          </span>  %       }  %       else { +%         if ($pair->[1]{icon}) { +            <i class="material-icons"><%= $pair->[1]{icon} %></i> +%         }  %=        $pair->[0]  %         if (length($pair->[0]) > 25) {              <br/>  %         } +          <span class="reason"> +%=        $pair->[1]{text} +          </span>  %       } -        <span class="reason"> -%=      $pair->[1] -        </span>          </li>  %     }  %     if ($departure->{route_info}) { | 
