Commit 0f9dde38 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add wagon images for IC and ICE 1/2/4

IC2, ICE 3 and ICE T will follow soon.
parent 7d29c0f2
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -123,6 +123,13 @@ sub startup {
		}
	);

	$self->attr(
		dbdb_wagon => sub {
			return JSON->new->utf8->decode(
				scalar read_file('share/dbdb_wagen.json') );
		}
	);

	$self->helper(
		hafas => sub {
			my ($self) = @_;
@@ -165,6 +172,32 @@ sub startup {
		}
	);

	$self->helper(
		wagon_image => sub {
			my ( $self, $train_type, $wagon_type, $uic ) = @_;
			my $ret;
			if (    $train_type =~ m{IC(?!E)}
				and $wagon_type
				=~ m{ ^ [AB] R? k? [ipv] m m? b? d? s? z f? $ }x )
			{
				$ret = $wagon_type;
			}
			elsif ( not $uic ) {
				return;
			}
			elsif ( $train_type =~ m{ICE [12]} and $wagon_type !~ m{^I} ) {
				$ret = substr( $uic, 5, 4 );
			}
			elsif ( $train_type =~ m{ICE 4} ) {
				$ret = substr( $uic, 4, 5 );
			}
			if ( $ret and $self->app->dbdb_wagon->{$ret} ) {
				return $ret;
			}
			return;
		}
	);

	$self->helper(
		'handle_no_results' => sub {
			my ( $self, $backend, $station, $errstr ) = @_;
@@ -418,6 +451,7 @@ sub startup {

	$r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung');
	$r->get('/wr/:train')->to('wagenreihung#zugbildung_db');
	$r->get('/w/:wagon')->to('wagenreihung#wagen');

	$r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route');
	$r->get('/map/:tripid/:lineno')->to('map#route');
+61 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ package DBInfoscreen::Controller::Wagenreihung;
# SPDX-License-Identifier: BSD-2-Clause

use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON qw(decode_json encode_json);
use Mojo::Util qw(b64_encode b64_decode);

use utf8;

@@ -99,6 +101,7 @@ sub wagenreihung {
					wr_error  => scalar $@,
					train_no  => $train,
					wr        => undef,
					wref      => undef,
					hide_opts => 1,
				);
			}
@@ -114,6 +117,14 @@ sub wagenreihung {
				}
			}

			my $wref = {
				tt => $wr->train_type,
				tn => $train,
				s  => $wr->station_name,
				p  => $wr->platform
			};
			$wref = b64_encode( encode_json($wref) );

			$self->render(
				'wagenreihung',
				wr_error => undef,
@@ -121,6 +132,7 @@ sub wagenreihung {
					map { $wr->train_type . ' ' . $_ } $wr->train_numbers ),
				train_no  => $train,
				wr        => $wr,
				wref      => $wref,
				hide_opts => 1,
			);
		}
@@ -133,6 +145,7 @@ sub wagenreihung {
				wr_error  => scalar $err,
				train_no  => $train,
				wr        => undef,
				wref      => undef,
				hide_opts => 1,
			);
		}
@@ -140,4 +153,52 @@ sub wagenreihung {

}

sub wagen {
	my ($self)   = @_;
	my $wagon_id = $self->stash('wagon');
	my $wagon_no = $self->param('n');
	my $section  = $self->param('s');
	my $wref     = $self->param('r');

	if ( not $self->app->dbdb_wagon->{$wagon_id} ) {
		$self->render(
			'not_found',
			message   => "Keine Daten zu Wagentyp \"${wagon_id}\" vorhanden",
			hide_opts => 1
		);
		return;
	}

	eval { $wref = decode_json( b64_decode($wref) ); };
	if ($@) {
		$wref = {};
	}

	$wref->{wn} = $wagon_no;
	$wref->{ws} = $section;

	my $wagon_file
	  = "https://lib.finalrewind.org/dbdb/db_wagen/${wagon_id}.png";

	my $title = "Wagen $wagon_id";

	if ( $wref->{tt} and $wref->{tn} ) {
		$title = sprintf( '%s %s', $wref->{tt}, $wref->{tn} );
		if ($wagon_no) {
			$title .= " Wagen $wagon_no";
		}
		else {
			$title .= " Wagen $wagon_id";
		}
	}

	$self->render(
		'wagen',
		title      => $title,
		wagon_file => $wagon_file,
		wref       => $wref,
		hide_opts  => 1,
	);
}

1;
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -2,12 +2,12 @@
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(/static/v42/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: url(/static/v43/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
  src: local('Material Icons'),
       local('MaterialIcons-Regular'),
       url(/static/v42/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v42/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v42/fonts/MaterialIcons-Regular.ttf) format('truetype');
       url(/static/v43/fonts/MaterialIcons-Regular.woff2) format('woff2'),
       url(/static/v43/fonts/MaterialIcons-Regular.woff) format('woff'),
       url(/static/v43/fonts/MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
Loading