From ae9051b807ac8116583f4a1b2e3b3cea7218a74f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 22 May 2015 16:23:45 +0200 Subject: color additional/cancelled stops green/red in IRIS+clean detail view --- index.pl | 135 +++++++++++++++++++++++++++--------------------- public/default.css | 8 +++ templates/clean.html.ep | 16 ++++-- 3 files changed, 94 insertions(+), 65 deletions(-) diff --git a/index.pl b/index.pl index bc52561..1a89bff 100644 --- a/index.pl +++ b/index.pl @@ -74,6 +74,67 @@ helper 'is_important' => sub { return; }; +helper 'json_route_diff' => sub { + my ( $self, $route, $sched_route ) = @_; + my @json_route; + my @route = @{$route}; + my @sched_route = @{$sched_route}; + + my $route_idx = 0; + my $sched_idx = 0; + + while ( $route_idx <= $#route and $sched_idx <= $#sched_route ) { + if ( $route[$route_idx] eq $sched_route[$sched_idx] ) { + push( @json_route, { name => $route[$route_idx] } ); + $route_idx++; + $sched_idx++; + } + + # this branch is inefficient, but won't be taken frequently + elsif ( not( $route[$route_idx] ~~ \@sched_route ) ) { + push( + @json_route, + { + name => $route[$route_idx], + isAdditional => 1 + } + ); + $route_idx++; + } + else { + push( + @json_route, + { + name => $sched_route[$sched_idx], + isCancelled => 1 + } + ); + $sched_idx++; + } + } + while ( $route_idx++ < $#route ) { + push( + @json_route, + { + name => $route[ $route_idx++ ], + isAdditional => 1, + isCancelled => 0 + } + ); + } + while ( $sched_idx++ < $#sched_route ) { + push( + @json_route, + { + name => $route[ $route_idx++ ], + isAdditional => 0, + isCancelled => 1 + } + ); + } + return @json_route; +}; + sub handle_request { my $self = shift; my $station = $self->stash('station'); @@ -374,60 +435,8 @@ sub handle_request { } if ( $template eq 'marudor' ) { - my ( $route_idx, $sched_idx ) = ( 0, 0 ); - my @json_route; - my @route = $result->route; - my @sched_route = $result->sched_route; - - while ( $route_idx <= $#route and $sched_idx <= $#sched_route ) { - if ( $route[$route_idx] eq $sched_route[$sched_idx] ) { - push( @json_route, { name => $route[$route_idx] } ); - $route_idx++; - $sched_idx++; - } - - # this branch is inefficient, but won't be taken frequently - elsif ( not( $route[$route_idx] ~~ \@sched_route ) ) { - push( - @json_route, - { - name => $route[$route_idx], - isAdditional => 1 - } - ); - $route_idx++; - } - else { - push( - @json_route, - { - name => $sched_route[$sched_idx], - isCancelled => 1 - } - ); - $sched_idx++; - } - } - while ( $route_idx++ < $#route ) { - push( - @json_route, - { - name => $route[ $route_idx++ ], - isAdditional => 1, - isCancelled => 0 - } - ); - } - while ( $sched_idx++ < $#sched_route ) { - push( - @json_route, - { - name => $route[ $route_idx++ ], - isAdditional => 0, - isCancelled => 1 - } - ); - } + my @json_route = $self->json_route_diff( [ $result->route ], + [ $result->sched_route ] ); push( @departures, @@ -480,12 +489,18 @@ sub handle_request { via => [ $result->route_interesting(3) ], scheduled_route => [ $result->sched_route ], route_post => [ $result->route_post ], - destination => $result->destination, - origin => $result->origin, - platform => $platform, - info => $info, - is_cancelled => $result->is_cancelled, - messages => { + route_post_diff => [ + $self->json_route_diff( + [ $result->route_post ], + [ $result->sched_route_post ] + ) + ], + destination => $result->destination, + origin => $result->origin, + platform => $platform, + info => $info, + is_cancelled => $result->is_cancelled, + messages => { delay => [ map { { timestamp => $_->[0], text => $_->[1] } } $result->delay_messages diff --git a/public/default.css b/public/default.css index c7159a4..e6f7ecd 100644 --- a/public/default.css +++ b/public/default.css @@ -163,6 +163,14 @@ div.displayclean li .moreinfo .mroute .generic-stop { color: #555555; } +div.displayclean li .moreinfo .mroute .additional-stop { + color: #009900; +} + +div.displayclean li .moreinfo .mroute .cancelled-stop { + color: #cc0000; +} + div.displayclean li .dest { color:#000000; /*font-weight:bold;*/ diff --git a/templates/clean.html.ep b/templates/clean.html.ep index 0bbdf54..61ee6d6 100644 --- a/templates/clean.html.ep +++ b/templates/clean.html.ep @@ -90,19 +90,25 @@ % } % } -% if ($departure->{route_post} and @{$departure->{route_post}}) { +% if ($departure->{route_post_diff} and @{$departure->{route_post_diff}}) {
Über: % my $first = 0; -% for my $stop (@{$departure->{route_post} // q{???}}) { +% for my $stop (@{$departure->{route_post_diff} // q{???}}) { % if ($first++) { % } -% if ($self->is_important($stop)) { - <%= $stop %> +% if ($stop->{isAdditional}) { + <%= $stop->{name} %> +% } +% elsif ($stop->{isCancelled}) { + <%= $stop->{name} %> +% } +% elsif ($self->is_important($stop->{name})) { + <%= $stop->{name} %> % } % else { - <%= $stop %> + <%= $stop->{name} %> % } % }
-- cgit v1.2.3