Skip to content

Commit

Permalink
feat: support evergreen content on Sectionals
Browse files Browse the repository at this point in the history
It was possible to *configure* evergreen content on this screen type,
but nothing actually looked at this configuration.

Other changes:

* Delete some old logic for generating placeholder widgets that would
  never be displayed.

* Simplify how candidate generator functions are specified, along the
  same lines as #2413.

* Introduce common styles for evergreen content on `bus(way|_shelter)`
  screens, and remove some redundant specification of pixel sizes that
  could instead use `100%` of the container's width/height.
  • Loading branch information
digitalcora committed Jan 27, 2025
1 parent 93f14f3 commit e914950
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 197 deletions.
4 changes: 2 additions & 2 deletions assets/css/bus_shelter_v2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

@import "v2/bus_shelter/alert";

@import "v2/bus_shelter/evergreen/image";
@import "v2/bus_shelter/evergreen/video";
@import "v2/lcd_common/evergreen";
@import "v2/bus_shelter/evergreen";

@import "v2/bus_shelter/survey";

Expand Down
2 changes: 2 additions & 0 deletions assets/css/busway_v2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@import "v2/busway/screen/takeover";
@import "v2/lcd_common/normal_header";

@import "v2/lcd_common/evergreen";

@import "v2/lcd_common/free_text";
@import "v2/lcd_common/route_pill";
@import "v2/lcd_common/subway_status";
Expand Down
28 changes: 28 additions & 0 deletions assets/css/v2/bus_shelter/evergreen.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.flex-one-large__large,
.flex-one-medium-two-small__left,
.flex-two-medium__left,
.flex-two-medium__right {
.evergreen-content-image__container,
.evergreen-content-video {
border-radius: 16px;
box-shadow: 0 12px 24px 0 rgb(23 31 38 / 25%);
}
}

.flex-one-medium-two-small__left,
.flex-two-medium__left,
.flex-two-medium__right {
.evergreen-content-image__container,
.evergreen-content-image__image {
width: 480px;
height: 580px;
}
}

.flex-one-large__large {
.evergreen-content-image__container,
.evergreen-content-image__image {
width: 1024px;
height: 576px;
}
}
72 changes: 0 additions & 72 deletions assets/css/v2/bus_shelter/evergreen/image.scss

This file was deleted.

72 changes: 0 additions & 72 deletions assets/css/v2/bus_shelter/evergreen/video.scss

This file was deleted.

13 changes: 13 additions & 0 deletions assets/css/v2/lcd_common/evergreen.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.evergreen-content-image__container,
.evergreen-content-video {
overflow: hidden;
background-color: #e4e6e1;
}

.evergreen-content-image__container,
.evergreen-content-image__image,
.evergreen-content-video,
.looping-video {
width: 100%;
height: 100%;
}
2 changes: 2 additions & 0 deletions assets/src/apps/v2/busway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MappingContext } from "Components/v2/widget";
import NormalScreen from "Components/v2/busway/normal_screen";
import TakeoverScreen from "Components/v2/takeover_screen";

import EvergreenContent from "Components/v2/evergreen_content";
import Placeholder from "Components/v2/placeholder";

