diff --git a/CHANGELOG.md b/CHANGELOG.md index 443c2c9..3156e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Show ammo groups under a type in a table by default - Only show historical ammo type information when displaying "Show used" in table - Only show historical ammo group information when displaying "Show used" in table +- Fix some values not being sorted in tables properly # v0.8.5 - Add link in readme to github mirror diff --git a/lib/cannery_web/components/ammo_group_table_component.ex b/lib/cannery_web/components/ammo_group_table_component.ex index 194d5ea..ab63965 100644 --- a/lib/cannery_web/components/ammo_group_table_component.ex +++ b/lib/cannery_web/components/ammo_group_table_component.ex @@ -167,10 +167,10 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do end defp get_value_for_key(:price_paid, %{price_paid: nil}, _additional_data), - do: {nil, gettext("No cost information")} + do: {0, gettext("No cost information")} defp get_value_for_key(:price_paid, %{price_paid: price_paid}, _additional_data), - do: gettext("$%{amount}", amount: display_currency(price_paid)) + do: {price_paid, gettext("$%{amount}", amount: display_currency(price_paid))} defp get_value_for_key(:purchased_on, %{purchased_on: purchased_on} = assigns, _additional_data) do {purchased_on, @@ -203,9 +203,8 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do end defp get_value_for_key(:remaining, ammo_group, %{current_user: current_user}) do - gettext("%{percentage}%", - percentage: ammo_group |> Ammo.get_percentage_remaining(current_user) - ) + percentage = ammo_group |> Ammo.get_percentage_remaining(current_user) + {percentage, gettext("%{percentage}%", percentage: percentage)} end defp get_value_for_key(:actions, ammo_group, %{actions: actions}) do @@ -245,13 +244,15 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do end defp get_value_for_key(:cpr, %{price_paid: nil}, _additional_data), - do: {nil, gettext("No cost information")} + do: {0, gettext("No cost information")} - defp get_value_for_key(:cpr, %{id: ammo_group_id}, %{cprs: cprs}), - do: gettext("$%{amount}", amount: display_currency(Map.fetch!(cprs, ammo_group_id))) + defp get_value_for_key(:cpr, %{id: ammo_group_id}, %{cprs: cprs}) do + amount = Map.fetch!(cprs, ammo_group_id) + {amount, gettext("$%{amount}", amount: display_currency(amount))} + end defp get_value_for_key(:count, %{count: count}, _additional_data), - do: if(count == 0, do: gettext("Empty"), else: count) + do: if(count == 0, do: {0, gettext("Empty")}, else: count) defp get_value_for_key(key, ammo_group, _additional_data), do: ammo_group |> Map.get(key) diff --git a/lib/cannery_web/components/ammo_type_table_component.ex b/lib/cannery_web/components/ammo_type_table_component.ex index 7b2a93f..efa7494 100644 --- a/lib/cannery_web/components/ammo_type_table_component.ex +++ b/lib/cannery_web/components/ammo_type_table_component.ex @@ -183,7 +183,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do do: ammo_type |> Map.get(key) |> humanize() defp get_ammo_type_value(:round_count, _key, %{id: ammo_type_id}, %{round_counts: round_counts}), - do: Map.get(round_counts, ammo_type_id) + do: Map.get(round_counts, ammo_type_id, 0) defp get_ammo_type_value( :historical_round_count, @@ -191,7 +191,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do %{id: ammo_type_id}, %{historical_round_counts: historical_round_counts} ) do - Map.get(historical_round_counts, ammo_type_id) + Map.get(historical_round_counts, ammo_type_id, 0) end defp get_ammo_type_value( @@ -200,7 +200,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do %{id: ammo_type_id}, %{used_counts: used_counts} ) do - Map.get(used_counts, ammo_type_id) + Map.get(used_counts, ammo_type_id, 0) end defp get_ammo_type_value( @@ -209,7 +209,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do %{id: ammo_type_id}, %{historical_pack_counts: historical_pack_counts} ) do - Map.get(historical_pack_counts, ammo_type_id) + Map.get(historical_pack_counts, ammo_type_id, 0) end defp get_ammo_type_value( @@ -231,19 +231,20 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do %{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)) + nil -> {0, gettext("No cost information")} + count -> {count, gettext("$%{amount}", amount: display_currency(count))} end end - defp get_ammo_type_value(:name, _key, ammo_type, _other_data) do + defp get_ammo_type_value(:name, _key, %{name: ammo_type_name} = ammo_type, _other_data) do assigns = %{ammo_type: ammo_type} - ~H""" - <.link navigate={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)} class="link"> - <%= @ammo_type.name %> - - """ + {ammo_type_name, + ~H""" + <.link navigate={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)} class="link"> + <%= @ammo_type.name %> + + """} end defp get_ammo_type_value(:actions, _key, ammo_type, %{actions: actions}) do diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 83efbab..207f508 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -621,7 +621,7 @@ msgid "Rounds:" msgstr "Patronen:" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -809,7 +809,7 @@ msgstr "Behälter" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -996,7 +996,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "%{name} bearbeiten" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index df126c2..a1dafc2 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -615,7 +615,7 @@ msgid "Rounds:" msgstr "" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -803,7 +803,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -990,7 +990,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index a97a5fc..8a7856a 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -615,7 +615,7 @@ msgid "Rounds:" msgstr "" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -803,7 +803,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -990,7 +990,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty" diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index 9f44680..cf25c82 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -622,7 +622,7 @@ msgid "Rounds:" msgstr "Balas:" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -811,7 +811,7 @@ msgstr "Contenedor:" msgid "Show used" msgstr "Mostrar usadas" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -998,7 +998,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "Editar %{ammo_type_name}" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 6b2e212..e70a6dc 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -623,7 +623,7 @@ msgid "Rounds:" msgstr "Cartouches :" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -812,7 +812,7 @@ msgstr "Conteneur" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -999,7 +999,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "Éditer %{name}" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty" diff --git a/priv/gettext/ga/LC_MESSAGES/default.po b/priv/gettext/ga/LC_MESSAGES/default.po index 4e0b4aa..bcfce67 100644 --- a/priv/gettext/ga/LC_MESSAGES/default.po +++ b/priv/gettext/ga/LC_MESSAGES/default.po @@ -617,7 +617,7 @@ msgid "Rounds:" msgstr "" #: lib/cannery_web/components/ammo_group_table_component.ex:170 -#: lib/cannery_web/components/ammo_group_table_component.ex:248 +#: lib/cannery_web/components/ammo_group_table_component.ex:247 #: 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 @@ -805,7 +805,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:206 +#: lib/cannery_web/components/ammo_group_table_component.ex:207 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -992,7 +992,7 @@ msgstr "" msgid "Edit %{ammo_type_name}" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:254 +#: lib/cannery_web/components/ammo_group_table_component.ex:255 #: lib/cannery_web/components/core_components/ammo_group_card.html.heex:17 #, elixir-autogen, elixir-format msgid "Empty"