-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1557acb
commit 0487889
Showing
10 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
defmodule DotcomWeb.VoteController do | ||
@moduledoc """ | ||
Handles rendering the vote widget | ||
""" | ||
|
||
use DotcomWeb, :controller | ||
|
||
import DotcomWeb.ViewHelpers, only: [cms_static_page_path: 2] | ||
|
||
plug(:meta_description) | ||
plug(:clear_polling_results) | ||
|
||
def show( | ||
conn, | ||
%{"address" => address, "latitude" => latitude, "longitude" => longitude} = _params | ||
) do | ||
google_api_key = Application.get_env(:dotcom, :google_api_key) | ||
|
||
response = | ||
Req.get("https://www.googleapis.com/civicinfo/v2/voterinfo", | ||
params: [ | ||
key: google_api_key, | ||
electionId: "9000", | ||
address: address | ||
] | ||
) | ||
|
||
conn = | ||
case response do | ||
{:ok, %{body: %{"pollingLocations" => [polling_location | _]}}} -> | ||
polling_location_name = Recase.to_title(polling_location["address"]["locationName"]) | ||
|
||
params = %{ | ||
"plan" => %{ | ||
"from_latitude" => latitude, | ||
"from_longitude" => longitude, | ||
"from" => address, | ||
"to_latitude" => polling_location["latitude"], | ||
"to_longitude" => polling_location["longitude"], | ||
"to" => polling_location_name | ||
} | ||
} | ||
|
||
conn | ||
|> assign(:polling_location, polling_location) | ||
|> assign(:polling_location_name, polling_location_name) | ||
|> assign(:trip_plan_path, trip_plan_path(DotcomWeb.Endpoint, :index, params)) | ||
|
||
_ -> | ||
conn |> assign(:polling_error, true) | ||
end | ||
|
||
conn | ||
|> assign(:should_scroll, true) | ||
|> assign(:breadcrumbs, [ | ||
Breadcrumb.build("Take the T to Vote", cms_static_page_path(conn, "/vote")) | ||
]) | ||
|> render("show.html") | ||
end | ||
|
||
def show(conn, _params) do | ||
conn | ||
|> assign(:breadcrumbs, [ | ||
Breadcrumb.build("Vote", cms_static_page_path(conn, "/vote")) | ||
]) | ||
|> render("show.html") | ||
end | ||
|
||
defp meta_description(conn, _) do | ||
conn | ||
|> assign( | ||
:meta_description, | ||
"Tuesday, November 5 is the last day to vote in the 2024 general election. Use the T to get to your polling location." | ||
) | ||
end | ||
|
||
defp clear_polling_results(conn, _) do | ||
conn | ||
|> assign(:polling_location, nil) | ||
|> assign(:polling_error, false) | ||
|> assign(:should_scroll, false) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<div class="container m-sales-locations"> | ||
<div class="col-md-8"> | ||
<div class="limited-width"> | ||
<h1>Take the T to Vote</h1> | ||
<img | ||
class="image-style-max-2600x2600 c-media__element img-fluid mb-6" | ||
src="https://cdn.mbta.com/sites/default/files/styles/max_2600x2600/public/media/2021-03/2017-28-06-downtown-crossing-flags.jpg?itok=GqEXce3F" | ||
alt="An exterior shot of the Downtown Crossing Station entrance. US Flags line the street, and skyscrapers are visible in the background. Many pedestrians are walking by " | ||
/> | ||
|
||
<p> | ||
Tuesday, November 5 is the last day to vote in the 2024 | ||
general election. Use the T to get to your polling location. | ||
</p> | ||
</div> | ||
|
||
<div | ||
id="polling-place-form" | ||
class="mb-6" | ||
{if @should_scroll, do: %{"phx-hook" => "ScrollIntoView"}, else: %{}} | ||
> | ||
<h2 class="mb-6">Find Your Polling Place</h2> | ||
|
||
<p class="font-bold mb-1">Home Address</p> | ||
<.algolia_autocomplete | ||
id="vote" | ||
config_type="vote" | ||
placeholder="Enter your registered address" | ||
/> | ||
</div> | ||
|
||
<div :if={@polling_location != nil}> | ||
<p class="font-bold mb-1">Your Polling Place</p> | ||
|
||
<div class="u-highlight-gray border border-silver-100 rounded-md flex flex-col p-6"> | ||
<div class="font-bold text-lg mb-2"> | ||
<%= @polling_location_name %> | ||
</div> | ||
<div class="mb-6"> | ||
<%= @polling_location["address"]["line1"] %> | ||
<br /> | ||
<%= @polling_location["address"]["city"] %>, <%= @polling_location["address"]["state"] %> | ||
<%= @polling_location["address"]["zip"] %> | ||
</div> | ||
<a class="btn btn-primary" href={@trip_plan_path}> | ||
Plan your trip | ||
</a> | ||
</div> | ||
</div> | ||
|
||
<div :if={@polling_error} class="flex flex-col"> | ||
<p class="italic"> | ||
We weren't able to find a polling place for your address. You | ||
can also visit the | ||
<a href="https://www.sec.state.ma.us/WhereDoIVoteMA/WhereDoIVote" target="_blank"> | ||
Secretary of State's official site | ||
</a> | ||
to find your polling place, and then use the | ||
<a href={trip_plan_path(DotcomWeb.Endpoint, :index)} target="_blank"> | ||
MBTA Trip Planner | ||
</a> | ||
to plan your trip. | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="m-schedule-page__schedule-notes u-mt-2"> | ||
<h2 class="mt-0">More Guides</h2> | ||
<figure class="c-media c-media--image c-media--wide"> | ||
<div class="c-media__content"> | ||
<a class="c-media__link" href="/guides" target=""> | ||
<img | ||
class="image-style-max-2600x2600 c-media__element img-fluid" | ||
src="https://cdn.mbta.com/sites/default/files/styles/max_2600x2600/public/media/2019-01/meta-guide-MORE-WORDS.png?itok=akfxoExc" | ||
alt="Clickable graphic for User Guides" | ||
/> | ||
</a> | ||
</div> | ||
</figure> | ||
|
||
<p> | ||
Our user guides can help you learn how to navigate the system, | ||
get to local events, use accessibility features, and more. | ||
</p> | ||
<%= link("View all guides", | ||
to: cms_static_page_path(@conn, "/guides"), | ||
target: "_blank", | ||
class: "c-call-to-action" | ||
) %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule DotcomWeb.VoteView do | ||
@moduledoc """ | ||
View for the vote widget | ||
""" | ||
use DotcomWeb, :view | ||
end |