From ca502c12ffbb63d42f7088be770caae9d3a836d8 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 2 Nov 2018 15:06:57 +0100 Subject: Split up App/Infoscreen into separate templates They're identical for now. --- index.pl | 47 ++++--- templates/app.html.ep | 280 ++++++++++++++++++++++++++++++++++++++ templates/clean.html.ep | 280 -------------------------------------- templates/infoscreen.html.ep | 280 ++++++++++++++++++++++++++++++++++++++ templates/layouts/default.html.ep | 4 +- 5 files changed, 590 insertions(+), 301 deletions(-) create mode 100644 templates/app.html.ep delete mode 100644 templates/clean.html.ep create mode 100644 templates/infoscreen.html.ep diff --git a/index.pl b/index.pl index 2dfb08d..d274caa 100644 --- a/index.pl +++ b/index.pl @@ -19,7 +19,7 @@ our $VERSION = qx{git describe --dirty} || '0.05'; my %default = ( backend => 'iris', - mode => 'clean', + mode => 'app', admode => 'deparr', ); @@ -37,7 +37,7 @@ sub get_results_for { my $data; my $cache_hafas = Cache::File->new( - cache_root => $ENV{DBFAKEDISPLAY_HAFAS_CACHE} // '/tmp/dbf-hafas', + cache_root => $ENV{DBFAKEDISPLAY_HAFAS_CACHE} // '/tmp/dbf-hafas', default_expires => '180 seconds', lock_level => Cache::File::LOCK_LOCAL(), ); @@ -167,7 +167,7 @@ helper 'handle_no_results' => sub { } $self->render( 'landingpage', - error => ( $errstr // "Got no results for '$station'" ), + error => ( $errstr // "Got no results for '$station'" ), hide_opts => 0 ); return; @@ -314,20 +314,20 @@ sub handle_request { my $via = $self->param('via'); my @platforms = split( /,/, $self->param('platforms') // q{} ); - my @lines = split( /,/, $self->param('lines') // q{} ); - my $template = $self->param('mode') // 'clean'; - my $hide_low_delay = $self->param('hidelowdelay') // 0; - my $hide_opts = $self->param('hide_opts') // 0; + my @lines = split( /,/, $self->param('lines') // q{} ); + my $template = $self->param('mode') // 'app'; + my $hide_low_delay = $self->param('hidelowdelay') // 0; + my $hide_opts = $self->param('hide_opts') // 0; my $show_realtime = $self->param('show_realtime') // 0; - my $show_details = $self->param('detailed') // 0; - my $backend = $self->param('backend') // 'iris'; - my $admode = $self->param('admode') // 'deparr'; - my $dark_layout = $self->param('dark') // 0; - my $apiver = $self->param('version') // 0; + my $show_details = $self->param('detailed') // 0; + my $backend = $self->param('backend') // 'iris'; + my $admode = $self->param('admode') // 'deparr'; + my $dark_layout = $self->param('dark') // 0; + my $apiver = $self->param('version') // 0; my $callback = $self->param('callback'); my $with_related = !$self->param('no_related'); my $save_defaults = $self->param('save_defaults') // 0; - my @train_types = split( /,/, $self->param('train_types') // q{} ); + my @train_types = split( /,/, $self->param('train_types') // q{} ); my %opt; my $api_version @@ -357,8 +357,11 @@ sub handle_request { $self->stash( layout => 'text' ); } - if ( not( $template ~~ [qw[clean json marudor multi single text]] ) ) { - $template = 'clean'; + if ( + not( $template ~~ [qw[app infoscreen json marudor multi single text]] ) + ) + { + $template = 'app'; } if ( not $station ) { @@ -494,7 +497,7 @@ sub handle_request { $info = "Zug endet hier: ${delaymsg}"; } elsif ( $result->delay and $result->delay > 0 ) { - if ( $template eq 'clean' ) { + if ( $template eq 'app' or $template eq 'infoscreen' ) { $info = $delaymsg; } else { @@ -502,7 +505,10 @@ sub handle_request { $result->delay, $delaymsg ? q{: } : q{}, $delaymsg ); } } - if ( $result->replacement_for and $template ne 'clean' ) { + if ( $result->replacement_for + and $template ne 'app' + and $template ne 'infoscreen' ) + { for my $rep ( $result->replacement_for ) { $info = sprintf( 'Ersatzzug für %s %s %s%s', @@ -921,7 +927,10 @@ sub handle_request { hide_opts => $hide_opts, hide_low_delay => $hide_low_delay, show_realtime => $show_realtime, - load_marquee => ($template eq 'single' or $template eq 'multi'), + load_marquee => ( + $template eq 'single' + or $template eq 'multi' + ), ); } return; @@ -985,7 +994,7 @@ post '/_geolocation' => sub { lat => $_->[0][4], distance => $_->[1], } - } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, + } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, $lat, 10 ); $self->render( json => { diff --git a/templates/app.html.ep b/templates/app.html.ep new file mode 100644 index 0000000..3c36965 --- /dev/null +++ b/templates/app.html.ep @@ -0,0 +1,280 @@ +% if (@{$departures}) { + +% if (param('dark')) { +
+% } +% else { +
+% } +
    +% my $i = 0; +% my $dt_now = DateTime->now; +% for my $departure (@{$departures}) { +% $i++; +% my $route_str = q{}; +% my $via_max = @{$departure->{via} // []}; +% my $via_cur = 0; +% for my $stop (@{$departure->{via} // []}) { +% $via_cur++; +% $route_str .= $stop . ($via_cur < $via_max ? ' - ' : q{}); +% } +% my $extraclasses = q{}; +% if ($departure->{is_cancelled} or $departure->{departure_is_cancelled}) { +% $extraclasses .= ' cancelled'; +
  • +% } +% else { +
  • +% } +% my $linetype = 'bahn'; +% if ( $departure->{train_type} eq 'S' ) { +% $linetype = 'sbahn'; +% } +% elsif ( $departure->{train_type} eq 'IC' +% or $departure->{train_type} eq 'ICE' +% or $departure->{train_type} eq 'EC' +% or $departure->{train_type} eq 'THA' ) { +% $linetype = 'fern'; +% } +
    + % if ($departure->{train_type} and $departure->{train_no}) { +%= $departure->{train_type} +% } +% if ($departure->{train_line} ) { +%= $departure->{train_line} +% } +% elsif ($departure->{train_no}) { + <%= $departure->{train_no} %> +% } +% else { +%= $departure->{train} +% } +% if ($departure->{train_line} and $departure->{train_no} +% and $departure->{train_line} ne $departure->{train_no} +% and param('detailed')) { +
    <%= $departure->{train_no} %>
    +% } +
    +% if (@{$departure->{replaced_by}} or @{$departure->{replacement_for}}) { +
    +% if (@{$departure->{replaced_by}}) { + %#→ Ersatzzug +% } +% if (@{$departure->{replacement_for}}) { + Ersatzzug +% } +
    +% } +
    + +
    +
    +% if ($departure->{scheduled_platform} or $departure->{platform}) { + Gleis <%= $departure->{scheduled_platform} // $departure->{platform} %> +% } +% if ($departure->{scheduled_platform} and $departure->{platform} +% and $departure->{scheduled_platform} ne $departure->{platform}) { + (heute Gleis <%= $departure->{platform} %>) +% } +% elsif ($departure->{changed_platform}) { + (Gleiswechsel) +% } +
    +% if (not $departure->{is_cancelled}) { +
    +% if ($departure->{sched_arrival}) { + Ankunft: <%= $departure->{sched_arrival} %> +% if ($departure->{arrival} and $departure->{arrival} ne $departure->{sched_arrival}) { + (heute <%= $departure->{arrival} %>) +% } +
    +% } +% if ($departure->{sched_departure}) { + Abfahrt: <%= $departure->{sched_departure} %> +% if ($departure->{departure} and $departure->{departure} ne $departure->{sched_departure}) { + (heute <%= $departure->{departure} %>) +% } +
    +% } +% if (not ($departure->{sched_arrival} or $departure->{sched_departure})) { + Abfahrt: <%= $departure->{time} %> +% if ($departure->{delay}) { + (heute +<%= $departure->{delay} %>) +% } +% } +
    +% } +% if ($departure->{route_post_diff} and @{$departure->{route_post_diff}}) { +
    + Über: +% my $first = 0; +% for my $stop (@{$departure->{route_post_diff} // q{???}}) { +% if ($first++) { + +% } +% if ($stop->{isAdditional}) { + <%= $stop->{name} %> +% } +% elsif ($stop->{isCancelled}) { + <%= $stop->{name} %> +% } +% elsif ($self->is_important($stop->{name})) { + <%= $stop->{name} %> +% } +% else { + <%= $stop->{name} %> +% } +% } +
    +% } +% if ($departure->{moreinfo} and @{$departure->{moreinfo}}) { + Meldungen: +
      +% for my $pair (@{$departure->{moreinfo}}) { +
    • +% if ($pair->[0]->isa('DateTime')) { +% if ($pair->[0]->day != $dt_now->day) { +% $pair->[0]->set_locale('de_DE'); +%= $pair->[0]->strftime('%a %H:%M') +% } +% else { +%= $pair->[0]->strftime('%H:%M') +% } +% } +% else { +%= $pair->[0] +% } + : + +%= $pair->[1] + +
    • +% } +% if ($departure->{route_info}) { +
    • <%= $departure->{route_info} %>
    • +% } +
    +% } +
    +
    +% if ($departure->{info} and length $departure->{info}) { + +%= $departure->{info} + +% } +% else { + +%= $route_str + +% } + +%= $departure->{destination} + + +% if ($departure->{delay} and not $departure->{is_cancelled}) { +% if ($show_realtime) { +% if ($departure->{delay} > 0) { + (+<%= $departure->{delay} %>) +% } +% else { + (<%= $departure->{delay} %>) +% } +% } +% else { +% if ($departure->{delay} > 0) { + (+<%= $departure->{delay} %>) +% } +% else { + (<%= $departure->{delay} %>) +% } +% } +% } +% if (($departure->{scheduled_platform} and $departure->{platform} and +% $departure->{scheduled_platform} ne $departure->{platform}) +% or $departure->{changed_platform}) { + +% } +% else { + +% } +%= $departure->{platform} + + + +% if (param('detailed')) { +% my $arrow = '→'; +% if (not $departure->{sched_arrival}) { +% $arrow = '↦'; +% } +% elsif (not $departure->{sched_departure}) { +% $arrow = '⇥'; +% } +% if ($show_realtime) { +%= ($departure->{arrival} // q{}) . $arrow . ($departure->{departure} // q{}) +% } +% else { +%= ($departure->{sched_arrival} // q{}) . $arrow . ($departure->{sched_departure} // q{}) +% } +% } +% else { +%= $departure->{time} +% } + +
  • + +% } + +
+
+ +% } +% else { + +
+
Keine Abfahrten gefunden. +Möglicherweise ist der Filter zu restriktiv, oder an dieser Station fahren +momentan keine Züge.
+
+ +% } diff --git a/templates/clean.html.ep b/templates/clean.html.ep deleted file mode 100644 index 3c36965..0000000 --- a/templates/clean.html.ep +++ /dev/null @@ -1,280 +0,0 @@ -% if (@{$departures}) { - -% if (param('dark')) { -
-% } -% else { -
-% } -
    -% my $i = 0; -% my $dt_now = DateTime->now; -% for my $departure (@{$departures}) { -% $i++; -% my $route_str = q{}; -% my $via_max = @{$departure->{via} // []}; -% my $via_cur = 0; -% for my $stop (@{$departure->{via} // []}) { -% $via_cur++; -% $route_str .= $stop . ($via_cur < $via_max ? ' - ' : q{}); -% } -% my $extraclasses = q{}; -% if ($departure->{is_cancelled} or $departure->{departure_is_cancelled}) { -% $extraclasses .= ' cancelled'; -
  • -% } -% else { -
  • -% } -% my $linetype = 'bahn'; -% if ( $departure->{train_type} eq 'S' ) { -% $linetype = 'sbahn'; -% } -% elsif ( $departure->{train_type} eq 'IC' -% or $departure->{train_type} eq 'ICE' -% or $departure->{train_type} eq 'EC' -% or $departure->{train_type} eq 'THA' ) { -% $linetype = 'fern'; -% } -
    - % if ($departure->{train_type} and $departure->{train_no}) { -%= $departure->{train_type} -% } -% if ($departure->{train_line} ) { -%= $departure->{train_line} -% } -% elsif ($departure->{train_no}) { - <%= $departure->{train_no} %> -% } -% else { -%= $departure->{train} -% } -% if ($departure->{train_line} and $departure->{train_no} -% and $departure->{train_line} ne $departure->{train_no} -% and param('detailed')) { -
    <%= $departure->{train_no} %>
    -% } -
    -% if (@{$departure->{replaced_by}} or @{$departure->{replacement_for}}) { -
    -% if (@{$departure->{replaced_by}}) { - %#→ Ersatzzug -% } -% if (@{$departure->{replacement_for}}) { - Ersatzzug -% } -
    -% } -
    - -
    -
    -% if ($departure->{scheduled_platform} or $departure->{platform}) { - Gleis <%= $departure->{scheduled_platform} // $departure->{platform} %> -% } -% if ($departure->{scheduled_platform} and $departure->{platform} -% and $departure->{scheduled_platform} ne $departure->{platform}) { - (heute Gleis <%= $departure->{platform} %>) -% } -% elsif ($departure->{changed_platform}) { - (Gleiswechsel) -% } -
    -% if (not $departure->{is_cancelled}) { -
    -% if ($departure->{sched_arrival}) { - Ankunft: <%= $departure->{sched_arrival} %> -% if ($departure->{arrival} and $departure->{arrival} ne $departure->{sched_arrival}) { - (heute <%= $departure->{arrival} %>) -% } -
    -% } -% if ($departure->{sched_departure}) { - Abfahrt: <%= $departure->{sched_departure} %> -% if ($departure->{departure} and $departure->{departure} ne $departure->{sched_departure}) { - (heute <%= $departure->{departure} %>) -% } -
    -% } -% if (not ($departure->{sched_arrival} or $departure->{sched_departure})) { - Abfahrt: <%= $departure->{time} %> -% if ($departure->{delay}) { - (heute +<%= $departure->{delay} %>) -% } -% } -
    -% } -% if ($departure->{route_post_diff} and @{$departure->{route_post_diff}}) { -
    - Über: -% my $first = 0; -% for my $stop (@{$departure->{route_post_diff} // q{???}}) { -% if ($first++) { - -% } -% if ($stop->{isAdditional}) { - <%= $stop->{name} %> -% } -% elsif ($stop->{isCancelled}) { - <%= $stop->{name} %> -% } -% elsif ($self->is_important($stop->{name})) { - <%= $stop->{name} %> -% } -% else { - <%= $stop->{name} %> -% } -% } -
    -% } -% if ($departure->{moreinfo} and @{$departure->{moreinfo}}) { - Meldungen: -
      -% for my $pair (@{$departure->{moreinfo}}) { -
    • -% if ($pair->[0]->isa('DateTime')) { -% if ($pair->[0]->day != $dt_now->day) { -% $pair->[0]->set_locale('de_DE'); -%= $pair->[0]->strftime('%a %H:%M') -% } -% else { -%= $pair->[0]->strftime('%H:%M') -% } -% } -% else { -%= $pair->[0] -% } - : - -%= $pair->[1] - -
    • -% } -% if ($departure->{route_info}) { -
    • <%= $departure->{route_info} %>
    • -% } -
    -% } -
    -
    -% if ($departure->{info} and length $departure->{info}) { - -%= $departure->{info} - -% } -% else { - -%= $route_str - -% } - -%= $departure->{destination} - - -% if ($departure->{delay} and not $departure->{is_cancelled}) { -% if ($show_realtime) { -% if ($departure->{delay} > 0) { - (+<%= $departure->{delay} %>) -% } -% else { - (<%= $departure->{delay} %>) -% } -% } -% else { -% if ($departure->{delay} > 0) { - (+<%= $departure->{delay} %>) -% } -% else { - (<%= $departure->{delay} %>) -% } -% } -% } -% if (($departure->{scheduled_platform} and $departure->{platform} and -% $departure->{scheduled_platform} ne $departure->{platform}) -% or $departure->{changed_platform}) { - -% } -% else { - -% } -%= $departure->{platform} - - - -% if (param('detailed')) { -% my $arrow = '→'; -% if (not $departure->{sched_arrival}) { -% $arrow = '↦'; -% } -% elsif (not $departure->{sched_departure}) { -% $arrow = '⇥'; -% } -% if ($show_realtime) { -%= ($departure->{arrival} // q{}) . $arrow . ($departure->{departure} // q{}) -% } -% else { -%= ($departure->{sched_arrival} // q{}) . $arrow . ($departure->{sched_departure} // q{}) -% } -% } -% else { -%= $departure->{time} -% } - -
  • - -% } - -
-
- -% } -% else { - -
-
Keine Abfahrten gefunden. -Möglicherweise ist der Filter zu restriktiv, oder an dieser Station fahren -momentan keine Züge.
-
- -% } diff --git a/templates/infoscreen.html.ep b/templates/infoscreen.html.ep new file mode 100644 index 0000000..3c36965 --- /dev/null +++ b/templates/infoscreen.html.ep @@ -0,0 +1,280 @@ +% if (@{$departures}) { + +% if (param('dark')) { +
+% } +% else { +
+% } +
    +% my $i = 0; +% my $dt_now = DateTime->now; +% for my $departure (@{$departures}) { +% $i++; +% my $route_str = q{}; +% my $via_max = @{$departure->{via} // []}; +% my $via_cur = 0; +% for my $stop (@{$departure->{via} // []}) { +% $via_cur++; +% $route_str .= $stop . ($via_cur < $via_max ? ' - ' : q{}); +% } +% my $extraclasses = q{}; +% if ($departure->{is_cancelled} or $departure->{departure_is_cancelled}) { +% $extraclasses .= ' cancelled'; +
  • +% } +% else { +
  • +% } +% my $linetype = 'bahn'; +% if ( $departure->{train_type} eq 'S' ) { +% $linetype = 'sbahn'; +% } +% elsif ( $departure->{train_type} eq 'IC' +% or $departure->{train_type} eq 'ICE' +% or $departure->{train_type} eq 'EC' +% or $departure->{train_type} eq 'THA' ) { +% $linetype = 'fern'; +% } +
    + % if ($departure->{train_type} and $departure->{train_no}) { +%= $departure->{train_type} +% } +% if ($departure->{train_line} ) { +%= $departure->{train_line} +% } +% elsif ($departure->{train_no}) { + <%= $departure->{train_no} %> +% } +% else { +%= $departure->{train} +% } +% if ($departure->{train_line} and $departure->{train_no} +% and $departure->{train_line} ne $departure->{train_no} +% and param('detailed')) { +
    <%= $departure->{train_no} %>
    +% } +
    +% if (@{$departure->{replaced_by}} or @{$departure->{replacement_for}}) { +
    +% if (@{$departure->{replaced_by}}) { + %#→ Ersatzzug +% } +% if (@{$departure->{replacement_for}}) { + Ersatzzug +% } +
    +% } +
    + +
    +
    +% if ($departure->{scheduled_platform} or $departure->{platform}) { + Gleis <%= $departure->{scheduled_platform} // $departure->{platform} %> +% } +% if ($departure->{scheduled_platform} and $departure->{platform} +% and $departure->{scheduled_platform} ne $departure->{platform}) { + (heute Gleis <%= $departure->{platform} %>) +% } +% elsif ($departure->{changed_platform}) { + (Gleiswechsel) +% } +
    +% if (not $departure->{is_cancelled}) { +
    +% if ($departure->{sched_arrival}) { + Ankunft: <%= $departure->{sched_arrival} %> +% if ($departure->{arrival} and $departure->{arrival} ne $departure->{sched_arrival}) { + (heute <%= $departure->{arrival} %>) +% } +
    +% } +% if ($departure->{sched_departure}) { + Abfahrt: <%= $departure->{sched_departure} %> +% if ($departure->{departure} and $departure->{departure} ne $departure->{sched_departure}) { + (heute <%= $departure->{departure} %>) +% } +
    +% } +% if (not ($departure->{sched_arrival} or $departure->{sched_departure})) { + Abfahrt: <%= $departure->{time} %> +% if ($departure->{delay}) { + (heute +<%= $departure->{delay} %>) +% } +% } +
    +% } +% if ($departure->{route_post_diff} and @{$departure->{route_post_diff}}) { +
    + Über: +% my $first = 0; +% for my $stop (@{$departure->{route_post_diff} // q{???}}) { +% if ($first++) { + +% } +% if ($stop->{isAdditional}) { + <%= $stop->{name} %> +% } +% elsif ($stop->{isCancelled}) { + <%= $stop->{name} %> +% } +% elsif ($self->is_important($stop->{name})) { + <%= $stop->{name} %> +% } +% else { + <%= $stop->{name} %> +% } +% } +
    +% } +% if ($departure->{moreinfo} and @{$departure->{moreinfo}}) { + Meldungen: +
      +% for my $pair (@{$departure->{moreinfo}}) { +
    • +% if ($pair->[0]->isa('DateTime')) { +% if ($pair->[0]->day != $dt_now->day) { +% $pair->[0]->set_locale('de_DE'); +%= $pair->[0]->strftime('%a %H:%M') +% } +% else { +%= $pair->[0]->strftime('%H:%M') +% } +% } +% else { +%= $pair->[0] +% } + : + +%= $pair->[1] + +
    • +% } +% if ($departure->{route_info}) { +
    • <%= $departure->{route_info} %>
    • +% } +
    +% } +
    +
    +% if ($departure->{info} and length $departure->{info}) { + +%= $departure->{info} + +% } +% else { + +%= $route_str + +% } + +%= $departure->{destination} + + +% if ($departure->{delay} and not $departure->{is_cancelled}) { +% if ($show_realtime) { +% if ($departure->{delay} > 0) { + (+<%= $departure->{delay} %>) +% } +% else { + (<%= $departure->{delay} %>) +% } +% } +% else { +% if ($departure->{delay} > 0) { + (+<%= $departure->{delay} %>) +% } +% else { + (<%= $departure->{delay} %>) +% } +% } +% } +% if (($departure->{scheduled_platform} and $departure->{platform} and +% $departure->{scheduled_platform} ne $departure->{platform}) +% or $departure->{changed_platform}) { + +% } +% else { + +% } +%= $departure->{platform} + + + +% if (param('detailed')) { +% my $arrow = '→'; +% if (not $departure->{sched_arrival}) { +% $arrow = '↦'; +% } +% elsif (not $departure->{sched_departure}) { +% $arrow = '⇥'; +% } +% if ($show_realtime) { +%= ($departure->{arrival} // q{}) . $arrow . ($departure->{departure} // q{}) +% } +% else { +%= ($departure->{sched_arrival} // q{}) . $arrow . ($departure->{sched_departure} // q{}) +% } +% } +% else { +%= $departure->{time} +% } + +
  • + +% } + +
+
+ +% } +% else { + +
+
Keine Abfahrten gefunden. +Möglicherweise ist der Filter zu restriktiv, oder an dieser Station fahren +momentan keine Züge.
+
+ +% } diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 1929569..78a962f 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -83,7 +83,7 @@ Bitte eine Station aus der Liste auswählen
Frontend
- %= select_field mode => [ ['App / Infoscreen' => 'clean'], ['Bahnhofstafel' => 'multi'], ['Gleis' => 'single'] ] + %= select_field mode => [ ['App' => 'app'], ['Infoscreen' => 'infoscreen'], ['Bahnhofstafel' => 'multi'], ['Gleisanzeiger' => 'single'] ]
@@ -191,7 +191,7 @@ Bitte eine Station aus der Liste auswählen
  • Essen HBf (IRIS, Bahnhofstafel)
  • Dortmund HBf (IRIS, Bahnhofstafel, nur Züge via Bochum oder Hamm)
  • -
  • Dortmund Universität (IRIS, Mobile/Infoscreen)
  • +
  • Dortmund Universität (IRIS, Infoscreen)
  • Düsseldorf HBf (IRIS, Gleistafel)
  • -- cgit v1.2.3