-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add additional scaffolding for shuttle page
- Loading branch information
Showing
11 changed files
with
253 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
defmodule ArrowWeb.ShuttleController do | ||
use ArrowWeb, :controller | ||
|
||
alias Arrow.Shuttles | ||
alias Arrow.Shuttles.Shuttle | ||
|
||
def index(conn, _params) do | ||
render(conn, :index, shuttles: []) | ||
shuttles = Shuttles.list_shuttles() | ||
render(conn, :index, shuttles: shuttles) | ||
end | ||
|
||
def new(conn, _params) do | ||
render(conn, :new, changeset: nil) | ||
changeset = Shuttles.change_shuttle(%Shuttle{}) | ||
render(conn, :new, changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"shuttle" => _shuttle_params}) do | ||
render(conn, :new, changeset: nil) | ||
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 | ||
render(conn, :show, shuttle: nil) | ||
def show(conn, %{"id" => id}) do | ||
shuttle = Shuttles.get_shuttle!(id) | ||
render(conn, :show, shuttle: shuttle) | ||
end | ||
|
||
def edit(conn, %{"id" => id}) do | ||
render(conn, :edit, shuttle: %Shuttle{id: id}, changeset: nil) | ||
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 | ||
render(conn, :edit, shuttle: nil, changeset: nil) | ||
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
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
34 changes: 16 additions & 18 deletions
34
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
<%= if @changeset do %> | ||
<.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> | ||
<% end %> | ||
<.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