Skip to content

Commit

Permalink
Merge branch 'master' into jz-import-controller-error-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jzimbel-mbta authored Oct 31, 2024
2 parents b0137b8 + 88495a7 commit 11513cc
Show file tree
Hide file tree
Showing 59 changed files with 667 additions and 706 deletions.
Empty file removed .dialyzer.ignore-warnings
Empty file.
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
import_deps: [:ecto, :phoenix],
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ npm-debug.log

# Screenshots taken by Wallaby
/test/integration/screenshots

.elixir_ls
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
elixir 1.14.5-otp-26
erlang 26.1.2
elixir 1.17.3-otp-27
erlang 27.1.2
nodejs 20.8.1
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG ELIXIR_VERSION=1.14.5
ARG ERLANG_VERSION=26.1.2
ARG DEBIAN_VERSION=bullseye-20230612
ARG ELIXIR_VERSION=1.17.3
ARG ERLANG_VERSION=27.1.2
ARG DEBIAN_VERSION=bullseye-20241016

FROM hexpm/elixir:$ELIXIR_VERSION-erlang-$ERLANG_VERSION-debian-$DEBIAN_VERSION as elixir-builder

Expand Down Expand Up @@ -39,6 +39,7 @@ COPY config/config.exs config/
COPY config/prod.exs config/

RUN mix deps.compile
RUN mix sentry.package_source_code

COPY assets assets
RUN npm ci --prefix assets
Expand Down
5 changes: 2 additions & 3 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ if config_env() == :prod do
root_source_code_path: File.cwd!(),
tags: %{
env: sentry_env
},
included_environments: [sentry_env]
}

config :logger, Sentry.LoggerBackend,
level: :warn,
level: :warning,
capture_log_messages: true
end

Expand Down
10 changes: 9 additions & 1 deletion lib/arrow/disruption_revision.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ defmodule Arrow.DisruptionRevision do

Enum.all?(days_of_week, fn day ->
Enum.member?(
Enum.map(Date.range(start_date, end_date), fn date -> Date.day_of_week(date) end),
Enum.map(date_range(start_date, end_date), fn date -> Date.day_of_week(date) end),
DayOfWeek.day_number(day)
)
end) ->
Expand Down Expand Up @@ -285,4 +285,12 @@ defmodule Arrow.DisruptionRevision do
changeset
end
end

defp date_range(start_date, end_date) do
if Date.compare(start_date, end_date) == :gt do
Date.range(start_date, end_date, -1)
else
Date.range(start_date, end_date)
end
end
end
4 changes: 2 additions & 2 deletions lib/arrow/gtfs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Arrow.Gtfs do
:ok

