Commit 4609b731 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

show expected wagon order whan real-time data is not available

work in progress.
parent 3c85cd22
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -90,17 +90,25 @@ sub startup {
	$self->attr(
		ice_type_map => sub {
			my $ice_type_map = JSON->new->utf8->decode(
				scalar read_file('share/ice_type.json') );
				scalar read_file('share/zugbildungsplan.json') );
			my $ret;
			while ( my ( $k, $v ) = each %{$ice_type_map} ) {
				if ( $v->{type} ) {
					$ret->{$k} = [ $v->{type}, $v->{short} ];
					$ret->{$k}
					  = [ $v->{type}, $v->{short}, exists $v->{wagon} ? 1 : 0 ];
				}
			}
			return $ret;
		}
	);

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

	$self->helper(
		hafas => sub {
			my ($self) = @_;
@@ -395,6 +403,7 @@ sub startup {
	$r->get('/_impressum')->to('static#imprint');

	$r->get('/_wr/:train/:departure')->to('wagenreihung#wagenreihung');
	$r->get('/zb-db/:train')->to('wagenreihung#zugbildung_db');

	$r->get('/_ajax_mapinfo/:tripid/:lineno')->to('map#ajax_route');
	$r->get('/map/:tripid/:lineno')->to('map#route');
+57 −0
Original line number Diff line number Diff line
package DBInfoscreen::Controller::Wagenreihung;

# Copyright (C) 2011-2020 Daniel Friesel
#
# SPDX-License-Identifier: BSD-2-Clause
@@ -6,11 +7,67 @@ package DBInfoscreen::Controller::Wagenreihung;
use Mojo::Base 'Mojolicious::Controller';

use Travel::Status::DE::DBWagenreihung;
use Travel::Status::DE::DBWagenreihung::Wagon;

my $dbf_version = qx{git describe --dirty} || 'experimental';

chomp $dbf_version;

sub zugbildung_db {
	my ($self) = @_;

	my $train_no = $self->param('train');

	my $details = $self->app->train_details_db->{$train_no};

	if ( not $details ) {
		$self->render( 'not_found',
			message => "Keine Daten zu Zug ${train_no} bekannt" );
		return;
	}

	my @wagons;

	for my $wagon_number ( sort { $a <=> $b } keys %{ $details->{wagon} } ) {
		my %wagon = (
			fahrzeugnummer      => "",
			fahrzeugtyp         => $details->{wagon}{$wagon_number},
			kategorie           => "",
			train_no            => $train_no,
			wagenordnungsnummer => $wagon_number,
			positionamhalt      => {
				startprozent => 0,
				endeprozent  => 0,
				startmeter   => 0,
				endemeter    => 0,
			}
		);
		my $wagon = Travel::Status::DE::DBWagenreihung::Wagon->new(%wagon);

		if ( $details->{type} ) {
			$wagon->set_traintype( $details->{type} );
		}
		push( @wagons, $wagon );
	}

	my $pos = 0;
	for my $wagon (@wagons) {
		$wagon->{position}{start_percent} = $pos;
		$wagon->{position}{end_percent}   = $pos + 4;
		$pos += 4;
	}

	$self->render(
		'zugbildung_db',
		wr_error  => undef,
		title     => $details->{raw} . ' ' . $train_no,
		zb        => $details,
		train_no  => $train_no,
		wagons    => [@wagons],
		hide_opts => 1,
	);
}

sub wagenreihung {
	my ($self)    = @_;
	my $train     = $self->stash('train');

share/ice_type.json

deleted100644 → 0
+0 −1

File deleted.

Preview size limit exceeded, changes collapsed.

+1 −0

File added.

Preview size limit exceeded, changes collapsed.

+3 −0
Original line number Diff line number Diff line
@@ -112,6 +112,9 @@
        <a class="smallbutton" href="/_wr/<%= $departure->{train_no} %>/<%= $departure->{wr_link} %>"><i class="material-icons" aria-hidden="true">train</i> Wagenreihung
        </a>
%     }
%     elsif ($icetype and $icetype->[2] and $linetype eq 'fern') {
        <a class="smallbutton" href="/zb-db/<%= $departure->{train_no} %>"><i class="material-icons" aria-hidden="true">train</i> Plan: <%= $icetype->[0] %></a>
%     }
%     elsif ($icetype and $icetype->[1] and $linetype eq 'fern') {
        <span class="disabledbutton"><i class="material-icons" aria-hidden="true">train</i> Plan: <%= $icetype->[0] %></span>
%     }
Loading