Loading lib/DBInfoscreen/Controller/Stationboard.pm +23 −2 Original line number Diff line number Diff line Loading @@ -560,6 +560,9 @@ sub render_train { my $stationinfo_req = Mojo::Promise->new; my $route_req = Mojo::Promise->new; my @requests = ( $wagonorder_req, $utilization_req, $stationinfo_req, $route_req ); if ( $departure->{wr_link} ) { $self->wagonorder->is_available_p( $result, $departure->{wr_link} ) ->then( Loading Loading @@ -769,9 +772,27 @@ sub render_train { } )->wait; if ( $self->param('detailed') ) { my $cycle_req = Mojo::Promise->new; push( @requests, $cycle_req ); $self->wagonorder->has_umlauf_p( $result->train_no )->then( sub { $departure->{has_cycle} = 1; } )->catch( sub { # nop } )->finally( sub { $cycle_req->resolve; return; } )->wait; } # Defer rendering until all requests have completed Mojo::Promise->all( $wagonorder_req, $utilization_req, $stationinfo_req, $route_req )->then( Mojo::Promise->all(@requests)->then( sub { $self->render( $template // '_train_details', Loading lib/DBInfoscreen/Helper/Wagonorder.pm +42 −0 Original line number Diff line number Diff line package DBInfoscreen::Helper::Wagonorder; # Copyright (C) 2011-2020 Daniel Friesel # # SPDX-License-Identifier: BSD-2-Clause Loading Loading @@ -56,6 +57,47 @@ sub is_available_p { return $promise; } sub has_umlauf_p { my ( $self, $train_no ) = @_; my $promise = Mojo::Promise->new; my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"; my $cache = $self->{main_cache}; if ( my $content = $cache->get($url) ) { if ( $content eq 'y' ) { return $promise->resolve; } else { return $promise->reject; } } $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} ) ->then( sub { my ($tx) = @_; if ( $tx->result->is_success ) { $cache->set( $url, 'y' ); $promise->resolve; } else { $cache->set( $url, 'n' ); $promise->reject; } return; } )->catch( sub { $cache->set( $url, 'n' ); $promise->reject; return; } )->wait; return $promise; } sub check_wagonorder_p { my ( $self, $train_no, $wr_link ) = @_; Loading templates/_train_details.html.ep +3 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,9 @@ % } </ul> <!-- mroute --> % } % if (param('detailed') and $departure->{has_cycle}) { <div><a href="https://lib.finalrewind.org/dbdb/db_umlauf/<%= $departure->{train_no} %>.png">Umlaufplan</a></div> % } % if (param('detailed') and $details->{commonAttr}) { % if ($details->{attrVariants} and (not $details->{commonAttr}{vmax} or not $details->{commonAttr}{brakingPercentage})) { <div class="db-attr"> Loading Loading
lib/DBInfoscreen/Controller/Stationboard.pm +23 −2 Original line number Diff line number Diff line Loading @@ -560,6 +560,9 @@ sub render_train { my $stationinfo_req = Mojo::Promise->new; my $route_req = Mojo::Promise->new; my @requests = ( $wagonorder_req, $utilization_req, $stationinfo_req, $route_req ); if ( $departure->{wr_link} ) { $self->wagonorder->is_available_p( $result, $departure->{wr_link} ) ->then( Loading Loading @@ -769,9 +772,27 @@ sub render_train { } )->wait; if ( $self->param('detailed') ) { my $cycle_req = Mojo::Promise->new; push( @requests, $cycle_req ); $self->wagonorder->has_umlauf_p( $result->train_no )->then( sub { $departure->{has_cycle} = 1; } )->catch( sub { # nop } )->finally( sub { $cycle_req->resolve; return; } )->wait; } # Defer rendering until all requests have completed Mojo::Promise->all( $wagonorder_req, $utilization_req, $stationinfo_req, $route_req )->then( Mojo::Promise->all(@requests)->then( sub { $self->render( $template // '_train_details', Loading
lib/DBInfoscreen/Helper/Wagonorder.pm +42 −0 Original line number Diff line number Diff line package DBInfoscreen::Helper::Wagonorder; # Copyright (C) 2011-2020 Daniel Friesel # # SPDX-License-Identifier: BSD-2-Clause Loading Loading @@ -56,6 +57,47 @@ sub is_available_p { return $promise; } sub has_umlauf_p { my ( $self, $train_no ) = @_; my $promise = Mojo::Promise->new; my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"; my $cache = $self->{main_cache}; if ( my $content = $cache->get($url) ) { if ( $content eq 'y' ) { return $promise->resolve; } else { return $promise->reject; } } $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} ) ->then( sub { my ($tx) = @_; if ( $tx->result->is_success ) { $cache->set( $url, 'y' ); $promise->resolve; } else { $cache->set( $url, 'n' ); $promise->reject; } return; } )->catch( sub { $cache->set( $url, 'n' ); $promise->reject; return; } )->wait; return $promise; } sub check_wagonorder_p { my ( $self, $train_no, $wr_link ) = @_; Loading
templates/_train_details.html.ep +3 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,9 @@ % } </ul> <!-- mroute --> % } % if (param('detailed') and $departure->{has_cycle}) { <div><a href="https://lib.finalrewind.org/dbdb/db_umlauf/<%= $departure->{train_no} %>.png">Umlaufplan</a></div> % } % if (param('detailed') and $details->{commonAttr}) { % if ($details->{attrVariants} and (not $details->{commonAttr}{vmax} or not $details->{commonAttr}{brakingPercentage})) { <div class="db-attr"> Loading