improve Ammo.get_packs_count

This commit is contained in:
2023-06-04 20:53:57 -04:00
parent cfc56519f5
commit a94d2eebf4
15 changed files with 82 additions and 124 deletions

View File

@ -27,10 +27,10 @@
<%= @container.location %>
</span>
<%= if @container |> Ammo.get_packs_count_for_container!(@current_user) != 0 do %>
<%= if Ammo.get_packs_count(@current_user, container_id: @container.id) != 0 do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Ammo.get_packs_count_for_container!(@current_user) %>
<%= Ammo.get_packs_count(@current_user, container_id: @container.id) %>
</span>
<span class="rounded-lg title text-lg">

View File

@ -52,7 +52,7 @@ defmodule CanneryWeb.ExportController do
containers =
Containers.list_containers(current_user)
|> Enum.map(fn container ->
pack_count = container |> Ammo.get_packs_count_for_container!(current_user)
pack_count = Ammo.get_packs_count(current_user, container_id: container.id)
round_count = container |> Ammo.get_round_count_for_container!(current_user)
container

View File

@ -122,8 +122,8 @@ defmodule CanneryWeb.ContainerLive.Show do
socket
|> assign(
container: container,
round_count: Ammo.get_round_count_for_container!(container, current_user),
packs_count: Ammo.get_packs_count_for_container!(container, current_user),
round_count: container |> Ammo.get_round_count_for_container!(current_user),
packs_count: Ammo.get_packs_count(current_user, container_id: container.id),
packs: packs,
original_counts: original_counts,
cprs: cprs,

View File

@ -148,7 +148,7 @@ defmodule CanneryWeb.PackLive.Index do
) do
# get total number of packs to determine whether to display onboarding
# prompts
packs_count = Ammo.get_packs_count!(current_user, true)
packs_count = Ammo.get_packs_count(current_user, show_used: true)
packs = Ammo.list_packs(current_user, search: search, class: class, show_used: show_used)
types_count = Ammo.get_types_count!(current_user)
containers_count = Containers.get_containers_count!(current_user)

View File

@ -66,8 +66,8 @@ defmodule CanneryWeb.TypeLive.Show do
if show_used do
[
packs |> Ammo.get_original_counts(current_user),
type |> Ammo.get_used_packs_count_for_type(current_user),
type |> Ammo.get_packs_count_for_type(current_user, true),
Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used),
Ammo.get_packs_count(current_user, type_id: type.id, show_used: true),
type |> ActivityLog.get_used_count_for_type(current_user),
type |> Ammo.get_historical_count_for_type(current_user)
]
@ -99,7 +99,7 @@ defmodule CanneryWeb.TypeLive.Show do
original_counts: original_counts,
used_rounds: used_rounds,
historical_round_count: historical_round_count,
packs_count: type |> Ammo.get_packs_count_for_type(current_user),
packs_count: Ammo.get_packs_count(current_user, type_id: type.id),
used_packs_count: used_packs_count,
historical_packs_count: historical_packs_count,
fields_to_display: fields_to_display(type),