add pack and round count to containers

This commit is contained in:
shibao 2022-07-01 19:13:54 -04:00
parent 11b1ae9980
commit 9a1a104c6d
4 changed files with 32 additions and 2 deletions

View File

@ -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)!

View File

@ -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.

View File

@ -45,7 +45,12 @@ defmodule CanneryWeb.Components.ContainerCard do
</span>
<% end %>
<%= if @container.ammo_groups do %>
<%= unless @container.ammo_groups |> Enum.empty?() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Containers.get_container_ammo_group_count!() %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>

View File

@ -22,6 +22,18 @@
</span>
<% end %>
<%= unless @container.ammo_groups |> Enum.empty?() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Containers.get_container_ammo_group_count!() %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>
</span>
<% end %>
<div class="flex space-x-4 justify-center items-center text-primary-600">
<%= live_patch to: Routes.container_show_path(Endpoint, :edit, @container),
class: "text-primary-600 link",