diff --git a/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex b/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex
new file mode 100644
index 00000000..6e1c4abe
--- /dev/null
+++ b/lib/cannery_web/live/ammo_group_live/ammo_group_card.ex
@@ -0,0 +1,46 @@
+defmodule CanneryWeb.AmmoGroupLive.AmmoGroupCard do
+ @moduledoc """
+ Display card for an ammo group
+ """
+
+ use CanneryWeb, :component
+ alias Cannery.Repo
+ alias CanneryWeb.Endpoint
+
+ def ammo_group_card(assigns) do
+ assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type))
+
+ ~H"""
+
<%= for ammo_group <- @ammo_groups do %>
-
+
<%= ammo_group.count %>
|
+
- <%= ammo_group.price_paid %>
+ $ <%= ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
|
+
<%= ammo_group.notes %>
|
-
-
- <%= live_redirect("Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group)) %>
-
-
- <%= live_patch("Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group)) %>
-
-
- <%= link("Delete",
- to: "#",
- phx_click: "delete",
- phx_value_id: ammo_group.id,
- data: [confirm: "Are you sure?"]
- ) %>
-
+ |
+ <%= live_redirect("View", to: Routes.ammo_group_show_path(@socket, :show, ammo_group)) %>
+
+ <%= live_patch to: Routes.ammo_group_index_path(@socket, :edit, ammo_group),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
+
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ phx_value_id: ammo_group.id,
+ data: [confirm: "Are you sure you want to delete this ammo?"] do %>
+
+ <% end %>
|
<% end %>
@@ -78,6 +80,7 @@
title: @page_title,
action: @live_action,
ammo_group: @ammo_group,
- return_to: Routes.ammo_group_index_path(@socket, :index)
+ return_to: Routes.ammo_group_index_path(@socket, :index),
+ current_user: @current_user
) %>
<% end %>
diff --git a/lib/cannery_web/live/ammo_group_live/show.ex b/lib/cannery_web/live/ammo_group_live/show.ex
index 658377c8..49dbc2a3 100644
--- a/lib/cannery_web/live/ammo_group_live/show.ex
+++ b/lib/cannery_web/live/ammo_group_live/show.ex
@@ -4,20 +4,32 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
"""
use CanneryWeb, :live_view
-
- alias Cannery.Ammo
+ import CanneryWeb.ContainerLive.ContainerCard
+ alias Cannery.{Ammo, Repo}
@impl true
def mount(_params, session, socket) do
- {:ok, socket |> assign_defaults(session)}
+ socket = socket |> assign_defaults(session)
+
+ {:ok, socket}
end
@impl true
def handle_params(%{"id" => id}, _, socket) do
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:ammo_group, Ammo.get_ammo_group!(id))}
+ socket =
+ socket
+ |> assign(
+ page_title: page_title(socket.assigns.live_action),
+ ammo_group: Ammo.get_ammo_group!(id) |> Repo.preload([:container, :ammo_type])
+ )
+
+ {:noreply, socket}
+ end
+
+ @impl true
+ def handle_event("delete", _, socket) do
+ socket.assigns.ammo_group |> Ammo.delete_ammo_group!()
+ {:noreply, socket |> push_redirect(to: Routes.ammo_group_index_path(socket, :index))}
end
defp page_title(:show), do: "Show Ammo group"
diff --git a/lib/cannery_web/live/ammo_group_live/show.html.heex b/lib/cannery_web/live/ammo_group_live/show.html.heex
new file mode 100644
index 00000000..ac94c563
--- /dev/null
+++ b/lib/cannery_web/live/ammo_group_live/show.html.heex
@@ -0,0 +1,62 @@
+
+
+ <%= @ammo_group.ammo_type.name %>
+
+
+
+
+ Count: <%= @ammo_group.count %>
+
+
+ <%= if @ammo_group.notes do %>
+
+ Notes: <%= @ammo_group.notes %>
+
+ <% end %>
+
+ <%= if @ammo_group.price_paid do %>
+
+ Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
+
+ <% end %>
+
+
+
+ <%= live_patch to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
+
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ data: [confirm: "Are you sure you want to delete this ammo?"] do %>
+
+ <% end %>
+
+
+
+
+
+ <%= if @ammo_group.container do %>
+
+ Stored in
+
+
+ <.container_card container={@ammo_group.container} />
+ <% else %>
+ This ammo group is not in a container
+ <% end %>
+
+
+
+<%= if @live_action in [:edit] do %>
+ <%= live_modal(CanneryWeb.AmmoGroupLive.FormComponent,
+ id: @ammo_group.id,
+ title: @page_title,
+ action: @live_action,
+ ammo_group: @ammo_group,
+ return_to: Routes.ammo_group_show_path(@socket, :show, @ammo_group),
+ current_user: @current_user
+ ) %>
+<% end %>
diff --git a/lib/cannery_web/live/ammo_group_live/show.html.leex b/lib/cannery_web/live/ammo_group_live/show.html.leex
deleted file mode 100644
index 67a00f80..00000000
--- a/lib/cannery_web/live/ammo_group_live/show.html.leex
+++ /dev/null
@@ -1,32 +0,0 @@
-Show Ammo group
-
-<%= if @live_action in [:edit] do %>
- <%= live_modal CanneryWeb.AmmoGroupLive.FormComponent,
- id: @ammo_group.id,
- title: @page_title,
- action: @live_action,
- ammo_group: @ammo_group,
- return_to: Routes.ammo_group_show_path(@socket, :show, @ammo_group) %>
-<% end %>
-
-
-
- -
- Count:
- <%= @ammo_group.count %>
-
-
- -
- Price paid:
- <%= @ammo_group.price_paid %>
-
-
- -
- Notes:
- <%= @ammo_group.notes %>
-
-
-
-
-<%= live_patch "Edit", to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group), class: "button" %>
-<%= live_redirect "Back", to: Routes.ammo_group_index_path(@socket, :index) %>
diff --git a/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex b/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex
new file mode 100644
index 00000000..a985d1ad
--- /dev/null
+++ b/lib/cannery_web/live/ammo_type_live/ammo_type_card.ex
@@ -0,0 +1,46 @@
+defmodule CanneryWeb.AmmoTypeLive.AmmoTypeCard do
+ @moduledoc """
+ Display card for an ammo type
+ """
+
+ use CanneryWeb, :component
+ alias Cannery.Repo
+ alias CanneryWeb.Endpoint
+
+ def ammo_group_card(assigns) do
+ assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type))
+
+ ~H"""
+
+ <%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group),
+ class: "mb-2 link" do %>
+
+ <%= @ammo_group.ammo_type.name %>
+
+ <% end %>
+
+
+
+ Count: <%= @ammo_group.count %>
+
+
+ <%= if @ammo_group.notes do %>
+
+ Notes: <%= @ammo_group.notes %>
+
+ <% end %>
+
+ <%= if @ammo_group.price_paid do %>
+
+ Price paid: $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
+
+ <% end %>
+
+
+ """
+ end
+end
diff --git a/lib/cannery_web/live/ammo_type_live/index.html.heex b/lib/cannery_web/live/ammo_type_live/index.html.heex
index ba5fd8a5..4b8ab08f 100644
--- a/lib/cannery_web/live/ammo_type_live/index.html.heex
+++ b/lib/cannery_web/live/ammo_type_live/index.html.heex
@@ -60,21 +60,21 @@
<%= ammo_type.manufacturer %>
-
-
- <%= live_redirect("Show", to: Routes.ammo_type_show_path(@socket, :show, ammo_type)) %>
-
-
- <%= live_patch("Edit", to: Routes.ammo_type_index_path(@socket, :edit, ammo_type)) %>
-
-
- <%= link("Delete",
- to: "#",
- phx_click: "delete",
- phx_value_id: ammo_type.id,
- data: [confirm: "Are you sure?"]
- ) %>
-
+ |
+ <%= live_redirect("View", to: Routes.ammo_type_show_path(@socket, :show, ammo_type)) %>
+
+ <%= live_patch to: Routes.ammo_type_index_path(@socket, :edit, ammo_type),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
+
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ phx_value_id: ammo_type.id,
+ data: [confirm: "Are you sure you want to delete this ammo?"] do %>
+
+ <% end %>
|
<% end %>
diff --git a/lib/cannery_web/live/ammo_type_live/show.ex b/lib/cannery_web/live/ammo_type_live/show.ex
index f9e511c7..77e23125 100644
--- a/lib/cannery_web/live/ammo_type_live/show.ex
+++ b/lib/cannery_web/live/ammo_type_live/show.ex
@@ -4,8 +4,8 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
"""
use CanneryWeb, :live_view
-
- alias Cannery.Ammo
+ import CanneryWeb.AmmoGroupLive.AmmoGroupCard
+ alias Cannery.{Ammo, Repo}
@impl true
def mount(_params, session, socket) do
@@ -14,10 +14,14 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
@impl true
def handle_params(%{"id" => id}, _, socket) do
- {:noreply,
- socket
- |> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:ammo_type, Ammo.get_ammo_type!(id))}
+ socket =
+ socket
+ |> assign(
+ page_title: page_title(socket.assigns.live_action),
+ ammo_type: Ammo.get_ammo_type!(id) |> Repo.preload(:ammo_groups)
+ )
+
+ {:noreply, socket}
end
@impl true
diff --git a/lib/cannery_web/live/ammo_type_live/show.html.heex b/lib/cannery_web/live/ammo_type_live/show.html.heex
index 5ff88763..cbed4587 100644
--- a/lib/cannery_web/live/ammo_type_live/show.html.heex
+++ b/lib/cannery_web/live/ammo_type_live/show.html.heex
@@ -3,45 +3,63 @@
<%= @ammo_type.name %>
-
- <%= 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}?"]
- ) %>
+
+ <%= if @ammo_type.desc do %>
+
+ Desc: <%= @ammo_type.desc %>
+
+ <% end %>
+
+ <%= if @ammo_type.case_material do %>
+
+ Case material: <%= @ammo_type.case_material %>
+
+ <% end %>
+
+ <%= if @ammo_type.bullet_type do %>
+
+ Bullet type: <%= @ammo_type.bullet_type %>
+
+ <% end %>
+
+ <%= if @ammo_type.grain do %>
+
+ Grain: <%= @ammo_type.grain %>
+
+ <% end %>
+
+ <%= if @ammo_type.manufacturer do %>
+
+ Manufacturer: <%= @ammo_type.manufacturer %>
+
+ <% end %>
-
+
+ <%= live_patch to: Routes.ammo_type_show_path(@socket, :edit, @ammo_type),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
-
- -
- Desc:
- <%= @ammo_type.desc %>
-
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ data: [confirm: "Are you sure you want to delete #{@ammo_type.name}?"] do %>
+
+ <% end %>
+
-
- Case material:
- <%= @ammo_type.case_material %>
-
+
-
- Bullet type:
- <%= @ammo_type.bullet_type %>
-
-
-
- Grain:
- <%= @ammo_type.grain %>
-
-
-
- Manufacturer:
- <%= @ammo_type.manufacturer %>
-
-
+
+ <%= if @ammo_type.ammo_groups |> Enum.empty?() do %>
+ No ammo for this type
+ <% else %>
+ <%= for ammo_group <- @ammo_type.ammo_groups do %>
+ <.ammo_group_card ammo_group={ammo_group} />
+ <% end %>
+ <% end %>
+
<%= if @live_action in [:edit] do %>
diff --git a/lib/cannery_web/live/container_live/container_card.ex b/lib/cannery_web/live/container_live/container_card.ex
new file mode 100644
index 00000000..800b9062
--- /dev/null
+++ b/lib/cannery_web/live/container_live/container_card.ex
@@ -0,0 +1,49 @@
+defmodule CanneryWeb.ContainerLive.ContainerCard do
+ @moduledoc """
+ Display card for a container
+ """
+
+ use CanneryWeb, :component
+ alias CanneryWeb.Endpoint
+
+ def container_card(assigns) do
+ ~H"""
+
+
+ <%= live_redirect to: Routes.container_show_path(Endpoint, :show, @container),
+ class: "link" do %>
+
+ <%= @container.name %>
+
+ <% end %>
+
+ <%= if @container.desc do %>
+
+ Description: <%= @container.desc %>
+
+ <% end %>
+
+
+ Type: <%= @container.type %>
+
+
+ <%= if @container.location do %>
+
+ Location: <%= @container.location %>
+
+ <% end %>
+
+
+ <%= if assigns |> Map.has_key?(:inner_block) do %>
+
+ <%= render_slot(@inner_block) %>
+
+ <% end %>
+
+ """
+ end
+end
diff --git a/lib/cannery_web/live/container_live/index.ex b/lib/cannery_web/live/container_live/index.ex
index f269a152..87e9c987 100644
--- a/lib/cannery_web/live/container_live/index.ex
+++ b/lib/cannery_web/live/container_live/index.ex
@@ -4,7 +4,7 @@ defmodule CanneryWeb.ContainerLive.Index do
"""
use CanneryWeb, :live_view
-
+ import CanneryWeb.ContainerLive.ContainerCard
alias Cannery.Containers
alias Cannery.Containers.Container
diff --git a/lib/cannery_web/live/container_live/index.html.heex b/lib/cannery_web/live/container_live/index.html.heex
index df63902d..8a531dc3 100644
--- a/lib/cannery_web/live/container_live/index.html.heex
+++ b/lib/cannery_web/live/container_live/index.html.heex
@@ -21,51 +21,20 @@
<%= for container <- @containers do %>
-
-
-
- <%= container.name %>
-
+ <.container_card container={container}>
+ <%= live_patch to: Routes.container_index_path(@socket, :edit, container),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
- <%= if container.desc do %>
-
- Description: <%= container.desc %>
-
- <% end %>
-
-
- Type: <%= container.type %>
-
-
- <%= if container.location do %>
-
- Location: <%= container.location %>
-
- <% end %>
-
-
-
- <%= live_redirect("Show",
- to: Routes.container_show_path(@socket, :show, container),
- class: "text-primary-500 link"
- ) %>
- <%= live_patch("Edit",
- to: Routes.container_index_path(@socket, :edit, container),
- class: "text-primary-500 link"
- ) %>
- <%= link("Delete",
- to: "#",
- class: "text-primary-500 link",
- phx_click: "delete",
- phx_value_id: container.id,
- data: [confirm: "Are you sure you want to delete #{container.name}?"]
- ) %>
-
-
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ phx_value_id: container.id,
+ data: [confirm: "Are you sure you want to delete #{container.name}?"] do %>
+
+ <% end %>
+
<% end %>
diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex
index a390d20f..bf1c4c46 100644
--- a/lib/cannery_web/live/container_live/show.ex
+++ b/lib/cannery_web/live/container_live/show.ex
@@ -4,8 +4,8 @@ defmodule CanneryWeb.ContainerLive.Show do
"""
use CanneryWeb, :live_view
-
- alias Cannery.Containers
+ import CanneryWeb.AmmoGroupLive.AmmoGroupCard
+ alias Cannery.{Containers, Repo}
@impl true
def mount(_params, session, socket) do
@@ -18,7 +18,7 @@ defmodule CanneryWeb.ContainerLive.Show do
socket
|> assign(
page_title: page_title(socket.assigns.live_action),
- container: Containers.get_container!(id)
+ container: Containers.get_container!(id) |> Repo.preload(:ammo_groups)
)
{:noreply, socket}
diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex
index bf9f3a10..cf9ccc76 100644
--- a/lib/cannery_web/live/container_live/show.html.heex
+++ b/lib/cannery_web/live/container_live/show.html.heex
@@ -20,19 +20,30 @@
<% end %>
- <%= live_redirect("Back", to: Routes.container_index_path(@socket, :index), class: "link") %>
- <%= live_patch("Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "link") %>
- <%= link("Delete",
- to: "#",
- class: "link",
- phx_click: "delete",
- data: [confirm: "Are you sure you want to delete #{@container.name}?"]
- ) %>
+ <%= live_patch to: Routes.container_show_path(@socket, :edit, @container),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
+
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ data: [confirm: "Are you sure you want to delete #{@container.name}?"] do %>
+
+ <% end %>
- No ammo groups in this container
+
+ <%= if @container.ammo_groups |> Enum.empty?() do %>
+ No ammo groups in this container
+ <% else %>
+ <%= for ammo_group <- @container.ammo_groups do %>
+ <.ammo_group_card ammo_group={ammo_group} />
+ <% end %>
+ <% end %>
+
<%= if @live_action in [:edit] do %>
<%= live_modal(CanneryWeb.ContainerLive.FormComponent,
diff --git a/lib/cannery_web/live/invite_live/index.html.leex b/lib/cannery_web/live/invite_live/index.html.leex
index ea1f946c..e9830203 100644
--- a/lib/cannery_web/live/invite_live/index.html.leex
+++ b/lib/cannery_web/live/invite_live/index.html.leex
@@ -15,7 +15,7 @@
<% else %>
<%= live_patch to: Routes.invite_index_path(@socket, :new),
class: "btn btn-primary" do %>
- Invite
+ Create Invite
<% end %>
<% end %>
@@ -42,29 +42,33 @@
- <%= live_patch "Edit", to: Routes.invite_index_path(@socket, :edit, invite),
- class: "text-primary-500 link" %>
+ <%= live_patch to: Routes.invite_index_path(@socket, :edit, invite),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
- <%= link "Delete", to: "#",
- class: "text-primary-500 link",
- phx_click: "delete",
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
phx_value_id: invite.id,
- data: [confirm: "Are you sure?"] %>
+ data: [confirm: "Are you sure you want to delete the invite for #{invite.name}?"] do %>
+
+ <% end %>
<%= if invite.disabled_at |> is_nil() do %>
-
Disable
<% else %>
-
Enable
<% end %>
<%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %>
-
Set Unlimited
diff --git a/lib/cannery_web/live/tag_live/index.ex b/lib/cannery_web/live/tag_live/index.ex
index e5e5c050..04607e85 100644
--- a/lib/cannery_web/live/tag_live/index.ex
+++ b/lib/cannery_web/live/tag_live/index.ex
@@ -4,7 +4,7 @@ defmodule CanneryWeb.TagLive.Index do
"""
use CanneryWeb, :live_view
-
+ import CanneryWeb.TagLive.TagCard
alias Cannery.Tags
alias Cannery.Tags.Tag
diff --git a/lib/cannery_web/live/tag_live/index.html.heex b/lib/cannery_web/live/tag_live/index.html.heex
index 05356a54..ee4d9e9e 100644
--- a/lib/cannery_web/live/tag_live/index.html.heex
+++ b/lib/cannery_web/live/tag_live/index.html.heex
@@ -22,32 +22,11 @@
<% end %>
<%= for tag <- @tags do %>
-
-
- <%= tag.name %>
-
- <%= live_patch to: Routes.tag_index_path(@socket, :edit, tag),
- class: "text-primary-500 link" do %>
-
- <% end %>
- <%= link to: "#",
- class: "text-primary-500 link",
- phx_click: "delete",
- phx_value_id: tag.id,
- data: [confirm: "Are you sure you want to delete #{tag.name}?"] do %>
-
- <% end %>
-
+ <.tag_card tag={tag} />
<% end %>
+
<%= if @live_action in [:new, :edit] do %>
<%= live_modal(CanneryWeb.TagLive.FormComponent,
id: @tag.id || :new,
diff --git a/lib/cannery_web/live/tag_live/tag_card.ex b/lib/cannery_web/live/tag_live/tag_card.ex
new file mode 100644
index 00000000..4abceeb6
--- /dev/null
+++ b/lib/cannery_web/live/tag_live/tag_card.ex
@@ -0,0 +1,38 @@
+defmodule CanneryWeb.TagLive.TagCard do
+ @moduledoc """
+ Display card for a tag
+ """
+
+ use CanneryWeb, :component
+ alias CanneryWeb.Endpoint
+
+ def tag_card(assigns) do
+ ~H"""
+
+
+ <%= @tag.name %>
+
+
+ <%= live_patch to: Routes.tag_index_path(Endpoint, :edit, @tag),
+ class: "text-primary-500 link" do %>
+
+ <% end %>
+
+ <%= link to: "#",
+ class: "text-primary-500 link",
+ phx_click: "delete",
+ phx_value_id: @tag.id,
+ data: [confirm: "Are you sure you want to delete #{@tag.name}?"] do %>
+
+ <% end %>
+
+ """
+ end
+end