Skip to content

Commit

Permalink
change image key names
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed Jul 11, 2024
1 parent a604ee1 commit d7a3010
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 51 deletions.
7 changes: 4 additions & 3 deletions lib/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ defmodule Alerts.Alert do
description: "",
effect: :unknown,
header: "",
image_alt_text: "",
image_url: nil,
image_alternative_text: nil,
image: nil,
informed_entity: %InformedEntitySet{},
lifecycle: :unknown,
priority: :low,
Expand Down Expand Up @@ -71,7 +71,8 @@ defmodule Alerts.Alert do
description: String.t() | nil,
effect: effect,
header: String.t(),
image_url: String.t() | nil,
image: String.t() | nil,
image_alternative_text: String.t() | nil,
informed_entity: InformedEntitySet.t(),
lifecycle: lifecycle,
priority: Priority.priority_level(),
Expand Down
12 changes: 2 additions & 10 deletions lib/alerts/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ defmodule Alerts.Parser do
description: description(attributes["description"]),
effect: effect(attributes),
header: attributes["header"],
image_alt_text: parse_informed_entity(attributes["informed_entity"]) |> create_alt_text(),
image_url: attributes["image_url"],
image_alternative_text: attributes["image_alternative_text"],
image: attributes["image"],
informed_entity: parse_informed_entity(attributes["informed_entity"]),
lifecycle: lifecycle(attributes["lifecycle"]),
severity: severity(attributes["severity"]),
Expand Down Expand Up @@ -217,14 +217,6 @@ defmodule Alerts.Parser do
:unknown
end
end

defp create_alt_text(informed_entities) do
informed_entities
|> Enum.map(& &1.route)
|> MapSet.new()
|> Enum.join(", ")
|> (fn routes -> "Line map of the " <> routes <> " route(s) closures" end).()
end
end

defmodule Banner do
Expand Down
15 changes: 0 additions & 15 deletions lib/alerts/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ defmodule Alerts.Repo do

@doc """
Get alerts that are diversion types: shuttle, station_closure, suspension.
Try to attach an image URL to the alert if it doesn't already have one.
"""
@spec diversions_by_route_ids([String.t()], DateTime.t()) :: [Alert.t()]
def diversions_by_route_ids(route_ids, now) do
route_ids
|> by_route_ids(now)
|> Enum.filter(&Alert.diversion?/1)
|> Enum.map(&maybe_attach_image_url/1)
end

@spec by_route_types(Enumerable.t(), DateTime.t()) :: [Alert.t()]
Expand Down Expand Up @@ -68,16 +65,4 @@ defmodule Alerts.Repo do
|> Store.all_alerts()
|> Enum.filter(&(&1.priority == priority))
end

# This function is used to attach an image URL to an alert if it doesn't already have one.
# It should be removed once alerts support image URLs.
defp maybe_attach_image_url(alert) do
if is_nil(alert.image_url) do
image_url = "/sites/default/files/diversion-diagrams/alert-#{alert.id}.png"

Map.put(alert, :image_url, image_url)
else
alert
end
end
end
6 changes: 2 additions & 4 deletions lib/dotcom_web/templates/alert/_item.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
</div>
<%= if @alert.description do %>
<div class="c-alert-item__bottom c-alert-item__bottom--<%= @alert.priority %>">
<%= if @alert.image_url && @alert.image_alt_text do %>
<object data="<%= @alert.image_url %>" type="image/png" class="w-100">
<%= @alert.image_alt_text %>
</object>
<%= if @alert.image do %>
<img src="<%= @alert.image %>" alt="<%= @alert.image_alternative_text %>" class="w-100" />
<% end %>
<div class="c-alert-item__description">
<%= format_alert_description(@alert.description) %>
Expand Down
17 changes: 0 additions & 17 deletions test/alerts/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@ defmodule Alerts.RepoTest do
# Verify
assert [^diversion] = diversions
end

test "attaches an image url to the alert if it doesn't already have one" do
# Setup
diversion = Factories.Alerts.Alert.build(:alert, effect: :shuttle, image_url: nil)

Store.update([diversion], nil)

diversion_route =
diversion.informed_entity.route |> MapSet.to_list() |> List.first()

# Exercise
diversions =
Repo.diversions_by_route_ids([diversion_route], Timex.now())

# Verify
assert diversions |> List.first() |> Map.get(:image_url) != nil
end
end

describe "by_route_types/1" do
Expand Down
4 changes: 2 additions & 2 deletions test/support/factories/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ defmodule Test.Support.Factories.Alerts.Alert do
description: Faker.Lorem.Shakespeare.king_richard_iii(),
effect: Alert.all_types() |> Faker.Util.pick(),
header: Faker.Lorem.Shakespeare.king_richard_iii(),
image_alt_text: Faker.Lorem.Shakespeare.king_richard_iii(),
image_url: Faker.Internet.image_url(),
image: Faker.Internet.image_url(),
image_alternative_text: Faker.Lorem.Shakespeare.king_richard_iii(),
informed_entity: InformedEntitySet.build(:informed_entity_set),
lifecycle: Alert.lifecycles() |> Faker.Util.pick(),
priority: Priority.priority_levels() |> Faker.Util.pick(),
Expand Down

0 comments on commit d7a3010

Please sign in to comment.