-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add shuttle shape page #978
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4e65dbc
fix: commit CoreComponents from a phoenix 7 new app
meagharty 88f441f
fix: update arrow_web.ex to match new phoenix app, use CoreComponents
meagharty 91222d0
chore: commit cosmetic npm lockfile change
meagharty a7ee6f2
feat: hook up phoenix 1.7 verified_routes to endpoint.ex
meagharty 0b47d5f
fix: fix icons by adding to static path list
meagharty 73f7d4a
feat: add tailwind css & hero icons for CoreComponents 1.7
meagharty 3eb2ada
fix: format tailwind.config.js with prettier
meagharty 3976c72
fix: add phx.digest output to .gitignore
meagharty 9bb6d02
fix: add tailwind to mix assets.build, assets.deploy
meagharty e07c972
fix: fix dev config name for watching tailwind changes
meagharty 41e35df
fix: have phoenix serve static files like images, fonts, icons
meagharty b72717f
fix: remove asset tagged versions of icons
meagharty 926208f
fix: fix path for checkbox.css image
meagharty 9d35758
fix: separate out css from js build, remove tailwind.css separate file
meagharty ee79d7b
fix: remove @tailwind/base to prevent collision with bootstrap
meagharty cf7ee90
fix: update esbuild, remove css refs and add empty loader
meagharty 4823396
fix: fix Dockerfile to work with tailwind with Phoenix .heex
meagharty 64d2bc4
feat: commit mix phx.gen.html output
meagharty c1abdec
feat: commit result of ecto migration
meagharty 4bbb742
fix: rename Shape -> ShapeView, add auth
meagharty 2acaa83
tests: add authentication to controller tests
meagharty 20dba1e
fix: fix credo issues
meagharty e40d27d
feat: add file upload input, mark required
meagharty 9de3398
tests: add test with upload params set
meagharty ed336b8
Merge branch 'master' into meag/add-shuttle-shape-page
meagharty d607eaf
fix: restore new line to priv/repo/structure.sql
meagharty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
defmodule Arrow.Shuttle do | ||
@moduledoc """ | ||
The Shuttle context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Arrow.Repo | ||
|
||
alias Arrow.Shuttle.Shape | ||
|
||
@doc """ | ||
Returns the list of shapes. | ||
|
||
## Examples | ||
|
||
iex> list_shapes() | ||
[%Shape{}, ...] | ||
|
||
""" | ||
def list_shapes do | ||
Repo.all(Shape) | ||
end | ||
|
||
@doc """ | ||
Gets a single shape. | ||
|
||
Raises `Ecto.NoResultsError` if the Shape does not exist. | ||
|
||
## Examples | ||
|
||
iex> get_shape!(123) | ||
%Shape{} | ||
|
||
iex> get_shape!(456) | ||
** (Ecto.NoResultsError) | ||
|
||
""" | ||
def get_shape!(id), do: Repo.get!(Shape, id) | ||
|
||
@doc """ | ||
Creates a shape. | ||
|
||
## Examples | ||
|
||
iex> create_shape(%{field: value}) | ||
{:ok, %Shape{}} | ||
|
||
iex> create_shape(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
|
||
""" | ||
def create_shape(attrs \\ %{}) do | ||
%Shape{} | ||
|> Shape.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a shape. | ||
|
||
## Examples | ||
|
||
iex> update_shape(shape, %{field: new_value}) | ||
{:ok, %Shape{}} | ||
|
||
iex> update_shape(shape, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
|
||
""" | ||
def update_shape(%Shape{} = shape, attrs) do | ||
shape | ||
|> Shape.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Deletes a shape. | ||
|
||
## Examples | ||
|
||
iex> delete_shape(shape) | ||
{:ok, %Shape{}} | ||
|
||
iex> delete_shape(shape) | ||
{:error, %Ecto.Changeset{}} | ||
|
||
""" | ||
def delete_shape(%Shape{} = shape) do | ||
Repo.delete(shape) | ||
end | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking shape changes. | ||
|
||
## Examples | ||
|
||
iex> change_shape(shape) | ||
%Ecto.Changeset{data: %Shape{}} | ||
|
||
""" | ||
def change_shape(%Shape{} = shape, attrs \\ %{}) do | ||
Shape.changeset(shape, attrs) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Arrow.Shuttle.Shape do | ||
@moduledoc "schema for shuttle shapes" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "shapes" do | ||
field :name, :string | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(shape, attrs) do | ||
shape | ||
|> cast(attrs, [:name]) | ||
|> validate_required([:name]) | ||
|> unique_constraint(:name) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
defmodule ArrowWeb.ShapeController do | ||
use ArrowWeb, :controller | ||
|
||
alias Arrow.Shuttle | ||
alias Arrow.Shuttle.Shape | ||
alias ArrowWeb.Plug.Authorize | ||
|
||
plug(Authorize, :view_disruption when action in [:index, :show]) | ||
plug(Authorize, :create_disruption when action in [:new, :create]) | ||
plug(Authorize, :update_disruption when action in [:edit, :update, :update_row_status]) | ||
plug(Authorize, :delete_disruption when action in [:delete]) | ||
|
||
def index(conn, _params) do | ||
shapes = Shuttle.list_shapes() | ||
render(conn, :index, shapes: shapes) | ||
end | ||
|
||
def new(conn, _params) do | ||
changeset = Shuttle.change_shape(%Shape{}) | ||
render(conn, :new, changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"shape" => shape_params}) do | ||
case Shuttle.create_shape(shape_params) do | ||
{:ok, shape} -> | ||
conn | ||
|> put_flash( | ||
:info, | ||
"Shape created successfully from #{shape_params["filename"].filename}" | ||
) | ||
|> redirect(to: ~p"/shapes/#{shape}") | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, :new, changeset: changeset) | ||
end | ||
end | ||
|
||
def show(conn, %{"id" => id}) do | ||
shape = Shuttle.get_shape!(id) | ||
render(conn, :show, shape: shape) | ||
end | ||
|
||
def edit(conn, %{"id" => id}) do | ||
shape = Shuttle.get_shape!(id) | ||
changeset = Shuttle.change_shape(shape) | ||
render(conn, :edit, shape: shape, changeset: changeset) | ||
end | ||
|
||
def update(conn, %{"id" => id, "shape" => shape_params}) do | ||
shape = Shuttle.get_shape!(id) | ||
|
||
case Shuttle.update_shape(shape, shape_params) do | ||
{:ok, shape} -> | ||
conn | ||
|> put_flash( | ||
:info, | ||
"Shape updated successfully from #{shape_params["filename"].filename}" | ||
) | ||
|> redirect(to: ~p"/shapes/#{shape}") | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, :edit, shape: shape, changeset: changeset) | ||
end | ||
end | ||
|
||
def delete(conn, %{"id" => id}) do | ||
shape = Shuttle.get_shape!(id) | ||
{:ok, _shape} = Shuttle.delete_shape(shape) | ||
|
||
conn | ||
|> put_flash(:info, "Shape deleted successfully.") | ||
|> redirect(to: ~p"/shapes") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule ArrowWeb.ShapeView do | ||
use ArrowWeb, :html | ||
|
||
embed_templates "shape_html/*" | ||
|
||
@doc """ | ||
Renders a shape form. | ||
""" | ||
attr :changeset, Ecto.Changeset, required: true | ||
attr :action, :string, required: true | ||
|
||
def shape_form(assigns) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<.header> | ||
Edit Shape <%= @shape.id %> | ||
<:subtitle>Use this form to manage shape records in your database.</:subtitle> | ||
</.header> | ||
|
||
<.shape_form changeset={@changeset} action={~p"/shapes/#{@shape}"} /> | ||
|
||
<.back navigate={~p"/shapes"}>Back to shapes</.back> |
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,23 @@ | ||
<.header> | ||
Listing Shapes | ||
<:actions> | ||
<.link href={~p"/shapes/new"}> | ||
<.button>New Shape</.button> | ||
</.link> | ||
</:actions> | ||
</.header> | ||
|
||
<.table id="shapes" rows={@shapes} row_click={&JS.navigate(~p"/shapes/#{&1}")}> | ||
<:col :let={shape} label="Name"><%= shape.name %></:col> | ||
<:action :let={shape}> | ||
<div class="sr-only"> | ||
<.link navigate={~p"/shapes/#{shape}"}>Show</.link> | ||
</div> | ||
<.link navigate={~p"/shapes/#{shape}/edit"}>Edit</.link> | ||
</:action> | ||
<:action :let={shape}> | ||
<.link href={~p"/shapes/#{shape}"} method="delete" data-confirm="Are you sure?"> | ||
Delete | ||
</.link> | ||
</:action> | ||
</.table> |
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,8 @@ | ||
<.header> | ||
New Shape | ||
<:subtitle>Use this form to manage shape records in your database.</:subtitle> | ||
</.header> | ||
|
||
<.shape_form changeset={@changeset} action={~p"/shapes"} /> | ||
|
||
<.back navigate={~p"/shapes"}>Back to shapes</.back> |
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,10 @@ | ||
<.simple_form :let={f} for={@changeset} action={@action} multipart> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input field={f[:filename]} type="file" label="Filename" required="true"/> | ||
<.input field={f[:name]} type="text" label="Name" /> | ||
<:actions> | ||
<.button>Save Shape</.button> | ||
</:actions> | ||
</.simple_form> |
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,15 @@ | ||
<.header> | ||
Shape <%= @shape.id %> | ||
<:subtitle>This is a shape record from your database.</:subtitle> | ||
<:actions> | ||
<.link href={~p"/shapes/#{@shape}/edit"}> | ||
<.button>Edit shape</.button> | ||
</.link> | ||
</:actions> | ||
</.header> | ||
|
||
<.list> | ||
<:item title="Name"><%= @shape.name %></:item> | ||
</.list> | ||
|
||
<.back navigate={~p"/shapes"}>Back to shapes</.back> |
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,13 @@ | ||
defmodule Arrow.Repo.Migrations.CreateShapes do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:shapes) do | ||
add :name, :string | ||
|
||
timestamps() | ||
end | ||
|
||
create unique_index(:shapes, [:name]) | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and migration update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we had a few dependent PRs (#984 is branched off of this, this PR was branched off another), I moved this into a new PR.