Unverified Commit 9955a3b6 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

dbris: show checkin suggestions at the top of the departure board

Suggestions for connecting trains (i.e., suggestions shown in the "checked in"
view) are not supported yet. This part is due for a major rewrite that moves
the associated departure board request to the background worker rather than
firing off a promise and delaying rendering until it has been answered.
parent 1496f452
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -1203,6 +1203,8 @@ sub station {
		}
	}

	my @suggestions;

	my $promise;
	if ($dbris_service) {
		if ( $station !~ m{ [@] L = \d+ }x ) {
@@ -1304,6 +1306,36 @@ sub station {
				if ( $station =~ m{ [@] O = (?<name> [^@]+ ) [@] }x ) {
					$status->{station_name} = $+{name};
				}

				my ($eva) = ( $station =~ m{ [@] L = (\d+) }x );
				my $backend_id
				  = $self->stations->get_backend_id( dbris => $dbris_service );
				my @destinations = $self->journeys->get_connection_targets(
					uid        => $uid,
					backend_id => $backend_id,
					eva        => $eva
				);

				for my $dep (@results) {
					destination: for my $dest (@destinations) {
						if (    $dep->destination
							and $dep->destination eq $dest->{name} )
						{
							push( @suggestions, [ $dep, $dest ] );
							next destination;
						}
						for my $via_name ( $dep->via ) {
							if ( $via_name eq $dest->{name} ) {
								push( @suggestions, [ $dep, $dest ] );
								next destination;
							}
						}
					}
				}

				@suggestions = map { $_->[0] }
				  sort { $a->[1] <=> $b->[1] }
				  map { [ $_, $_->[0]->dep->epoch ] } @suggestions;
			}
			elsif ($hafas_service) {

@@ -1449,6 +1481,7 @@ sub station {
							related_stations => $status->{related_stations},
							user_status      => $user_status,
							can_check_out    => $can_check_out,
							suggestions      => \@suggestions,
							title => "travelynx: $status->{station_name}",
						);
					}
+8 −5
Original line number Diff line number Diff line
@@ -2106,8 +2106,13 @@ sub get_connection_targets {
	  // DateTime->now( time_zone => 'Europe/Berlin' )->subtract( months => 4 );
	my $db         = $opt{db} //= $self->{pg}->db;
	my $min_count  = $opt{min_count} // 3;
	my $backend_id = $opt{backend_id};
	my $dest_id    = $opt{eva};

	$self->{log}->debug(
"get_connection_targets(uid => $uid, backend_id => $backend_id, dest_id => $dest_id)"
	);

	if ( $opt{destination_name} ) {
		return {
			eva  => $opt{eva},
@@ -2115,8 +2120,6 @@ sub get_connection_targets {
		};
	}

	my $backend_id = $opt{backend_id};

	if ( not $dest_id ) {
		( $dest_id, $backend_id ) = $self->get_latest_dest_ids(%opt);
	}
+54 −0
Original line number Diff line number Diff line
<ul class="collection departures connections">
	% for my $res (@{$suggestions}) {
		% my ($dep, $dest) = @{$res};
		% my $row_class = '';
		% my $link_class = 'action-checkin';
		% if ($dep->is_cancelled) {
			% $row_class = 'cancelled';
			% $link_class = 'action-cancelled-from';
		% }
		% if ($checkin_from) {
			<li class="collection-item <%= $row_class %> <%= $link_class %>"
			data-dbris="<%= $dbris %>"
			data-station="<%= $dep->stop_eva %>"
			data-train="<%= $dep->id %>"
			data-suffix="<%= $dep->maybe_line_no %>"
			data-ts="<%= ($dep->sched_dep // $dep->dep)->epoch %>"
			data-dest="<%= $dest->{name} %>">
		% }
		% else {
			<li class="collection-item <%= $row_class %>">
		% }
			<a class="dep-time" href="#">
				% if ($dep->is_cancelled) {
					%= $dep->sched_dep->strftime('%H:%M')
				% }
				% else {
					%= $dep->dep->strftime('%H:%M')
				% }
				% if ($dep->delay) {
					%= sprintf('(%+d)', $dep->delay)
				% }
			</a>
			<span class="connect-platform-wrapper">
				% if ($dep->platform) {
					<span>
						% if (($dep->type // q{}) =~ m{ ast | bus | ruf }ix) {
							Steig
						% }
						% else {
							Gleis
						% }
						%= $dep->platform
					</span>
				% }
				<span class="dep-line <%= $dep->type // q{} %>">
					%= $dep->line
				</span>
			</span>
			<span class="dep-dest">
				%= $dest->{name}
			</span>
		</li>
	% }
</ul>
+6 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@
		</div>
	</div>
% }
% elsif (not param('train') and (@{stash('connections_iris') // []} or @{stash('connections_hafas') // []}) ) {
% elsif (not param('train') and (@{stash('connections_iris') // []} or @{stash('connections_hafas') // []} or @{stash('suggestions') // []}) ) {
	% $have_connections = 1;
	<div class="row">
		<div class="col s12">
@@ -99,6 +99,11 @@
			% if (@{stash('connections_hafas') // []}) {
				%= include '_connections_hafas', connections => stash('connections_hafas'), checkin_from => $eva;
			% }
			% if (@{stash('suggestions') // []}) {
				% if ($dbris) {
					%= include '_suggestions_dbris', suggestions => stash('suggestions'), checkin_from => $eva;
				% }
			% }
		</div>
	</div>
% }