diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-12-25 17:27:57 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-12-25 17:27:57 +0100 |
commit | 0f9dde3810a3b86e0769e6013a19ccf0faeba0a3 (patch) | |
tree | cd2c4a5f2b9914f1e6d335f00038c12ebe66d209 /lib/DBInfoscreen/Controller/Wagenreihung.pm | |
parent | 7d29c0f25f4d7e4e47ea726bcdac1985da866126 (diff) |
add wagon images for IC and ICE 1/2/4
IC2, ICE 3 and ICE T will follow soon.
Diffstat (limited to 'lib/DBInfoscreen/Controller/Wagenreihung.pm')
-rw-r--r-- | lib/DBInfoscreen/Controller/Wagenreihung.pm | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/DBInfoscreen/Controller/Wagenreihung.pm b/lib/DBInfoscreen/Controller/Wagenreihung.pm index 4707d03..073d762 100644 --- a/lib/DBInfoscreen/Controller/Wagenreihung.pm +++ b/lib/DBInfoscreen/Controller/Wagenreihung.pm @@ -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; |