From dc355fcd8e9d809d45ce576dcd8e4a1f064b1a06 Mon Sep 17 00:00:00 2001 From: shibao Date: Sun, 6 Nov 2022 20:35:12 -0500 Subject: [PATCH] add ammo count to ammo type index page --- CHANGELOG.md | 1 + lib/cannery/ammo.ex | 43 ++++++++++++++++++++ lib/cannery_web/live/ammo_type_live/index.ex | 18 +++++++- priv/gettext/de/LC_MESSAGES/default.po | 11 +++-- priv/gettext/de/LC_MESSAGES/errors.po | 2 +- priv/gettext/de/LC_MESSAGES/prompts.po | 2 +- priv/gettext/default.pot | 11 +++-- priv/gettext/en/LC_MESSAGES/default.po | 11 +++-- priv/gettext/en/LC_MESSAGES/errors.po | 2 +- priv/gettext/en/LC_MESSAGES/prompts.po | 2 +- priv/gettext/errors.pot | 2 +- priv/gettext/es/LC_MESSAGES/default.po | 11 +++-- priv/gettext/es/LC_MESSAGES/errors.po | 2 +- priv/gettext/es/LC_MESSAGES/prompts.po | 2 +- priv/gettext/fr/LC_MESSAGES/default.po | 11 +++-- priv/gettext/fr/LC_MESSAGES/errors.po | 2 +- priv/gettext/fr/LC_MESSAGES/prompts.po | 2 +- priv/gettext/prompts.pot | 2 +- 18 files changed, 111 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 970615b6..47108cab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v0.5.5 - Update translations - Make ammo index page a bit more compact +- Add ammo count to ammo type index page - Forgot to add the logo as the favicon whoops # v0.5.4 diff --git a/lib/cannery/ammo.ex b/lib/cannery/ammo.ex index 3ebe632c..23036e7e 100644 --- a/lib/cannery/ammo.ex +++ b/lib/cannery/ammo.ex @@ -231,6 +231,49 @@ defmodule Cannery.Ammo do ) end + @doc """ + Returns the count of ammo_groups for an ammo type. + + ## Examples + + iex> get_ammo_groups_count_for_type(%User{id: 123}) + 3 + + """ + @spec get_ammo_groups_count_for_type(AmmoType.t(), User.t()) :: [AmmoGroup.t()] + @spec get_ammo_groups_count_for_type(AmmoType.t(), User.t(), include_empty :: boolean()) :: + [AmmoGroup.t()] + def get_ammo_groups_count_for_type(ammo_type, user, include_empty \\ false) + + def get_ammo_groups_count_for_type( + %AmmoType{id: ammo_type_id, user_id: user_id}, + %User{id: user_id}, + _include_empty = true + ) do + Repo.one!( + from ag in AmmoGroup, + where: ag.user_id == ^user_id, + where: ag.ammo_type_id == ^ammo_type_id, + distinct: true, + select: count(ag.id) + ) || 0 + end + + def get_ammo_groups_count_for_type( + %AmmoType{id: ammo_type_id, user_id: user_id}, + %User{id: user_id}, + _include_empty = false + ) do + Repo.one!( + from ag in AmmoGroup, + where: ag.user_id == ^user_id, + where: ag.ammo_type_id == ^ammo_type_id, + where: not (ag.count == 0), + distinct: true, + select: count(ag.id) + ) || 0 + end + @doc """ Returns the list of ammo_groups for a user. diff --git a/lib/cannery_web/live/ammo_type_live/index.ex b/lib/cannery_web/live/ammo_type_live/index.ex index f8ed72af..1597a950 100644 --- a/lib/cannery_web/live/ammo_type_live/index.ex +++ b/lib/cannery_web/live/ammo_type_live/index.ex @@ -48,7 +48,7 @@ defmodule CanneryWeb.AmmoTypeLive.Index do columns = [ - %{label: gettext("Name"), key: "name", type: :string}, + %{label: gettext("Name"), key: "name", type: :name}, %{label: gettext("Bullet type"), key: "bullet_type", type: :string}, %{label: gettext("Bullet core"), key: "bullet_core", type: :string}, %{label: gettext("Cartridge"), key: "cartridge", type: :string}, @@ -84,6 +84,7 @@ defmodule CanneryWeb.AmmoTypeLive.Index do end) |> Kernel.++([ %{label: gettext("Total # of rounds"), key: "round_count", type: :round_count}, + %{label: gettext("Total # of ammo"), key: "ammo_count", type: :ammo_count}, %{label: gettext("Average Price paid"), key: "avg_price_paid", type: :avg_price_paid}, %{label: nil, key: "actions", type: :actions, sortable: false} ]) @@ -108,6 +109,9 @@ defmodule CanneryWeb.AmmoTypeLive.Index do defp get_ammo_type_value(:round_count, _key, ammo_type, current_user), do: ammo_type |> Ammo.get_round_count_for_ammo_type(current_user) + defp get_ammo_type_value(:ammo_count, _key, ammo_type, current_user), + do: ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user) + defp get_ammo_type_value(:avg_price_paid, _key, ammo_type, current_user) do case ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user) do nil -> gettext("No cost information") @@ -115,6 +119,18 @@ defmodule CanneryWeb.AmmoTypeLive.Index do end end + defp get_ammo_type_value(:name, _key, ammo_type, _current_user) do + assigns = %{ammo_type: ammo_type} + + ~H""" + <%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type), + class: "link", + data: [qa: "view-name-#{ammo_type.id}"] do %> + <%= ammo_type.name %> + <% end %> + """ + end + defp get_ammo_type_value(:actions, _key, ammo_type, _current_user) do assigns = %{ammo_type: ammo_type} diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 3f697a2d..47063805 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -59,7 +59,7 @@ msgid "Ammo type" msgstr "Munitionsarten" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:87 +#: lib/cannery_web/live/ammo_type_live/index.ex:88 #: lib/cannery_web/live/ammo_type_live/show.html.heex:100 msgid "Average Price paid" msgstr "Durchschnittlicher Kaufpreis" @@ -620,7 +620,7 @@ msgstr "Schießkladde" #: lib/cannery_web/live/ammo_group_live/index.ex:125 #: lib/cannery_web/live/ammo_group_live/show.html.heex:37 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44 -#: lib/cannery_web/live/ammo_type_live/index.ex:114 +#: lib/cannery_web/live/ammo_type_live/index.ex:118 #: lib/cannery_web/live/ammo_type_live/show.html.heex:104 msgid "$%{amount}" msgstr "$%{amount}" @@ -732,7 +732,7 @@ msgid "Show %{name}" msgstr "Zeige %{name}" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:113 +#: lib/cannery_web/live/ammo_type_live/index.ex:117 #: lib/cannery_web/live/ammo_type_live/show.html.heex:110 msgid "No cost information" msgstr "Keine Preisinformationen" @@ -935,3 +935,8 @@ msgstr "" #: lib/cannery_web/live/invite_live/form_component.html.heex:28 msgid "Leave \"Uses left\" blank to make invite unlimited" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +#: lib/cannery_web/live/ammo_type_live/index.ex:87 +msgid "Total # of ammo" +msgstr "Summe aller Patronen" diff --git a/priv/gettext/de/LC_MESSAGES/errors.po b/priv/gettext/de/LC_MESSAGES/errors.po index 2028391f..228d043f 100644 --- a/priv/gettext/de/LC_MESSAGES/errors.po +++ b/priv/gettext/de/LC_MESSAGES/errors.po @@ -188,7 +188,7 @@ msgstr "" "%{multiplier}" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:442 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/de/LC_MESSAGES/prompts.po b/priv/gettext/de/LC_MESSAGES/prompts.po index dd86fc9b..30e35e15 100644 --- a/priv/gettext/de/LC_MESSAGES/prompts.po +++ b/priv/gettext/de/LC_MESSAGES/prompts.po @@ -293,7 +293,7 @@ msgstr[0] "Munitionsgruppe erfolgreich aktualisiert" msgstr[1] "Munitionsgruppe erfolgreich aktualisiert" #, elixir-autogen, elixir-format, fuzzy -#: lib/cannery_web/live/ammo_type_live/index.ex:140 +#: lib/cannery_web/live/ammo_type_live/index.ex:156 #: lib/cannery_web/live/ammo_type_live/show.html.heex:27 msgid "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!" msgstr "Sind Sie sicher, dass sie %{name} löschen möchten?" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 68242398..bd494ce6 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -44,7 +44,7 @@ msgid "Ammo type" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:87 +#: lib/cannery_web/live/ammo_type_live/index.ex:88 #: lib/cannery_web/live/ammo_type_live/show.html.heex:100 msgid "Average Price paid" msgstr "" @@ -603,7 +603,7 @@ msgstr "" #: lib/cannery_web/live/ammo_group_live/index.ex:125 #: lib/cannery_web/live/ammo_group_live/show.html.heex:37 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44 -#: lib/cannery_web/live/ammo_type_live/index.ex:114 +#: lib/cannery_web/live/ammo_type_live/index.ex:118 #: lib/cannery_web/live/ammo_type_live/show.html.heex:104 msgid "$%{amount}" msgstr "" @@ -715,7 +715,7 @@ msgid "Show %{name}" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:113 +#: lib/cannery_web/live/ammo_type_live/index.ex:117 #: lib/cannery_web/live/ammo_type_live/show.html.heex:110 msgid "No cost information" msgstr "" @@ -918,3 +918,8 @@ msgstr "" #: lib/cannery_web/live/invite_live/form_component.html.heex:28 msgid "Leave \"Uses left\" blank to make invite unlimited" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_type_live/index.ex:87 +msgid "Total # of ammo" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index a5d8f7d7..b9bf3fd6 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -45,7 +45,7 @@ msgid "Ammo type" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:87 +#: lib/cannery_web/live/ammo_type_live/index.ex:88 #: lib/cannery_web/live/ammo_type_live/show.html.heex:100 msgid "Average Price paid" msgstr "" @@ -604,7 +604,7 @@ msgstr "" #: lib/cannery_web/live/ammo_group_live/index.ex:125 #: lib/cannery_web/live/ammo_group_live/show.html.heex:37 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44 -#: lib/cannery_web/live/ammo_type_live/index.ex:114 +#: lib/cannery_web/live/ammo_type_live/index.ex:118 #: lib/cannery_web/live/ammo_type_live/show.html.heex:104 msgid "$%{amount}" msgstr "" @@ -716,7 +716,7 @@ msgid "Show %{name}" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:113 +#: lib/cannery_web/live/ammo_type_live/index.ex:117 #: lib/cannery_web/live/ammo_type_live/show.html.heex:110 msgid "No cost information" msgstr "" @@ -919,3 +919,8 @@ msgstr "" #: lib/cannery_web/live/invite_live/form_component.html.heex:28 msgid "Leave \"Uses left\" blank to make invite unlimited" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +#: lib/cannery_web/live/ammo_type_live/index.ex:87 +msgid "Total # of ammo" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/errors.po b/priv/gettext/en/LC_MESSAGES/errors.po index d0b1a222..13dc2534 100644 --- a/priv/gettext/en/LC_MESSAGES/errors.po +++ b/priv/gettext/en/LC_MESSAGES/errors.po @@ -171,7 +171,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:442 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/prompts.po b/priv/gettext/en/LC_MESSAGES/prompts.po index 551cac9e..8dc9adda 100644 --- a/priv/gettext/en/LC_MESSAGES/prompts.po +++ b/priv/gettext/en/LC_MESSAGES/prompts.po @@ -273,7 +273,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-autogen, elixir-format, fuzzy -#: lib/cannery_web/live/ammo_type_live/index.ex:140 +#: lib/cannery_web/live/ammo_type_live/index.ex:156 #: lib/cannery_web/live/ammo_type_live/show.html.heex:27 msgid "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!" msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 3c684cbe..b18e8457 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -170,7 +170,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:442 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index a65f61b2..80cd5b2a 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -59,7 +59,7 @@ msgid "Ammo type" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:87 +#: lib/cannery_web/live/ammo_type_live/index.ex:88 #: lib/cannery_web/live/ammo_type_live/show.html.heex:100 msgid "Average Price paid" msgstr "" @@ -618,7 +618,7 @@ msgstr "" #: lib/cannery_web/live/ammo_group_live/index.ex:125 #: lib/cannery_web/live/ammo_group_live/show.html.heex:37 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44 -#: lib/cannery_web/live/ammo_type_live/index.ex:114 +#: lib/cannery_web/live/ammo_type_live/index.ex:118 #: lib/cannery_web/live/ammo_type_live/show.html.heex:104 msgid "$%{amount}" msgstr "" @@ -730,7 +730,7 @@ msgid "Show %{name}" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:113 +#: lib/cannery_web/live/ammo_type_live/index.ex:117 #: lib/cannery_web/live/ammo_type_live/show.html.heex:110 msgid "No cost information" msgstr "" @@ -933,3 +933,8 @@ msgstr "" #: lib/cannery_web/live/invite_live/form_component.html.heex:28 msgid "Leave \"Uses left\" blank to make invite unlimited" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +#: lib/cannery_web/live/ammo_type_live/index.ex:87 +msgid "Total # of ammo" +msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/errors.po b/priv/gettext/es/LC_MESSAGES/errors.po index 0b393386..1db6bbba 100644 --- a/priv/gettext/es/LC_MESSAGES/errors.po +++ b/priv/gettext/es/LC_MESSAGES/errors.po @@ -186,7 +186,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:442 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/prompts.po b/priv/gettext/es/LC_MESSAGES/prompts.po index d0e15815..8c1f2a34 100644 --- a/priv/gettext/es/LC_MESSAGES/prompts.po +++ b/priv/gettext/es/LC_MESSAGES/prompts.po @@ -292,7 +292,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-autogen, elixir-format, fuzzy -#: lib/cannery_web/live/ammo_type_live/index.ex:140 +#: lib/cannery_web/live/ammo_type_live/index.ex:156 #: lib/cannery_web/live/ammo_type_live/show.html.heex:27 msgid "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!" msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 14c86c05..470e5bb1 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -59,7 +59,7 @@ msgid "Ammo type" msgstr "Type de munition" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:87 +#: lib/cannery_web/live/ammo_type_live/index.ex:88 #: lib/cannery_web/live/ammo_type_live/show.html.heex:100 msgid "Average Price paid" msgstr "Prix acheté moyen" @@ -622,7 +622,7 @@ msgstr "Évènements de tir" #: lib/cannery_web/live/ammo_group_live/index.ex:125 #: lib/cannery_web/live/ammo_group_live/show.html.heex:37 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44 -#: lib/cannery_web/live/ammo_type_live/index.ex:114 +#: lib/cannery_web/live/ammo_type_live/index.ex:118 #: lib/cannery_web/live/ammo_type_live/show.html.heex:104 msgid "$%{amount}" msgstr "%{amount} $" @@ -734,7 +734,7 @@ msgid "Show %{name}" msgstr "Montrer %{name}" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:113 +#: lib/cannery_web/live/ammo_type_live/index.ex:117 #: lib/cannery_web/live/ammo_type_live/show.html.heex:110 msgid "No cost information" msgstr "Aucune information de prix" @@ -937,3 +937,8 @@ msgstr "" #: lib/cannery_web/live/invite_live/form_component.html.heex:28 msgid "Leave \"Uses left\" blank to make invite unlimited" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +#: lib/cannery_web/live/ammo_type_live/index.ex:87 +msgid "Total # of ammo" +msgstr "Quantité de cartouches" diff --git a/priv/gettext/fr/LC_MESSAGES/errors.po b/priv/gettext/fr/LC_MESSAGES/errors.po index d9409e04..919864a0 100644 --- a/priv/gettext/fr/LC_MESSAGES/errors.po +++ b/priv/gettext/fr/LC_MESSAGES/errors.po @@ -187,7 +187,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:442 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/prompts.po b/priv/gettext/fr/LC_MESSAGES/prompts.po index 5c210a95..8182415f 100644 --- a/priv/gettext/fr/LC_MESSAGES/prompts.po +++ b/priv/gettext/fr/LC_MESSAGES/prompts.po @@ -294,7 +294,7 @@ msgstr[0] "Groupe de munition mis à jour avec succès" msgstr[1] "Groupe de munition mis à jour avec succès" #, elixir-autogen, elixir-format, fuzzy -#: lib/cannery_web/live/ammo_type_live/index.ex:140 +#: lib/cannery_web/live/ammo_type_live/index.ex:156 #: lib/cannery_web/live/ammo_type_live/show.html.heex:27 msgid "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!" msgstr "Êtes-vous certain·e de supprimer %{name} ?" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index f8a02860..cd7bbf83 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -272,7 +272,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_type_live/index.ex:140 +#: lib/cannery_web/live/ammo_type_live/index.ex:156 #: lib/cannery_web/live/ammo_type_live/show.html.heex:27 msgid "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!" msgstr ""