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

tryp type css selector: prefer train type over line number, if valid

Closes #347
parent 319b5b4f
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -36,6 +36,20 @@ use Travelynx::Model::Stations;
use Travelynx::Model::Traewelling;
use Travelynx::Model::Users;

my %valid_train_type = map { $_ => 1 } qw(
  Bus BUS NachtBus Niederflurbus Stadtbus StadtBus MetroBus PlusBus Landbus
  Regionalbus RegionalBus SB ExpressBus BSV RVV-Bus-Linie Buslinie Omnibus
  RegioBus RUF AST RufTaxi Rufbus Linientaxi
  Fhre Fh Schiff SCH KAT FERRY
  STR Tram TRAM Str Strb STB Straenbahn NachtTram Stadtbahn Niederflurstrab
  Trm S RS RER SKW METRO
  S-Bahn U M SUBWAY U-Bahn UBAHN
  Schw-B Schwebebahn H-Bahn
  RE IRE REX REGIONAL_FAST_RAIL RB MEX TER R REGIONAL_RAIL Regionalzug R-Bahn
  BRB ECD IC ICE EC ECE D IR TGV OGV EST FR TLK EIC EIP HIGHSPEED_RAIL
  LONG_DISTANCE RJ RJX NJ EN NIGHT_RAIL ICN WB FLX
);

sub check_password {
	my ( $password, $hash ) = @_;

@@ -232,6 +246,18 @@ sub startup {
		}
	);

	$self->helper(
		trip_type_css_selector => sub {
			my ( $self, @candidates ) = @_;
			for my $c (@candidates) {
				if ( defined $c and $valid_train_type{$c} ) {
					return $c;
				}
			}
			return q{};
		}
	);

	$self->helper(
		efa => sub {
			my ($self) = @_;
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
						%= $dep->{platform}
					</span>
				% }
				<span class="dep-line <%= $dep->{type} // q{} %>">
				<span class="dep-line <%= trip_type_css_selector(($travel->{type} // q{}) =~ tr{a-zA-Z_-}{}cdr, ($travel->{line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx) %>">
					%= $dep->{line}
				</span>
			</span>
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
				<i class="material-icons" aria-label="Keine Echtzeitdaten vorhanden" style="font-size: 16px;">gps_off</i>
			% }
		</a>
		<span class="dep-line <%= ($result->type // q{}) =~ tr{a-zA-Z_-}{}cdr %> <%= $result->line =~ s{ ^ \D+ \K \d .* $ }{}rx %>">
		<span class="dep-line <%= trip_type_css_selector(($travel->{type} // q{}) =~ tr{a-zA-Z_-}{}cdr, ($travel->{line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx) %>">
			%= $result->line
		</span>
		<span class="dep-dest">
+1 −1
Original line number Diff line number Diff line
% if ($journey->{extra_data}{wagonorder_pride}) {
	🏳️‍🌈
% }
<span class="dep-line <%= ($journey->{train_type} // q{}) =~ tr{a-zA-Z_-}{}cdr %> <%= ($journey->{train_line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx %>">
<span class="dep-line <%= trip_type_css_selector(($travel->{type} // q{}) =~ tr{a-zA-Z_-}{}cdr, ($travel->{line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx) %>">
	% if (not $journey->{is_motis}) {
		<%= $journey->{train_type} %>
	% }
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
			% }
			<li class="collection-item">
				<a href="<%= $detail_link %>">
					<span class="dep-line <%= ($travel->{type} // q{}) =~ tr{a-zA-Z_-}{}cdr %> <%= ($travel->{line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx %>">
					<span class="dep-line <%= trip_type_css_selector(($travel->{type} // q{}) =~ tr{a-zA-Z_-}{}cdr, ($travel->{line} // q{}) =~ s{ ^ \D+ \K \d .* $ }{}rx) %>">
						% if (length($travel->{type}) < 5 and not $travel->{is_motis}) {
							<%= $travel->{type} %>
						% }