style ammo type show page
This commit is contained in:
		| @@ -4,9 +4,9 @@ defmodule Cannery.Ammo do | |||||||
|   """ |   """ | ||||||
|  |  | ||||||
|   import Ecto.Query, warn: false |   import Ecto.Query, warn: false | ||||||
|   alias Cannery.Repo |   alias Cannery.{Accounts.User, Repo} | ||||||
|  |   alias Cannery.Ammo.{AmmoGroup, AmmoType} | ||||||
|   alias Cannery.Ammo.AmmoType |   alias Ecto.Changeset | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Returns the list of ammo_types. |   Returns the list of ammo_types. | ||||||
| @@ -17,9 +17,8 @@ defmodule Cannery.Ammo do | |||||||
|       [%AmmoType{}, ...] |       [%AmmoType{}, ...] | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def list_ammo_types do |   @spec list_ammo_types() :: [AmmoType.t()] | ||||||
|     Repo.all(AmmoType) |   def list_ammo_types, do: Repo.all(AmmoType) | ||||||
|   end |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Gets a single ammo_type. |   Gets a single ammo_type. | ||||||
| @@ -35,6 +34,7 @@ defmodule Cannery.Ammo do | |||||||
|       ** (Ecto.NoResultsError) |       ** (Ecto.NoResultsError) | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|  |   @spec get_ammo_type!(AmmoType.id()) :: AmmoType.t() | ||||||
|   def get_ammo_type!(id), do: Repo.get!(AmmoType, id) |   def get_ammo_type!(id), do: Repo.get!(AmmoType, id) | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
| @@ -49,11 +49,9 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def create_ammo_type(attrs \\ %{}) do |   @spec create_ammo_type(attrs :: map()) :: {:ok, AmmoType.t()} | {:error, Changeset.t()} | ||||||
|     %AmmoType{} |   def create_ammo_type(attrs \\ %{}), | ||||||
|     |> AmmoType.changeset(attrs) |     do: %AmmoType{} |> AmmoType.changeset(attrs) |> Repo.insert() | ||||||
|     |> Repo.insert() |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Updates a ammo_type. |   Updates a ammo_type. | ||||||
| @@ -67,11 +65,10 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def update_ammo_type(%AmmoType{} = ammo_type, attrs) do |   @spec update_ammo_type(AmmoType.t(), attrs :: map()) :: | ||||||
|     ammo_type |           {:ok, AmmoType.t()} | {:error, Changeset.t()} | ||||||
|     |> AmmoType.changeset(attrs) |   def update_ammo_type(%AmmoType{} = ammo_type, attrs), | ||||||
|     |> Repo.update() |     do: ammo_type |> AmmoType.changeset(attrs) |> Repo.update() | ||||||
|   end |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Deletes a ammo_type. |   Deletes a ammo_type. | ||||||
| @@ -85,9 +82,20 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def delete_ammo_type(%AmmoType{} = ammo_type) do |   @spec delete_ammo_type(AmmoType.t()) :: {:ok, AmmoType.t()} | {:error, Changeset.t()} | ||||||
|     Repo.delete(ammo_type) |   def delete_ammo_type(%AmmoType{} = ammo_type), do: ammo_type |> Repo.delete() | ||||||
|   end |  | ||||||
|  |   @doc """ | ||||||
|  |   Deletes a ammo_type. | ||||||
|  |  | ||||||
|  |   ## Examples | ||||||
|  |  | ||||||
|  |       iex> delete_ammo_type(ammo_type) | ||||||
|  |       %AmmoType{} | ||||||
|  |  | ||||||
|  |   """ | ||||||
|  |   @spec delete_ammo_type!(AmmoType.t()) :: AmmoType.t() | ||||||
|  |   def delete_ammo_type!(%AmmoType{} = ammo_type), do: ammo_type |> Repo.delete!() | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Returns an `%Ecto.Changeset{}` for tracking ammo_type changes. |   Returns an `%Ecto.Changeset{}` for tracking ammo_type changes. | ||||||
| @@ -98,23 +106,28 @@ defmodule Cannery.Ammo do | |||||||
|       %Ecto.Changeset{data: %AmmoType{}} |       %Ecto.Changeset{data: %AmmoType{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def change_ammo_type(%AmmoType{} = ammo_type, attrs \\ %{}) do |   @spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type()) :: Changeset.t() | ||||||
|     AmmoType.changeset(ammo_type, attrs) |   @spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type(), attrs :: map()) :: Changeset.t() | ||||||
|   end |   def change_ammo_type(%AmmoType{} = ammo_type, attrs \\ %{}), | ||||||
|  |     do: AmmoType.changeset(ammo_type, attrs) | ||||||
|   alias Cannery.Ammo.AmmoGroup |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Returns the list of ammo_groups. |   Returns the list of ammo_groups. | ||||||
|  |  | ||||||
|   ## Examples |   ## Examples | ||||||
|  |  | ||||||
|       iex> list_ammo_groups() |       iex> list_ammo_groups(%User{id: 123}) | ||||||
|  |       [%AmmoGroup{}, ...] | ||||||
|  |  | ||||||
|  |       iex> list_ammo_groups(123) | ||||||
|       [%AmmoGroup{}, ...] |       [%AmmoGroup{}, ...] | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def list_ammo_groups do |   @spec list_ammo_groups(User.t() | User.id()) :: [AmmoGroup.t()] | ||||||
|     Repo.all(AmmoGroup) |   def list_ammo_groups(%{id: user_id}), do: list_ammo_groups(user_id) | ||||||
|  |  | ||||||
|  |   def list_ammo_groups(user_id) do | ||||||
|  |     Repo.all(from am in AmmoGroup, where: am.user_id == ^user_id) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
| @@ -131,6 +144,7 @@ defmodule Cannery.Ammo do | |||||||
|       ** (Ecto.NoResultsError) |       ** (Ecto.NoResultsError) | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|  |   @spec get_ammo_group!(AmmoGroup.id()) :: AmmoGroup.t() | ||||||
|   def get_ammo_group!(id), do: Repo.get!(AmmoGroup, id) |   def get_ammo_group!(id), do: Repo.get!(AmmoGroup, id) | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
| @@ -145,11 +159,9 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def create_ammo_group(attrs \\ %{}) do |   @spec create_ammo_group(attrs :: map()) :: {:ok, AmmoGroup.t()} | {:error, Changeset.t()} | ||||||
|     %AmmoGroup{} |   def create_ammo_group(attrs \\ %{}), | ||||||
|     |> AmmoGroup.changeset(attrs) |     do: %AmmoGroup{} |> AmmoGroup.changeset(attrs) |> Repo.insert() | ||||||
|     |> Repo.insert() |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Updates a ammo_group. |   Updates a ammo_group. | ||||||
| @@ -163,11 +175,10 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def update_ammo_group(%AmmoGroup{} = ammo_group, attrs) do |   @spec update_ammo_group(AmmoGroup.t(), attrs :: map()) :: | ||||||
|     ammo_group |           {:ok, AmmoGroup.t()} | {:error, Changeset.t()} | ||||||
|     |> AmmoGroup.changeset(attrs) |   def update_ammo_group(%AmmoGroup{} = ammo_group, attrs), | ||||||
|     |> Repo.update() |     do: ammo_group |> AmmoGroup.changeset(attrs) |> Repo.update() | ||||||
|   end |  | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Deletes a ammo_group. |   Deletes a ammo_group. | ||||||
| @@ -181,9 +192,20 @@ defmodule Cannery.Ammo do | |||||||
|       {:error, %Ecto.Changeset{}} |       {:error, %Ecto.Changeset{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def delete_ammo_group(%AmmoGroup{} = ammo_group) do |   @spec delete_ammo_group(AmmoGroup.t()) :: {:ok, AmmoGroup.t()} | {:error, Changeset.t()} | ||||||
|     Repo.delete(ammo_group) |   def delete_ammo_group(%AmmoGroup{} = ammo_group), do: ammo_group |> Repo.delete() | ||||||
|   end |  | ||||||
|  |   @doc """ | ||||||
|  |   Deletes a ammo_group. | ||||||
|  |  | ||||||
|  |   ## Examples | ||||||
|  |  | ||||||
|  |       iex> delete_ammo_group!(ammo_group) | ||||||
|  |       %AmmoGroup{} | ||||||
|  |  | ||||||
|  |   """ | ||||||
|  |   @spec delete_ammo_group!(AmmoGroup.t()) :: AmmoGroup.t() | ||||||
|  |   def delete_ammo_group!(%AmmoGroup{} = ammo_group), do: ammo_group |> Repo.delete!() | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   Returns an `%Ecto.Changeset{}` for tracking ammo_group changes. |   Returns an `%Ecto.Changeset{}` for tracking ammo_group changes. | ||||||
| @@ -194,7 +216,8 @@ defmodule Cannery.Ammo do | |||||||
|       %Ecto.Changeset{data: %AmmoGroup{}} |       %Ecto.Changeset{data: %AmmoGroup{}} | ||||||
|  |  | ||||||
|   """ |   """ | ||||||
|   def change_ammo_group(%AmmoGroup{} = ammo_group, attrs \\ %{}) do |   @spec change_ammo_group(AmmoGroup.t()) :: Changeset.t(AmmoGroup.t()) | ||||||
|     AmmoGroup.changeset(ammo_group, attrs) |   @spec change_ammo_group(AmmoGroup.t(), attrs :: map()) :: Changeset.t(AmmoGroup.t()) | ||||||
|   end |   def change_ammo_group(%AmmoGroup{} = ammo_group, attrs \\ %{}), | ||||||
|  |     do: AmmoGroup.changeset(ammo_group, attrs) | ||||||
| end | end | ||||||
|   | |||||||
| @@ -20,6 +20,12 @@ defmodule CanneryWeb.AmmoTypeLive.Show do | |||||||
|      |> assign(:ammo_type, Ammo.get_ammo_type!(id))} |      |> assign(:ammo_type, Ammo.get_ammo_type!(id))} | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  |   @impl true | ||||||
|  |   def handle_event("delete", _, socket) do | ||||||
|  |     socket.assigns.ammo_type |> Ammo.delete_ammo_type!() | ||||||
|  |     {:noreply, socket |> push_redirect(to: Routes.ammo_type_index_path(socket, :index))} | ||||||
|  |   end | ||||||
|  |  | ||||||
|   defp page_title(:show), do: "Show Ammo type" |   defp page_title(:show), do: "Show Ammo type" | ||||||
|   defp page_title(:edit), do: "Edit Ammo type" |   defp page_title(:edit), do: "Edit Ammo type" | ||||||
| end | end | ||||||
|   | |||||||
							
								
								
									
										54
									
								
								lib/cannery_web/live/ammo_type_live/show.html.heex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								lib/cannery_web/live/ammo_type_live/show.html.heex
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | |||||||
|  | <div class="mx-auto space-y-4 max-w-3xl flex flex-col justify-center items-center"> | ||||||
|  |   <h1 class="title text-2xl title-primary-500"> | ||||||
|  |     <%= @ammo_type.name %> | ||||||
|  |   </h1> | ||||||
|  |  | ||||||
|  |   <div class="flex space-x-4 justify-center items-center text-primary-500"> | ||||||
|  |     <%= live_redirect "Back", to: Routes.ammo_type_index_path(@socket, :index), class: "link" %> | ||||||
|  |     <%= live_patch "Edit", to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type), class: "button" %> | ||||||
|  |     <%= link("Delete", | ||||||
|  |       to: "#", | ||||||
|  |       class: "link", | ||||||
|  |       phx_click: "delete", | ||||||
|  |       data: [confirm: "Are you sure you want to delete #{@ammo_type.name}?"] | ||||||
|  |     ) %> | ||||||
|  |   </div> | ||||||
|  |  | ||||||
|  |   <hr class="w-full"> | ||||||
|  |  | ||||||
|  |   <ul class="text-center"> | ||||||
|  |     <li> | ||||||
|  |       <strong>Desc:</strong> | ||||||
|  |       <%= @ammo_type.desc %> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li> | ||||||
|  |       <strong>Case material:</strong> | ||||||
|  |       <%= @ammo_type.case_material %> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li> | ||||||
|  |       <strong>Bullet type:</strong> | ||||||
|  |       <%= @ammo_type.bullet_type %> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li> | ||||||
|  |       <strong>Grain:</strong> | ||||||
|  |       <%= @ammo_type.grain %> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li> | ||||||
|  |       <strong>Manufacturer:</strong> | ||||||
|  |       <%= @ammo_type.manufacturer %> | ||||||
|  |     </li> | ||||||
|  |   </ul> | ||||||
|  | </div> | ||||||
|  |  | ||||||
|  | <%= if @live_action in [:edit] do %> | ||||||
|  |   <%= live_modal CanneryWeb.AmmoTypeLive.FormComponent, | ||||||
|  |     id: @ammo_type.id, | ||||||
|  |     title: @page_title, | ||||||
|  |     action: @live_action, | ||||||
|  |     ammo_type: @ammo_type, | ||||||
|  |     return_to: Routes.ammo_type_show_path(@socket, :show, @ammo_type) %> | ||||||
|  | <% end %> | ||||||
| @@ -1,47 +0,0 @@ | |||||||
| <h1>Show Ammo type</h1> |  | ||||||
|  |  | ||||||
| <%= if @live_action in [:edit] do %> |  | ||||||
|   <%= live_modal CanneryWeb.AmmoTypeLive.FormComponent, |  | ||||||
|     id: @ammo_type.id, |  | ||||||
|     title: @page_title, |  | ||||||
|     action: @live_action, |  | ||||||
|     ammo_type: @ammo_type, |  | ||||||
|     return_to: Routes.ammo_type_show_path(@socket, :show, @ammo_type) %> |  | ||||||
| <% end %> |  | ||||||
|  |  | ||||||
| <ul> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Name:</strong> |  | ||||||
|     <%= @ammo_type.name %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Desc:</strong> |  | ||||||
|     <%= @ammo_type.desc %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Case material:</strong> |  | ||||||
|     <%= @ammo_type.case_material %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Bullet type:</strong> |  | ||||||
|     <%= @ammo_type.bullet_type %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Weight:</strong> |  | ||||||
|     <%= @ammo_type.weight %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
|   <li> |  | ||||||
|     <strong>Manufacturer:</strong> |  | ||||||
|     <%= @ammo_type.manufacturer %> |  | ||||||
|   </li> |  | ||||||
|  |  | ||||||
| </ul> |  | ||||||
|  |  | ||||||
| <span><%= live_patch "Edit", to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type), class: "button" %></span> |  | ||||||
| <span><%= live_redirect "Back", to: Routes.ammo_type_index_path(@socket, :index) %></span> |  | ||||||
		Reference in New Issue
	
	Block a user