fix ammo type table not displaying correct information
This commit is contained in:
parent
40e4f6fe0a
commit
ca81924ebe
@ -1,6 +1,7 @@
|
||||
# v0.8.6
|
||||
- Fix duplicate entries showing up
|
||||
- Show ammo groups under a type in a table by default
|
||||
- Only show historical ammo type information when displaying "Show used" in table
|
||||
|
||||
# v0.8.5
|
||||
- Add link in readme to github mirror
|
||||
|
@ -103,13 +103,13 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
|
||||
[
|
||||
%{
|
||||
label: gettext("Used packs"),
|
||||
key: :used_packs_count,
|
||||
type: :used_packs_count
|
||||
key: :used_pack_count,
|
||||
type: :used_pack_count
|
||||
},
|
||||
%{
|
||||
label: gettext("Total ever packs"),
|
||||
key: :historical_packs_count,
|
||||
type: :historical_packs_count
|
||||
key: :historical_pack_count,
|
||||
type: :historical_pack_count
|
||||
}
|
||||
]
|
||||
else
|
||||
@ -122,23 +122,21 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
|
||||
])
|
||||
|
||||
round_counts = ammo_types |> Ammo.get_round_count_for_ammo_types(current_user)
|
||||
|
||||
used_counts =
|
||||
show_used && ammo_types |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
|
||||
historical_round_counts =
|
||||
show_used && ammo_types |> Ammo.get_historical_count_for_ammo_types(current_user)
|
||||
|
||||
packs_count = ammo_types |> Ammo.get_ammo_groups_count_for_types(current_user)
|
||||
|
||||
historical_packs_count =
|
||||
show_used && ammo_types |> Ammo.get_ammo_groups_count_for_types(current_user, true)
|
||||
|
||||
used_packs_count =
|
||||
show_used && ammo_types |> Ammo.get_used_ammo_groups_count_for_types(current_user)
|
||||
|
||||
average_costs = ammo_types |> Ammo.get_average_cost_for_ammo_types(current_user)
|
||||
|
||||
[used_counts, historical_round_counts, historical_pack_counts, used_pack_counts] =
|
||||
if show_used do
|
||||
[
|
||||
ammo_types |> ActivityLog.get_used_count_for_ammo_types(current_user),
|
||||
ammo_types |> Ammo.get_historical_count_for_ammo_types(current_user),
|
||||
ammo_types |> Ammo.get_ammo_groups_count_for_types(current_user, true),
|
||||
ammo_types |> Ammo.get_used_ammo_groups_count_for_types(current_user)
|
||||
]
|
||||
else
|
||||
[nil, nil, nil, nil]
|
||||
end
|
||||
|
||||
extra_data = %{
|
||||
actions: actions,
|
||||
current_user: current_user,
|
||||
@ -146,8 +144,8 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
|
||||
round_counts: round_counts,
|
||||
historical_round_counts: historical_round_counts,
|
||||
packs_count: packs_count,
|
||||
used_packs_count: used_packs_count,
|
||||
historical_packs_count: historical_packs_count,
|
||||
used_pack_counts: used_pack_counts,
|
||||
historical_pack_counts: historical_pack_counts,
|
||||
average_costs: average_costs
|
||||
}
|
||||
|
||||
@ -192,33 +190,46 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
|
||||
_key,
|
||||
%{id: ammo_type_id},
|
||||
%{historical_round_counts: historical_round_counts}
|
||||
),
|
||||
do: Map.get(historical_round_counts, ammo_type_id)
|
||||
|
||||
defp get_ammo_type_value(:used_round_count, _key, %{id: ammo_type_id}, %{
|
||||
used_counts: used_counts
|
||||
}),
|
||||
do: Map.get(used_counts, ammo_type_id)
|
||||
) do
|
||||
Map.get(historical_round_counts, ammo_type_id)
|
||||
end
|
||||
|
||||
defp get_ammo_type_value(
|
||||
:historical_packs_count,
|
||||
:used_round_count,
|
||||
_key,
|
||||
%{id: ammo_type_id},
|
||||
%{historical_packs_count: historical_packs_count}
|
||||
),
|
||||
do: Map.get(historical_packs_count, ammo_type_id)
|
||||
%{used_counts: used_counts}
|
||||
) do
|
||||
Map.get(used_counts, ammo_type_id)
|
||||
end
|
||||
|
||||
defp get_ammo_type_value(:used_packs_count, _key, %{id: ammo_type_id}, %{
|
||||
used_packs_count: used_packs_count
|
||||
}),
|
||||
do: Map.get(used_packs_count, ammo_type_id)
|
||||
defp get_ammo_type_value(
|
||||
:historical_pack_count,
|
||||
_key,
|
||||
%{id: ammo_type_id},
|
||||
%{historical_pack_counts: historical_pack_counts}
|
||||
) do
|
||||
Map.get(historical_pack_counts, ammo_type_id)
|
||||
end
|
||||
|
||||
defp get_ammo_type_value(
|
||||
:used_pack_count,
|
||||
_key,
|
||||
%{id: ammo_type_id},
|
||||
%{used_pack_counts: used_pack_counts}
|
||||
) do
|
||||
Map.get(used_pack_counts, ammo_type_id, 0)
|
||||
end
|
||||
|
||||
defp get_ammo_type_value(:ammo_count, _key, %{id: ammo_type_id}, %{packs_count: packs_count}),
|
||||
do: Map.get(packs_count, ammo_type_id)
|
||||
|
||||
defp get_ammo_type_value(:avg_price_paid, _key, %{id: ammo_type_id}, %{
|
||||
average_costs: average_costs
|
||||
}) do
|
||||
defp get_ammo_type_value(
|
||||
:avg_price_paid,
|
||||
_key,
|
||||
%{id: ammo_type_id},
|
||||
%{average_costs: average_costs}
|
||||
) do
|
||||
case Map.get(average_costs, ammo_type_id) do
|
||||
nil -> gettext("No cost information")
|
||||
count -> gettext("$%{amount}", amount: display_currency(count))
|
||||
|
@ -528,7 +528,7 @@ msgstr "Schießkladde"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -622,7 +622,7 @@ msgid "Rounds:"
|
||||
msgstr "Patronen:"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -522,7 +522,7 @@ msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -616,7 +616,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -522,7 +522,7 @@ msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -616,7 +616,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -529,7 +529,7 @@ msgstr "Registro de tiros"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -623,7 +623,7 @@ msgid "Rounds:"
|
||||
msgstr "Balas:"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -530,7 +530,7 @@ msgstr "Évènements de tir"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -624,7 +624,7 @@ msgid "Rounds:"
|
||||
msgstr "Cartouches :"
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -524,7 +524,7 @@ msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:154
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:230
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:224
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:235
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:45
|
||||
#: lib/cannery_web/components/core_components/ammo_group_card.html.heex:50
|
||||
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
|
||||
@ -618,7 +618,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/components/ammo_group_table_component.ex:227
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:223
|
||||
#: lib/cannery_web/components/ammo_type_table_component.ex:234
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:139
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No cost information"
|
||||
|
@ -230,9 +230,9 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
assert html =~ gettext("Used packs")
|
||||
assert html =~ gettext("Total ever packs")
|
||||
|
||||
assert html =~ "20"
|
||||
assert html =~ "0"
|
||||
assert html =~ "1"
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ "\n0\n"
|
||||
assert html =~ "\n1\n"
|
||||
|
||||
shot_group_fixture(%{"count" => 5}, current_user, ammo_group)
|
||||
|
||||
@ -243,8 +243,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "15"
|
||||
assert html =~ "5"
|
||||
assert html =~ "\n15\n"
|
||||
assert html =~ "\n5\n"
|
||||
end
|
||||
end
|
||||
|
||||
@ -297,7 +297,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, _show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|
||||
|
||||
assert html =~ ammo_type_name
|
||||
assert html =~ "some ammo group"
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ container_name
|
||||
end
|
||||
|
||||
@ -310,7 +310,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "some ammo group"
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ container_name
|
||||
end
|
||||
end
|
||||
@ -323,14 +323,14 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
refute html =~ "some ammo group"
|
||||
refute html =~ "\n20\n"
|
||||
|
||||
html =
|
||||
show_live
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "some ammo group"
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ "Empty"
|
||||
assert html =~ container_name
|
||||
end
|
||||
@ -345,14 +345,14 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> render_click()
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
refute html =~ "some ammo group"
|
||||
refute html =~ "\n20\n"
|
||||
|
||||
html =
|
||||
show_live
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "some ammo group"
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ "Empty"
|
||||
assert html =~ container_name
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user