-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scaffolding for shuttle page (#1019)
- Loading branch information
Showing
13 changed files
with
359 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule ArrowWeb.ShuttleController do | ||
use ArrowWeb, :controller | ||
|
||
alias Arrow.Shuttles | ||
alias Arrow.Shuttles.Shuttle | ||
|
||
def index(conn, _params) do | ||
shuttles = Shuttles.list_shuttles() | ||
render(conn, :index, shuttles: shuttles) | ||
end | ||
|
||
def new(conn, _params) do | ||
changeset = Shuttles.change_shuttle(%Shuttle{}) | ||
render(conn, :new, changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"shuttle" => shuttle_params}) do | ||
case Shuttles.create_shuttle(shuttle_params) do | ||
{:ok, shuttle} -> | ||
conn | ||
|> put_flash(:info, "Shuttle created successfully.") | ||
|> redirect(to: ~p"/shuttles/#{shuttle}") | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, :new, changeset: changeset) | ||
end | ||
end | ||
|
||
def show(conn, %{"id" => id}) do | ||
shuttle = Shuttles.get_shuttle!(id) | ||
render(conn, :show, shuttle: shuttle) | ||
end | ||
|
||
def edit(conn, %{"id" => id}) do | ||
shuttle = Shuttles.get_shuttle!(id) | ||
changeset = Shuttles.change_shuttle(shuttle) | ||
render(conn, :edit, shuttle: shuttle, changeset: changeset) | ||
end | ||
|
||
def update(conn, %{"id" => id, "shuttle" => shuttle_params}) do | ||
shuttle = Shuttles.get_shuttle!(id) | ||
|
||
case Shuttles.update_shuttle(shuttle, shuttle_params) do | ||
{:ok, shuttle} -> | ||
conn | ||
|> put_flash(:info, "Shuttle updated successfully.") | ||
|> redirect(to: ~p"/shuttles/#{shuttle}") | ||
|
||
{:error, %Ecto.Changeset{} = changeset} -> | ||
render(conn, :edit, shuttle: shuttle, changeset: changeset) | ||
end | ||
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.ShuttleView do | ||
use ArrowWeb, :html | ||
|
||
embed_templates "shuttle_html/*" | ||
|
||
@doc """ | ||
Renders a shuttle form. | ||
""" | ||
attr :changeset, Ecto.Changeset, required: true | ||
attr :action, :string, required: true | ||
|
||
def shuttle_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,7 @@ | ||
<.header> | ||
Edit Shuttle <%= @shuttle.id %> | ||
</.header> | ||
|
||
<.shuttle_form changeset={@changeset} action={~p"/shuttles/#{@shuttle}"} /> | ||
|
||
<.back navigate={~p"/shuttles"}>Back to shuttles</.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,19 @@ | ||
<.header> | ||
Listing Shuttles | ||
<:actions> | ||
<.link href={~p"/shuttles/new"}> | ||
<.button>New Shuttle</.button> | ||
</.link> | ||
</:actions> | ||
</.header> | ||
|
||
<.table id="shuttles" rows={@shuttles} row_click={&JS.navigate(~p"/shuttles/#{&1}")}> | ||
<:col :let={shuttle} label="Shuttle name"><%= shuttle.shuttle_name %></:col> | ||
<:col :let={shuttle} label="Status"><%= shuttle.status %></:col> | ||
<:action :let={shuttle}> | ||
<div class="sr-only"> | ||
<.link navigate={~p"/shuttles/#{shuttle}"}>Show</.link> | ||
</div> | ||
<.link navigate={~p"/shuttles/#{shuttle}/edit"}>Edit</.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,7 @@ | ||
<.header> | ||
New Shuttle | ||
</.header> | ||
|
||
<.shuttle_form changeset={@changeset} action={~p"/shuttles"} /> | ||
|
||
<.back navigate={~p"/shuttles"}>Back to shuttles</.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,15 @@ | ||
<.header> | ||
Shuttle <%= @shuttle.id %> | ||
<:actions> | ||
<.link href={~p"/shuttles/#{@shuttle}/edit"}> | ||
<.button>Edit shuttle</.button> | ||
</.link> | ||
</:actions> | ||
</.header> | ||
|
||
<.list> | ||
<:item title="Shuttle name"><%= @shuttle.shuttle_name %></:item> | ||
<:item title="Status"><%= @shuttle.status %></:item> | ||
</.list> | ||
|
||
<.back navigate={~p"/shuttles"}>Back to shuttles</.back> |
16 changes: 16 additions & 0 deletions
16
lib/arrow_web/controllers/shuttle_html/shuttle_form.html.heex
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,16 @@ | ||
<.simple_form :let={f} for={@changeset} action={@action}> | ||
<.error :if={@changeset.action}> | ||
Oops, something went wrong! Please check the errors below. | ||
</.error> | ||
<.input field={f[:shuttle_name]} type="text" label="Shuttle name" /> | ||
<.input | ||
field={f[:status]} | ||
type="select" | ||
label="Status" | ||
prompt="Choose a value" | ||
options={Ecto.Enum.values(Arrow.Shuttles.Shuttle, :status)} | ||
/> | ||
<:actions> | ||
<.button>Save Shuttle</.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
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,75 @@ | ||
defmodule ArrowWeb.ShuttleControllerTest do | ||
use ArrowWeb.ConnCase | ||
|
||
import Arrow.ShuttlesFixtures | ||
|
||
@create_attrs %{status: :draft, shuttle_name: "some shuttle_name"} | ||
@update_attrs %{status: :active, shuttle_name: "some updated shuttle_name"} | ||
@invalid_attrs %{status: nil, shuttle_name: nil} | ||
|
||
describe "index" do | ||
@tag :authenticated | ||
test "lists all shuttles", %{conn: conn} do | ||
conn = get(conn, ~p"/shuttles") | ||
assert html_response(conn, 200) =~ "Listing Shuttles" | ||
end | ||
end | ||
|
||
describe "new shuttle" do | ||
@tag :authenticated_admin | ||
test "renders form", %{conn: conn} do | ||
conn = get(conn, ~p"/shuttles/new") | ||
assert html_response(conn, 200) =~ "New Shuttle" | ||
end | ||
end | ||
|
||
describe "create shuttle" do | ||
@tag :authenticated_admin | ||
test "redirects to show when data is valid", %{conn: conn} do | ||
conn = post(conn, ~p"/shuttles", shuttle: @create_attrs) | ||
|
||
assert %{id: id} = redirected_params(conn) | ||
assert redirected_to(conn) == ~p"/shuttles/#{id}" | ||
end | ||
|
||
@tag :authenticated_admin | ||
test "renders errors when data is invalid", %{conn: conn} do | ||
conn = post(conn, ~p"/shuttles", shuttle: @invalid_attrs) | ||
assert html_response(conn, 200) =~ "New Shuttle" | ||
end | ||
end | ||
|
||
describe "edit shuttle" do | ||
setup [:create_shuttle] | ||
|
||
@tag :authenticated_admin | ||
test "renders form for editing chosen shuttle", %{conn: conn, shuttle: shuttle} do | ||
conn = get(conn, ~p"/shuttles/#{shuttle}/edit") | ||
assert html_response(conn, 200) =~ "Edit Shuttle" | ||
end | ||
end | ||
|
||
describe "update shuttle" do | ||
setup [:create_shuttle] | ||
|
||
@tag :authenticated_admin | ||
test "redirects when data is valid", %{conn: conn, shuttle: shuttle} do | ||
redirected = put(conn, ~p"/shuttles/#{shuttle}", shuttle: @update_attrs) | ||
assert redirected_to(redirected) == ~p"/shuttles/#{shuttle}" | ||
|
||
conn = get(conn, ~p"/shuttles/#{shuttle}") | ||
assert html_response(conn, 200) =~ "some updated shuttle_name" | ||
end | ||
|
||
@tag :authenticated_admin | ||
test "renders errors when data is invalid", %{conn: conn, shuttle: shuttle} do | ||
conn = put(conn, ~p"/shuttles/#{shuttle}", shuttle: @invalid_attrs) | ||
assert html_response(conn, 200) =~ "Edit Shuttle" | ||
end | ||
end | ||
|
||
defp create_shuttle(_) do | ||
shuttle = shuttle_fixture() | ||
%{shuttle: shuttle} | ||
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