{:error, reason} = error ->
Logger.warn(
Logger.warning(
"GTFS import or validation failed #{job_logging_params(job)} reason=#{inspect(reason)}"
)

Expand All @@ -51,7 +51,7 @@ defmodule Arrow.Gtfs do
:ok

{:error, reason} = error ->
Logger.warn(
Logger.warning(
"GTFS import or validation failed #{job_logging_params(job)} reason=#{inspect(reason)}"
)

Expand Down
2 changes: 1 addition & 1 deletion lib/arrow/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Arrow.Repo do

Keyword.merge(config,
password: token,
ssl_opts: [
ssl: [
cacertfile: Path.join(:code.priv_dir(:arrow), "aws-cert-bundle.pem"),
verify: :verify_peer,
server_name_indication: String.to_charlist(hostname),
Expand Down
36 changes: 28 additions & 8 deletions lib/arrow/shuttles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Arrow.Shuttles do
alias Arrow.Repo
alias ArrowWeb.ErrorHelpers

alias Arrow.Gtfs.Route, as: GtfsRoute
alias Arrow.Shuttles.KML
alias Arrow.Shuttles.Shape
alias Arrow.Shuttles.ShapesUpload
Expand Down Expand Up @@ -244,7 +245,7 @@ defmodule Arrow.Shuttles do
"""
def list_shuttles do
Repo.all(Shuttle)
Repo.all(Shuttle) |> Repo.preload(routes: [:shape])
end

@doc """
Expand All @@ -261,7 +262,9 @@ defmodule Arrow.Shuttles do
** (Ecto.NoResultsError)
"""
def get_shuttle!(id), do: Repo.get!(Shuttle, id)
def get_shuttle!(id) do
Repo.get!(Shuttle, id) |> Repo.preload(routes: [:shape])
end

@doc """
Creates a shuttle.
Expand All @@ -276,9 +279,15 @@ defmodule Arrow.Shuttles do
"""
def create_shuttle(attrs \\ %{}) do
%Shuttle{}
|> Shuttle.changeset(attrs)
|> Repo.insert()
created_shuttle =
%Shuttle{}
|> Shuttle.changeset(attrs)
|> Repo.insert()

case created_shuttle do
{:ok, shuttle} -> {:ok, Repo.preload(shuttle, routes: [:shape])}
err -> err
end
end

@doc """
Expand All @@ -294,9 +303,15 @@ defmodule Arrow.Shuttles do
"""
def update_shuttle(%Shuttle{} = shuttle, attrs) do
shuttle
|> Shuttle.changeset(attrs)
|> Repo.update()
updated_shuttle =
shuttle
|> Shuttle.changeset(attrs)
|> Repo.update()

case updated_shuttle do
{:ok, shuttle} -> {:ok, Repo.preload(shuttle, routes: [:shape])}
err -> err
end
end

@doc """
Expand All @@ -311,4 +326,9 @@ defmodule Arrow.Shuttles do
def change_shuttle(%Shuttle{} = shuttle, attrs \\ %{}) do
Shuttle.changeset(shuttle, attrs)
end

def list_disruptable_routes do
query = from(r in GtfsRoute, where: r.type in [:light_rail, :heavy_rail])
Repo.all(query)
end
end
7 changes: 4 additions & 3 deletions lib/arrow/shuttles/route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ defmodule Arrow.Shuttles.Route do
field :direction_id, Ecto.Enum, values: [:"0", :"1"]
field :direction_desc, :string
field :waypoint, :string
field :shuttle_id, :id
field :shape_id, :id
belongs_to :shuttle, Arrow.Shuttles.Shuttle
belongs_to :shape, Arrow.Shuttles.Shape

timestamps(type: :utc_datetime)
end

@doc false
def changeset(route, attrs) do
route
|> cast(attrs, [:direction_id, :direction_desc, :destination, :waypoint, :suffix])
|> cast(attrs, [:direction_id, :direction_desc, :destination, :waypoint, :suffix, :shape_id])
|> foreign_key_constraint(:shape_id)
|> validate_required([:direction_id, :direction_desc, :destination])
end
end
2 changes: 1 addition & 1 deletion lib/arrow/shuttles/route_stop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Arrow.Shuttles.RouteStop do
field :stop_id, :string
field :stop_sequence, :integer
field :time_to_next_stop, :decimal
field :shuttle_route_id, :id
belongs_to :route, Arrow.Shuttles.Route

timestamps(type: :utc_datetime)
end
Expand Down
29 changes: 29 additions & 0 deletions lib/arrow/shuttles/shuttle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Arrow.Shuttles.Shuttle do
field :status, Ecto.Enum, values: [:draft, :active, :inactive]
field :shuttle_name, :string
field :disrupted_route_id, :string
has_many :routes, Arrow.Shuttles.Route, preload_order: [asc: :direction_id]

timestamps(type: :utc_datetime)
end
Expand All @@ -15,7 +16,35 @@ defmodule Arrow.Shuttles.Shuttle do
def changeset(shuttle, attrs) do
shuttle
|> cast(attrs, [:shuttle_name, :disrupted_route_id, :status])
|> cast_assoc(:routes, with: &Arrow.Shuttles.Route.changeset/2)
|> validate_required([:shuttle_name, :status])
|> validate_required_for(:status)
|> foreign_key_constraint(:disrupted_route_id)
|> unique_constraint(:shuttle_name)
end

def validate_required_for(changeset, :status) do
# Placeholder validation until form is complete
status = get_field(changeset, :status)
# Set error on status field for now
fields = [:status]

case status do
:active ->
message = "can't be set to active when required fields are missing"

%{
changeset
| errors:
Enum.map(
fields,
&{&1, {message, [validation: :required]}}
),
valid?: false
}

_ ->
changeset
end
end
end
8 changes: 4 additions & 4 deletions lib/arrow_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule ArrowWeb do
def channel do
quote do
use Phoenix.Channel
import ArrowWeb.Gettext
use Gettext, backend: ArrowWeb.Gettext
end
end

Expand All @@ -41,7 +41,7 @@ defmodule ArrowWeb do
use Phoenix.Controller, namespace: ArrowWeb

import Plug.Conn
import ArrowWeb.Gettext
use Gettext, backend: ArrowWeb.Gettext
alias ArrowWeb.Router.Helpers, as: Routes

unquote(verified_routes())
Expand All @@ -63,7 +63,7 @@ defmodule ArrowWeb do
use Phoenix.HTML

import ArrowWeb.ErrorHelpers
import ArrowWeb.Gettext
use Gettext, backend: ArrowWeb.Gettext
alias ArrowWeb.Router.Helpers, as: Routes

# Import the `react_component` helper
Expand All @@ -77,7 +77,7 @@ defmodule ArrowWeb do
import Phoenix.HTML
# Core UI components and translation
import ArrowWeb.CoreComponents
import ArrowWeb.Gettext
use Gettext, backend: ArrowWeb.Gettext

# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
Expand Down
30 changes: 15 additions & 15 deletions lib/arrow_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule ArrowWeb.CoreComponents do
use Phoenix.Component

alias Phoenix.LiveView.JS
import ArrowWeb.Gettext
use Gettext, backend: ArrowWeb.Gettext

@doc """
Renders a modal.
Expand Down Expand Up @@ -203,7 +203,7 @@ defmodule ArrowWeb.CoreComponents do
~H"""
<.form :let={f} for={@for} as={@as} phx-change="validate" {@rest}>
<%= render_slot(@inner_block, f) %>
<hr class="light-hr">
<hr class="light-hr" />
<div :for={action <- @actions} class="d-flex justify-content-center">
<%= render_slot(action, f) %>
</div>
Expand Down Expand Up @@ -408,7 +408,7 @@ defmodule ArrowWeb.CoreComponents do

def label(assigns) do
~H"""
<label for={@for}>
<label for={@for} class="col-form-label">
<%= render_slot(@inner_block) %>
</label>
"""
Expand Down Expand Up @@ -490,19 +490,19 @@ defmodule ArrowWeb.CoreComponents do
<table class="w-[40rem] mt-11 sm:w-full">
<thead class="text-sm text-left leading-6 text-zinc-500">
<tr>
<th :for={col <- @col} class="p-0 pb-4 pr-6 font-normal">
<%= if col[:link] do %>
<.link href={col[:link]}>
<%= if String.ends_with?(col[:link], "desc") do %>
<.icon name="hero-bars-arrow-down" class="h-4 w-4" />
<% else %>
<.icon name="hero-bars-arrow-up" class="h-4 w-4" />
<% end %>
<th :for={col <- @col} class="p-0 pb-4 pr-6 font-normal">
<%= if col[:link] do %>
<.link href={col[:link]}>
<%= if String.ends_with?(col[:link], "desc") do %>
<.icon name="hero-bars-arrow-down" class="h-4 w-4" />
<% else %>
<.icon name="hero-bars-arrow-up" class="h-4 w-4" />
<% end %>
<%= col[:label] %>
</.link>
<% else %>
<%= col[:label] %>
</.link>
<% else %>
<%= col[:label] %>
<% end %>
<% end %>
</th>
<th :if={@action != []} class="relative p-0 pb-4">
<span class="sr-only"><%= gettext("Actions") %></span>
Expand Down
2 changes: 1 addition & 1 deletion lib/arrow_web/controllers/api/gtfs_import_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defmodule ArrowWeb.API.GtfsImportController do
json(conn, value)

{:error, status, message} ->
Logger.warn("GtfsImportController unsuccessful request message=#{inspect(message)}")
Logger.warning("GtfsImportController unsuccessful request message=#{inspect(message)}")
send_resp(conn, status, message)

{:error, message} ->
Expand Down
8 changes: 4 additions & 4 deletions lib/arrow_web/controllers/disruption_html/_form.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

<div class="w-25 ml-2">
<%= link("cancel",
to: @cancel_path,
class: "w-100 btn btn-outline-primary",
data: [confirm: @cancel_confirmation]
) %>
to: @cancel_path,
class: "w-100 btn btn-outline-primary",
data: [confirm: @cancel_confirmation]
) %>
</div>
</div>
2 changes: 1 addition & 1 deletion lib/arrow_web/controllers/disruption_html/_table.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<tbody>
<%= for %{revisions: [revision]} = disruption <- @disruptions do %>
<tr class={if not revision.row_approved, do: 'bg-light-pink'}>
<tr class={if not revision.row_approved, do: "bg-light-pink"}>
<td>
<%= revision.title %>
</td>
Expand Down
3 changes: 1 addition & 2 deletions lib/arrow_web/controllers/disruption_html/edit.html.heex
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<%= form_tag Routes.disruption_path(@conn, :update, @id), method: "put", class: "col-lg-8" do %>
<hr />
<h1>
edit disruption
<span class="m-disruption-form__header-id">ID</span>
edit disruption <span class="m-disruption-form__header-id">ID</span>
<span class="m-disruption-form__header-num"><%= @id %></span>
</h1>

Expand Down
Loading

0 comments on commit 11513cc

Please sign in to comment.