diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5b6193..d4b58445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # v0.5.4 - Rename "Ammo" tab to "Catalog", and "Manage" tab is now "Ammo" -- Ammo groups are now just referred to as Ammo +- Ammo groups are now just referred to as Ammo or "Packs" - URL paths now reflect new names +- Add pack and round count to container information # v0.5.3 - Update French translation: Thank you [duponin](https://udongein.xyz/users/duponin)! diff --git a/lib/cannery/containers.ex b/lib/cannery/containers.ex index 55e0b906..58b139e5 100644 --- a/lib/cannery/containers.ex +++ b/lib/cannery/containers.ex @@ -207,6 +207,18 @@ defmodule Cannery.Containers do if count == 0, do: raise("could not delete container tag"), else: count end + @doc """ + Returns number of rounds in container. If data is already preloaded, then + there will be no db hit. + """ + @spec get_container_ammo_group_count!(Container.t()) :: non_neg_integer() + def get_container_ammo_group_count!(%Container{} = container) do + container + |> Repo.preload(:ammo_groups) + |> Map.fetch!(:ammo_groups) + |> Enum.count() + end + @doc """ Returns number of rounds in container. If data is already preloaded, then there will be no db hit. diff --git a/lib/cannery_web/components/container_card.ex b/lib/cannery_web/components/container_card.ex index fc298e91..db3af291 100644 --- a/lib/cannery_web/components/container_card.ex +++ b/lib/cannery_web/components/container_card.ex @@ -45,7 +45,12 @@ defmodule CanneryWeb.Components.ContainerCard do <% end %> - <%= if @container.ammo_groups do %> + <%= unless @container.ammo_groups |> Enum.empty?() do %> + + <%= gettext("Packs:") %> + <%= @container |> Containers.get_container_ammo_group_count!() %> + + <%= gettext("Rounds:") %> <%= @container |> Containers.get_container_rounds!() %> diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex index 43935798..2fc68c6b 100644 --- a/lib/cannery_web/live/container_live/show.html.heex +++ b/lib/cannery_web/live/container_live/show.html.heex @@ -22,6 +22,18 @@ <% end %> + <%= unless @container.ammo_groups |> Enum.empty?() do %> + + <%= gettext("Packs:") %> + <%= @container |> Containers.get_container_ammo_group_count!() %> + + + + <%= gettext("Rounds:") %> + <%= @container |> Containers.get_container_rounds!() %> + + <% end %> +