diff options
-rw-r--r-- | index.pl | 135 | ||||
-rw-r--r-- | public/default.css | 8 | ||||
-rw-r--r-- | templates/clean.html.ep | 16 |
3 files changed, 94 insertions, 65 deletions
@@ -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 @@ % } </div> <!-- timeinfo --> % } -% if ($departure->{route_post} and @{$departure->{route_post}}) { +% if ($departure->{route_post_diff} and @{$departure->{route_post_diff}}) { <div class="mroute"> Über: % my $first = 0; -% for my $stop (@{$departure->{route_post} // q{???}}) { +% for my $stop (@{$departure->{route_post_diff} // q{???}}) { % if ($first++) { <span class="separator">–</span> % } -% if ($self->is_important($stop)) { - <span class="important-stop"><%= $stop %></span> +% if ($stop->{isAdditional}) { + <span class="additional-stop"><%= $stop->{name} %></span> +% } +% elsif ($stop->{isCancelled}) { + <span class="cancelled-stop"><%= $stop->{name} %></span> +% } +% elsif ($self->is_important($stop->{name})) { + <span class="important-stop"><%= $stop->{name} %></span> % } % else { - <span class="generic-stop"><%= $stop %></span> + <span class="generic-stop"><%= $stop->{name} %></span> % } % } </div> <!-- mroute --> |