Commit 4f0fee77 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

show cancelled trains in connections list

parent 613f7d60
Loading
Loading
Loading
Loading
+42 −9
Original line number Diff line number Diff line
@@ -2276,6 +2276,7 @@ sub startup {
			  map { [ $_, $_->departure ? $_->departure->epoch : 0 ] }
			  @{ $stationboard->{results} };
			my @results;
			my @cancellations;
			my %via_count = map { $_ => 0 } @destinations;
			for my $train ( @{ $stationboard->{results} } ) {
				if ( not $train->departure ) {
@@ -2291,6 +2292,34 @@ sub startup {
				{
					next;
				}

             # In general, this function is meant to return feasible
             # connections. However, cancelled connections may also be of
             # interest and are also useful for logging cancellations.
             # To satisfy both demands with (hopefully) little confusion and
             # UI clutter, this function returns two concatenated arrays:
             # actual connections (ordered by actual departure time) followed
             # by cancelled connections (ordered by scheduled departure time).
             # This is easiest to achieve in two separate loops.
             #
             # Note that a cancelled train may still have a matching destination
             # in its route_post, e.g. if it leaves out $ds100 due to
             # unscheduled route changes but continues on schedule afterwards
             # -- so it is only cancelled at $ds100, not on the remainder of
             # the route. Also note that this specific case is not yet handled
             # properly by the cancellation logic etc.

				if ( $train->departure_is_cancelled ) {
					my @via
					  = ( $train->sched_route_post, $train->sched_route_end );
					for my $dest (@destinations) {
						if ( List::Util::any { $_ eq $dest } @via ) {
							push( @cancellations, [ $train, $dest ] );
							next;
						}
					}
				}
				else {
					my @via = ( $train->route_post, $train->route_end );
					for my $dest (@destinations) {
						if ( $via_count{$dest} < 2
@@ -2302,6 +2331,7 @@ sub startup {
						}
					}
				}
			}

			@results = map { $_->[0] }
			  sort { $a->[1] <=> $b->[1] }
@@ -2311,8 +2341,11 @@ sub startup {
					$_->[0]->departure->epoch // $_->[0]->sched_departure->epoch
				]
			  } @results;
			@cancellations = map { $_->[0] }
			  sort { $a->[1] <=> $b->[1] }
			  map { [ $_, $_->[0]->sched_departure->epoch ] } @cancellations;

			return @results;
			return ( @results, @cancellations );
		}
	);

+37 −12
Original line number Diff line number Diff line
<div class="hide-on-med-and-up"><table class="striped"><tbody>
	% for my $res (@{$connections}) {
		% my ($train, $via) = @{$res};
		% my $td_class = '';
		% my $link_class = 'action-checkin';
		% if ($train->is_cancelled) {
			% $td_class = 'cancelled';
			% $link_class = 'action-cancelled-from';
		% }
		<tr>
			<td>
			<td class="<%= $td_class %>">
				% if ($checkin_from) {
					<a class="action-checkin" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $train->line %></a>
					<a class="<%= $link_class %>" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $train->line %></a>
				% }
				% else {
					%= $train->line
				% }
			</td>
			<td>
			<td class="<%= $td_class %>">
				% if ($checkin_from) {
					<a class="action-checkin" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $via %></a>
					<a class="<%= $link_class %>" data-station="<%= $train->station_uic %>" data-train="<%= $train->train_id %>" data-dest="<%= $via %>"><%= $via %></a>
				% }
				% else {
					%= $via
				% }
			</td>
			<td><%= $train->departure->strftime('%H:%M') %>
			<td>
				% if ($train->departure_is_cancelled) {
					%= $train->sched_departure->strftime('%H:%M')

				% }
				% else {
					%= $train->departure->strftime('%H:%M')
					% if ($train->departure_delay) {
						%= sprintf('(%+d)', $train->departure_delay)
					% }
				<br/>Gleis <%= $train->platform || '?' %></td>
					<br/>Gleis <%= $train->platform || '?' %>
				% }
			</td>
		</tr>
	% }
</tbody></table></div>
@@ -52,11 +66,22 @@
					%= $via
				% }
			</td>
			<td><%= $train->departure->strftime('%H:%M') %>
			<td>
				% if ($train->departure_is_cancelled) {
					%= $train->sched_departure->strftime('%H:%M')
					(fällt aus)
				% }
				% else {
					%= $train->departure->strftime('%H:%M')
					% if ($train->departure_delay) {
						%= sprintf('(%+d)', $train->departure_delay)
					% }
			</td><td>Gleis <%= $train->platform || '?' %></td>
				% }
			</td><td>
				% if (not $train->departure_is_cancelled) {
					Gleis <%= $train->platform || '?' %>
				% }
			</td>
		</tr>
	% }
</tbody></table></div>