diff --git a/assets/js/components/Dashboard/EditPaMessage/EditPaMessage.tsx b/assets/js/components/Dashboard/EditPaMessage/EditPaMessage.tsx
index bd672b014..e21ed819f 100644
--- a/assets/js/components/Dashboard/EditPaMessage/EditPaMessage.tsx
+++ b/assets/js/components/Dashboard/EditPaMessage/EditPaMessage.tsx
@@ -6,12 +6,11 @@ import PaMessageForm from "../PaMessageForm";
import { updateExistingPaMessage } from "Utils/api";
import { Alert } from "Models/alert";
import { AudioPreview } from "Components/PaMessageForm/types";
-import { StaticTemplate } from "Models/static_template";
+import { STATIC_TEMPLATES } from "Components/PaMessageForm/StaticTemplatePage";
interface PaMessageResponse {
pa_message: PaMessage;
alert: Alert | null;
- template: StaticTemplate | null;
}
const usePaMessage = (id: string | number) => {
@@ -43,13 +42,7 @@ const FetchPaMessage = ({ id }: { id: string | number }) => {
if (isLoading || error || data?.pa_message == null) return null;
- return (
-
- );
+ return ;
};
const EditPaMessageContainer = () => {
@@ -68,10 +61,9 @@ const EditPaMessageContainer = () => {
interface Props {
paMessage: PaMessage;
alert?: Alert | null;
- template?: StaticTemplate | null;
}
-const EditPaMessage = ({ paMessage, alert, template }: Props) => {
+const EditPaMessage = ({ paMessage, alert }: Props) => {
const navigate = useNavigate();
const [errorMessage, setErrorMessage] = useState(null);
const [errors, setErrors] = useState([]);
@@ -86,7 +78,9 @@ const EditPaMessage = ({ paMessage, alert, template }: Props) => {
onErrorsChange={setErrors}
defaultValues={paMessage}
defaultAlert={alert ?? paMessage.alert_id}
- defaultTemplate={template}
+ defaultTemplate={STATIC_TEMPLATES.find(
+ (t) => t.id === paMessage.template_id,
+ )}
defaultAudioState={AudioPreview.Reviewed}
paused={paMessage.paused}
onSubmit={async (data) => {
diff --git a/assets/js/components/Dashboard/PaMessageForm/StaticTemplatePage.tsx b/assets/js/components/Dashboard/PaMessageForm/StaticTemplatePage.tsx
index 3add28610..c2a827255 100644
--- a/assets/js/components/Dashboard/PaMessageForm/StaticTemplatePage.tsx
+++ b/assets/js/components/Dashboard/PaMessageForm/StaticTemplatePage.tsx
@@ -1,8 +1,8 @@
-import React, { useEffect, useState } from "react";
+import React, { useState } from "react";
import { Container, Row, Col, Button } from "react-bootstrap";
import { StaticTemplate } from "Models/static_template";
-import { fetchStaticTemplates } from "Utils/api";
import FilterGroup from "Components/FilterGroup";
+import _staticTemplates from "../../../../static/static_templates.json";
interface Props {
onCancel: () => void;
@@ -11,15 +11,12 @@ interface Props {
type MessageType = "psa" | "emergency";
+export const STATIC_TEMPLATES = _staticTemplates as StaticTemplate[];
+
const StaticTemplatePage = ({ onCancel, onSelect }: Props) => {
- const [staticTemplates, setStaticTemplates] = useState([]);
const [selectedMessageType, setSelectedMessageType] =
useState("psa");
- useEffect(() => {
- fetchStaticTemplates().then((templates) => setStaticTemplates(templates));
- }, []);
-
return (
@@ -51,7 +48,7 @@ const StaticTemplatePage = ({ onCancel, onSelect }: Props) => {
template.type === selectedMessageType,
)}
selectedMessageType={selectedMessageType}
diff --git a/assets/js/utils/api.ts b/assets/js/utils/api.ts
index 22958943e..7ebf98e04 100644
--- a/assets/js/utils/api.ts
+++ b/assets/js/utils/api.ts
@@ -5,7 +5,6 @@ import { ScreensByAlert } from "../models/screensByAlert";
import { PlaceIdsAndNewScreens } from "../components/Dashboard/PermanentConfiguration/Workflows/GlEink/ConfigureScreensPage";
import getCsrfToken from "../csrf";
import { NewPaMessageBody, UpdatePaMessageBody } from "Models/pa_message";
-import { StaticTemplate } from "Models/static_template";
export const fetchPlaces = async (): Promise => {
const response = await fetch("/api/dashboard");
@@ -171,11 +170,6 @@ export const updateExistingPaMessage = async (
};
};
-export const fetchStaticTemplates = async (): Promise => {
- const response = await fetch("/api/pa-messages/static-templates");
- return await response.json();
-};
-
const getPostBodyAndHeaders = (
bodyData: { [key: string]: any },
extraHeaders: { [key: string]: string } = {},
diff --git a/assets/static/static_templates.json b/assets/static/static_templates.json
new file mode 100644
index 000000000..26ccda505
--- /dev/null
+++ b/assets/static/static_templates.json
@@ -0,0 +1,146 @@
+[
+ {
+ "id": 1,
+ "title": "Bicycles (English)",
+ "visual_text": "To make space for other passengers, bicycles are not permitted on trains during rush hour, or at any time of day on the Green Line. For details visit mbta.com/bikes.",
+ "audio_text": "To make space for other passengers, bicycles are not permitted on trains during rush hour, or at any time of day on the Green Line. For details visit mbta.com/bikes.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 2,
+ "title": "Backpacks (English)",
+ "visual_text": "To make space for other passengers and speed up boarding, please take off your backpack before entering the train and hold it at your side.",
+ "audio_text": "To make space for other passengers and speed up boarding, please take off your backpack before entering the train and hold it at your side.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 3,
+ "title": "Track Fires (English)",
+ "visual_text": "Delays due to fires are often caused by trash on the tracks. Please help us keep our stations clean by throwing away or recycling unwanted items.",
+ "audio_text": "Delays due to fires are often caused by trash on the tracks. Please help us keep our stations clean by throwing away or recycling unwanted items.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 4,
+ "title": "Bicycles (English + Spanish)",
+ "visual_text": "To make space for other passengers, bicycles are not permitted on trains during rush hour, or at any time of day on the Green Line. For details visit mbta.com/bikes.\n\nPara dejar espacio para otros pasajeros, bicicletas no son permitidas en los trenes durante hora pico y nunca son permitidas en la linea verde. Para mas informacion, visite mbta.com/bikes",
+ "audio_text": "To make space for other passengers, bicycles are not permitted on trains during rush hour, or at any time of day on the Green Line. For details visit mbta.com/bikes.\n\n Para dejar espacio para otros pasajeros, bicicletas no son permitidas en los trenes durante hora pico y nunca son permitidas en la línea verde. Para más información, visite [mbta.com/bikes](http://mbta.com/bikes) ",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 5,
+ "title": "Backpacks (English + Spanish)",
+ "visual_text": "To make space for other passengers and speed up boarding, please take off your backpack before entering the train and hold it at your side.\n\nPara dejar espacio para otros pasajeros y acelerar el embarque, por favor quitese la mochila y mantengala a su lado.",
+ "audio_text": "To make space for other passengers and speed up boarding, please take off your backpack before entering the train and hold it at your side.\n\n Para dejar espacio para otros pasajeros y acelerar el embarque, por favor quítese la mochila y manténgala a su lado. ",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 6,
+ "title": "Track Fires (English + Spanish)",
+ "visual_text": "Delays due to fires are often caused by trash on the tracks. Please help us keep our stations clean by throwing away or recycling unwanted items.\n\nRetrasos debidos a incendios, muchas veces son causados por basura en las rieles. Por favor, ayudenos a mantener nuestras estaciones limpias tirando o reciclando sus articulos no deseados.",
+ "audio_text": "Delays due to fires are often caused by trash on the tracks. Please help us keep our stations clean by throwing away or recycling unwanted items.\n\n Retrasos debidos a incendios, muchas veces son causados por basura en las rieles. Por favor, ayúdenos a mantener nuestras estaciones limpias tirando o reciclando sus artículos no deseados. ",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 7,
+ "title": "Safety: See something, say something",
+ "visual_text": "Safety Reminder: If you see something, say something. Call Transit Police at 617-222-1212",
+ "audio_text": "Safety Reminder: If you see something, say something. Call Transit Police at 617-222-1212",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 8,
+ "title": "Safety: Don't scroll and stroll",
+ "visual_text": "Safety Reminder: Don't scroll and stroll. Please pay attention to your surroundings and other riders.",
+ "audio_text": "Safety Reminder: Don't scroll and stroll. Please pay attention to your surroundings and other riders.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 9,
+ "title": "Safety: Do not run car to car",
+ "visual_text": "Safety Reminder: Do not run from car to car. It can cause injuries to yourself and others.",
+ "audio_text": "Safety Reminder: Do not run from car to car. It can cause injuries to yourself and others.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 10,
+ "title": "Safety: Closing doors",
+ "visual_text": "Safety Reminder: Please watch for closing doors for your own safety.",
+ "audio_text": "Safety Reminder: Please watch for closing doors for your own safety.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 11,
+ "title": "Safety: Follow instructions",
+ "visual_text": "Safety Reminder: In the event of an emergency, follow instructions from MBTA personnel for your safety.",
+ "audio_text": "Safety Reminder: In the event of an emergency, follow instructions from MBTA personnel for your safety.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 12,
+ "title": "Safety: Don't throw trash",
+ "visual_text": "Do not throw trash on the tracks. It can cause track fires and risk your safety.",
+ "audio_text": "Safety Reminder: Do not throw trash on the tracks. It can cause track fires and risk your safety.",
+ "type": "psa",
+ "archived": false
+ },
+ {
+ "id": 13,
+ "title": "Emergency in station",
+ "visual_text": "Attention Passengers. An emergency situation has been reported, please leave the station through the nearest exit.",
+ "audio_text": "Attention Passengers. An emergency situation has been reported, please leave the station through the nearest exit.",
+ "type": "emergency",
+ "archived": false
+ },
+ {
+ "id": 14,
+ "title": "Emergency outside station",
+ "visual_text": "Attention Passengers. An emergency situation has been reported outside the station. Please remain in the station until advised otherwise by MBTA or emergency personnel.",
+ "audio_text": "Attention Passengers. An emergency situation has been reported outside the station. Please remain in the station until advised otherwise by MBTA or emergency personnel.",
+ "type": "emergency",
+ "archived": false
+ },
+ {
+ "id": 15,
+ "title": "Emergency follow instructions",
+ "visual_text": "Attention Passengers. An emergency situation has been reported. Please follow the instructions of MBTA or emergency personnel.",
+ "audio_text": "Attention Passengers. An emergency situation has been reported. Please follow the instructions of MBTA or emergency personnel.",
+ "type": "emergency",
+ "archived": false
+ },
+ {
+ "id": 16,
+ "title": "Stand behind line",
+ "visual_text": "Attention Passengers. Please stand behind the yellow safety line, a train is approaching the station.",
+ "audio_text": "Attention Passengers. Please stand behind the yellow safety line, a train is approaching the station.",
+ "type": "emergency",
+ "archived": false
+ },
+ {
+ "id": 17,
+ "title": "Emergency situation ended",
+ "visual_text": "Attention Passengers. The emergency situation has ended. It is now safe to exit the station.",
+ "audio_text": "Attention Passengers. The emergency situation has ended. It is now safe to exit the station.",
+ "type": "emergency",
+ "archived": false
+ },
+ {
+ "id": 18,
+ "title": "Emergency TEST",
+ "visual_text": "This is a test of the emergency messaging system. This is not an emergency, this is a test.",
+ "audio_text": "This is a test of the emergency messaging system. This is not an emergency, this is a test.",
+ "type": "emergency",
+ "archived": false
+ }
+]
diff --git a/config/config.exs b/config/config.exs
index 92e0a9d57..990682a47 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -32,8 +32,7 @@ config :screenplay,
pending_screens_config_fetcher: Screenplay.PendingScreensConfig.Fetch.S3,
config_s3_bucket: "mbta-ctd-config",
record_sentry: false,
- start_cache_processes: config_env() != :test,
- static_template_file_spec: {:priv, "static_templates.json"}
+ start_cache_processes: config_env() != :test
# Include 2 logger backends
config :logger,
diff --git a/config/test.exs b/config/test.exs
index 7970287c5..5f02ca638 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -23,8 +23,7 @@ config :screenplay,
local_signs_json_path: {:test, "signs.json"},
stops_mod: Screenplay.Stops.Mock,
routes_mod: Screenplay.Routes.Mock,
- facilities_mod: Screenplay.Facilities.Mock,
- static_template_file_spec: {:test, "static_templates.json"}
+ facilities_mod: Screenplay.Facilities.Mock
config :ueberauth, Ueberauth,
providers: [
diff --git a/lib/screenplay/pa_messages/static_templates.ex b/lib/screenplay/pa_messages/static_templates.ex
deleted file mode 100644
index 7221319b5..000000000
--- a/lib/screenplay/pa_messages/static_templates.ex
+++ /dev/null
@@ -1,41 +0,0 @@
-defmodule Screenplay.PaMessages.StaticTemplates do
- @moduledoc """
- Functions needed to access static templates in priv/config/static_templates.json.
-
- Static template should never be deleted. If a template is no longer in use, set
- its `archived` field to `true`.
- """
-
- require Logger
-
- @spec get_all :: {:ok, list(map())} | :error
- # sobelow_skip ["Traversal.FileModule"]
- def get_all do
- with {:ok, contents} <- file_path() |> File.read(),
- {:ok, json} <- Jason.decode(contents) do
- {:ok, Enum.reject(json, & &1["archived"])}
- else
- {:error, err} ->
- Logger.error("static_template_fetch_error #{inspect(err)}")
- :error
- end
- end
-
- @spec get_template(nil) :: nil
- @spec get_template(non_neg_integer()) :: {:ok, map()} | :error
- def get_template(nil), do: {:ok, nil}
-
- def get_template(id) do
- case get_all() do
- {:ok, templates} -> {:ok, Enum.find(templates, fn template -> template["id"] == id end)}
- :error -> :error
- end
- end
-
- defp file_path do
- case Application.get_env(:screenplay, :static_template_file_spec) do
- {:test, file_name} -> Path.join(~w[#{File.cwd!()} test fixtures #{file_name}])
- {:priv, file_name} -> Path.join([:code.priv_dir(:screenplay), "config", file_name])
- end
- end
-end
diff --git a/lib/screenplay_web/controllers/pa_messages_api_controller.ex b/lib/screenplay_web/controllers/pa_messages_api_controller.ex
index 77ccddd5f..6c72b7647 100644
--- a/lib/screenplay_web/controllers/pa_messages_api_controller.ex
+++ b/lib/screenplay_web/controllers/pa_messages_api_controller.ex
@@ -7,7 +7,6 @@ defmodule ScreenplayWeb.PaMessagesApiController do
alias Screenplay.Alerts.Cache, as: AlertsCache
alias Screenplay.PaMessages
alias Screenplay.PaMessages.ListParams
- alias Screenplay.PaMessages.StaticTemplates
@watts_client Application.compile_env(:screenplay, :watts_client, Screenplay.Watts.Client)
@@ -52,12 +51,10 @@ defmodule ScreenplayWeb.PaMessagesApiController do
def show(conn, %{"id" => id}) do
if pa_message = PaMessages.get_message(id) do
- {:ok, template} = StaticTemplates.get_template(pa_message.template_id)
alert = AlertsCache.alert(pa_message.alert_id)
json(conn, %{
pa_message: pa_message,
- template: template,
alert: if(is_nil(alert), do: alert, else: Alert.to_full_map(alert))
})
else
@@ -66,14 +63,4 @@ defmodule ScreenplayWeb.PaMessagesApiController do
|> json(%{error: "not_found"})
end
end
-
- def static_templates(conn, _) do
- templates =
- case StaticTemplates.get_all() do
- {:ok, templates} -> templates
- :error -> []
- end
-
- json(conn, templates)
- end
end
diff --git a/lib/screenplay_web/router.ex b/lib/screenplay_web/router.ex
index aff2f3391..de270b733 100644
--- a/lib/screenplay_web/router.ex
+++ b/lib/screenplay_web/router.ex
@@ -90,7 +90,6 @@ defmodule ScreenplayWeb.Router do
get("/pa-messages/new/associate-alert", PaMessagesController, :index)
get("/pa-messages/:id/edit", PaMessagesController, :index)
get("/api/pa-messages/preview_audio", PaMessagesApiController, :preview_audio)
- get("/api/pa-messages/static-templates", PaMessagesApiController, :static_templates)
end
scope "/", ScreenplayWeb do
diff --git a/test/screenplay/pa_messages/static_templates_test.exs b/test/screenplay/pa_messages/static_templates_test.exs
deleted file mode 100644
index 911a45c0c..000000000
--- a/test/screenplay/pa_messages/static_templates_test.exs
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule Screenplay.PaMessages.StaticTemplatesTest do
- use ScreenplayWeb.DataCase
-
- alias Screenplay.PaMessages.StaticTemplates
-
- describe "get_all/0" do
- test "returns all active templates" do
- assert {:ok, [%{"id" => 1}, %{"id" => 2}]} = StaticTemplates.get_all()
- end
- end
-
- describe "get_template/1" do
- test "returns active template" do
- assert {:ok, %{"id" => 1}} = StaticTemplates.get_template(1)
- end
-
- test "returns nil for inactive templates" do
- assert {:ok, nil} = StaticTemplates.get_template(3)
- end
-
- test "returns nil for templates that do not exist" do
- assert {:ok, nil} = StaticTemplates.get_template(9999)
- end
- end
-end
diff --git a/test/screenplay_web/controllers/pa_messages_api_controller_test.exs b/test/screenplay_web/controllers/pa_messages_api_controller_test.exs
index 5ff754e3d..dcc8d411f 100644
--- a/test/screenplay_web/controllers/pa_messages_api_controller_test.exs
+++ b/test/screenplay_web/controllers/pa_messages_api_controller_test.exs
@@ -363,7 +363,7 @@ defmodule ScreenplayWeb.PaMessagesApiControllerTest do
audio_text: "Audio Text"
})
- assert %{"pa_message" => %{"id" => 1}, "alert" => nil, "template" => nil} =
+ assert %{"pa_message" => %{"id" => 1}, "alert" => nil} =
conn
|> get("/api/pa-messages/1")
|> json_response(200)
@@ -382,26 +382,7 @@ defmodule ScreenplayWeb.PaMessagesApiControllerTest do
alert_id: "1"
})
- assert %{"pa_message" => %{"id" => 1}, "alert" => %{"id" => "1"}, "template" => nil} =
- conn
- |> get("/api/pa-messages/1")
- |> json_response(200)
- end
-
- @tag :authenticated_pa_message_admin
- test "returns the PA message with the given ID and its associated template", %{conn: conn} do
- insert(:pa_message, %{
- id: 1,
- start_datetime: ~U[2024-05-01T01:00:00Z],
- end_datetime: ~U[2024-05-01T13:00:00Z],
- days_of_week: [1, 2, 3, 4, 5, 6, 7],
- inserted_at: ~U[2024-05-01T01:00:00Z],
- visual_text: "Visual Text",
- audio_text: "Audio Text",
- template_id: 1
- })
-
- assert %{"pa_message" => %{"id" => 1}, "alert" => nil, "template" => %{"id" => 1}} =
+ assert %{"pa_message" => %{"id" => 1}, "alert" => %{"id" => "1"}} =
conn
|> get("/api/pa-messages/1")
|> json_response(200)
@@ -415,12 +396,4 @@ defmodule ScreenplayWeb.PaMessagesApiControllerTest do
|> json_response(404)
end
end
-
- describe "GET /api/static-templates" do
- @tag :authenticated_pa_message_admin
- test "returns all static templates", %{conn: conn} do
- assert [%{"id" => 1}, %{"id" => 2}] =
- conn |> get("/api/pa-messages/static-templates") |> json_response(200)
- end
- end
end