import NormalHeader from "Components/v2/lcd/normal_header";
Expand All @@ -36,6 +37,7 @@ import SimulationScreenPage from "Components/v2/simulation_screen_page";
const TYPE_TO_COMPONENT = {
normal: NormalScreen,
takeover: TakeoverScreen,
evergreen_content: EvergreenContent,
placeholder: Placeholder,
normal_header: NormalHeader,
departures: Departures,
Expand Down
32 changes: 9 additions & 23 deletions lib/screens/v2/candidate_generator/busway.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ defmodule Screens.V2.CandidateGenerator.Busway do
alias Screens.V2.CandidateGenerator
alias Screens.V2.CandidateGenerator.Widgets
alias Screens.V2.Template.Builder
alias Screens.V2.WidgetInstance.{NormalHeader, Placeholder}
alias Screens.V2.WidgetInstance.NormalHeader
alias ScreensConfig.Screen
alias ScreensConfig.V2.Busway
alias ScreensConfig.V2.Header.CurrentStopName

defmodule Deps do
@moduledoc false
defstruct now: &DateTime.utc_now/0,
departures_instances: &Widgets.Departures.departures_instances/2
end

@behaviour CandidateGenerator

@instance_fns [
&Widgets.Departures.departures_instances/2,
&Widgets.Evergreen.evergreen_content_instances/2
]

@impl CandidateGenerator
def screen_template do
{
Expand All @@ -30,15 +29,9 @@ defmodule Screens.V2.CandidateGenerator.Busway do
end

@impl CandidateGenerator
def candidate_instances(config, deps \\ %Deps{}) do
now = deps.now.()

[
fn -> header_instances(config, now) end,
fn -> deps.departures_instances.(config, now) end,
fn -> placeholder_instances() end
]
|> Task.async_stream(& &1.(), timeout: 15_000)
def candidate_instances(config, now \\ DateTime.utc_now(), instance_fns \\ @instance_fns) do
[(&header_instances/2) | instance_fns]
|> Task.async_stream(& &1.(config, now), timeout: 15_000)
|> Enum.flat_map(fn {:ok, instances} -> instances end)
end

Expand All @@ -47,13 +40,6 @@ defmodule Screens.V2.CandidateGenerator.Busway do

defp header_instances(config, now) do
%Screen{app_params: %Busway{header: %CurrentStopName{stop_name: stop_name}}} = config

[%NormalHeader{screen: config, icon: :logo, text: stop_name, time: now}]
end

defp placeholder_instances do
[
%Placeholder{color: :blue, slot_names: [:main_content]}
]
end
end
6 changes: 2 additions & 4 deletions lib/screens/v2/candidate_generator/widgets/evergreen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ defmodule Screens.V2.CandidateGenerator.Widgets.Evergreen do
alias Screens.V2.WidgetInstance.EvergreenContent
alias ScreensConfig.Screen
alias ScreensConfig.V2.EvergreenContentItem
alias ScreensConfig.V2.{BusEink, BusShelter, Dup, Elevator, GlEink, PreFare}

def evergreen_content_instances(
%Screen{app_params: %app{evergreen_content: evergreen_content}} = config,
%Screen{app_params: %_app{evergreen_content: evergreen_content}} = config,
now \\ DateTime.utc_now()
)
when app in [BusEink, BusShelter, Dup, Elevator, GlEink, PreFare] do
) do
Enum.map(evergreen_content, &evergreen_content_instance(&1, config, now))
end

Expand Down
42 changes: 18 additions & 24 deletions test/screens/v2/candidate_generator/busway_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@ defmodule Screens.V2.CandidateGenerator.BuswayTest do
alias Screens.V2.CandidateGenerator.Busway
alias Screens.V2.WidgetInstance.{DeparturesNoData, NormalHeader}

setup do
config = %Screen{
app_params: %V2.Busway{
departures: %V2.Departures{sections: []},
header: %V2.Header.CurrentStopName{stop_name: ""}
},
vendor: :solari,
device_id: "TEST",
name: "TEST",
app_id: :solari_test_v2
}

deps = %Busway.Deps{departures_instances: fn _, _ -> [] end}

%{config: config, deps: deps}
end
@config %Screen{
app_params: %V2.Busway{
departures: %V2.Departures{sections: []},
header: %V2.Header.CurrentStopName{stop_name: ""}
},
vendor: :solari,
device_id: "TEST",
name: "TEST",
app_id: :solari_test_v2
}

describe "screen_template/0" do
test "returns correct template" do
Expand All @@ -33,20 +27,20 @@ defmodule Screens.V2.CandidateGenerator.BuswayTest do
end

describe "candidate_instances/2" do
test "includes header with stop name", %{config: config, deps: deps} do
test "includes header with stop name" do
now = ~U[2020-04-06T10:00:00Z]
config = put_in(config.app_params.header.stop_name, "Ruggles")
deps = struct!(deps, now: fn -> now end)
config = put_in(@config.app_params.header.stop_name, "Ruggles")

expected_header = %NormalHeader{screen: config, icon: :logo, text: "Ruggles", time: now}
assert expected_header in Busway.candidate_instances(config, deps)
assert expected_header in Busway.candidate_instances(config, now, _instance_fns = [])
end

test "includes departures instances", %{config: config, deps: deps} do
no_data = %DeparturesNoData{screen: config, show_alternatives?: true}
deps = struct!(deps, departures_instances: fn ^config, _ -> [no_data] end)
test "includes departures instances" do
now = ~U[2020-04-06T10:00:00Z]
no_data = %DeparturesNoData{screen: @config, show_alternatives?: true}
instance_fns = [fn @config, ^now -> [no_data] end]

assert no_data in Busway.candidate_instances(config, deps)
assert no_data in Busway.candidate_instances(@config, now, instance_fns)
end
end
end

0 comments on commit e914950

Please sign in to comment.