hide historical ammo type information until show_used is toggled

This commit is contained in:
2023-03-19 11:43:13 -04:00
parent fd0bac3bbf
commit 2e372ca2ab
10 changed files with 192 additions and 177 deletions

View File

@ -92,25 +92,40 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
end)
ammo_groups = ammo_type |> Ammo.list_ammo_groups_for_type(current_user, show_used)
original_counts = ammo_groups |> Ammo.get_original_counts(current_user)
cprs = ammo_groups |> Ammo.get_cprs(current_user)
historical_packs_count = ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user, true)
last_used_dates = ammo_groups |> ActivityLog.get_last_used_dates(current_user)
[
original_counts,
used_packs_count,
historical_packs_count,
used_rounds,
historical_round_count
] =
if show_used do
[
ammo_groups |> Ammo.get_original_counts(current_user),
ammo_type |> Ammo.get_used_ammo_groups_count_for_type(current_user),
ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user, true),
ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user),
ammo_type |> Ammo.get_historical_count_for_ammo_type(current_user)
]
else
[nil, nil, nil, nil, nil]
end
socket
|> assign(
page_title: page_title(live_action, ammo_type),
ammo_type: ammo_type,
ammo_groups: ammo_groups,
original_counts: original_counts,
cprs: cprs,
last_used_dates: last_used_dates,
cprs: ammo_groups |> Ammo.get_cprs(current_user),
last_used_dates: ammo_groups |> ActivityLog.get_last_used_dates(current_user),
avg_cost_per_round: ammo_type |> Ammo.get_average_cost_for_ammo_type(current_user),
rounds: ammo_type |> Ammo.get_round_count_for_ammo_type(current_user),
used_rounds: ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user),
historical_round_count: ammo_type |> Ammo.get_historical_count_for_ammo_type(current_user),
original_counts: original_counts,
used_rounds: used_rounds,
historical_round_count: historical_round_count,
packs_count: ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user),
used_packs_count: ammo_type |> Ammo.get_used_ammo_groups_count_for_type(current_user),
used_packs_count: used_packs_count,
historical_packs_count: historical_packs_count,
fields_list: @fields_list,
fields_to_display: fields_to_display

View File

@ -74,26 +74,24 @@
<%= @rounds %>
</span>
<h3 class="title text-lg">
<%= gettext("Used rounds:") %>
</h3>
<%= if @show_used do %>
<h3 class="title text-lg">
<%= gettext("Used rounds:") %>
</h3>
<span class="text-primary-600">
<%= @used_rounds %>
</span>
<span class="text-primary-600">
<%= @used_rounds %>
</span>
<h3 class="title text-lg">
<%= gettext("Total ever rounds:") %>
</h3>
<h3 class="title text-lg">
<%= gettext("Total ever rounds:") %>
</h3>
<span class="text-primary-600">
<%= @historical_round_count %>
</span>
</div>
<span class="text-primary-600">
<%= @historical_round_count %>
</span>
<% end %>
<hr class="hr" />
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
<h3 class="title text-lg">
<%= gettext("Packs:") %>
</h3>
@ -102,26 +100,24 @@
<%= @packs_count %>
</span>
<h3 class="title text-lg">
<%= gettext("Used packs:") %>
</h3>
<%= if @show_used do %>
<h3 class="title text-lg">
<%= gettext("Used packs:") %>
</h3>
<span class="text-primary-600">
<%= @used_packs_count %>
</span>
<span class="text-primary-600">
<%= @used_packs_count %>
</span>
<h3 class="title text-lg">
<%= gettext("Total ever packs:") %>
</h3>
<h3 class="title text-lg">
<%= gettext("Total ever packs:") %>
</h3>
<span class="text-primary-600">
<%= @historical_packs_count %>
</span>
</div>
<span class="text-primary-600">
<%= @historical_packs_count %>
</span>
<% end %>
<hr class="hr" />
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
<h3 class="title text-lg">
<%= gettext("Added on:") %>
</h3>
@ -189,7 +185,7 @@
<.ammo_group_card
:for={%{id: ammo_group_id} = ammo_group <- @ammo_groups}
ammo_group={ammo_group}
original_count={Map.fetch!(@original_counts, ammo_group_id)}
original_count={@original_counts && Map.fetch!(@original_counts, ammo_group_id)}
cpr={Map.get(@cprs, ammo_group_id)}
last_used_date={Map.get(@last_used_dates, ammo_group_id)}
current_user={@current_user}