From 08942936202e39f20ab35ab5ca048999fb43fb44 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 3 Dec 2022 21:41:54 -0500 Subject: [PATCH] improve code in table components --- .../components/ammo_group_table_component.ex | 19 ++++++++++--------- .../components/ammo_type_table_component.ex | 5 +++-- .../components/container_table_component.ex | 13 +++++++------ priv/gettext/de/LC_MESSAGES/default.po | 16 ++++++++-------- priv/gettext/default.pot | 16 ++++++++-------- priv/gettext/en/LC_MESSAGES/default.po | 16 ++++++++-------- priv/gettext/es/LC_MESSAGES/default.po | 16 ++++++++-------- priv/gettext/fr/LC_MESSAGES/default.po | 16 ++++++++-------- priv/gettext/ga/LC_MESSAGES/default.po | 16 ++++++++-------- 9 files changed, 68 insertions(+), 65 deletions(-) diff --git a/lib/cannery_web/components/ammo_group_table_component.ex b/lib/cannery_web/components/ammo_group_table_component.ex index 6c24bb31..d8aad19e 100644 --- a/lib/cannery_web/components/ammo_group_table_component.ex +++ b/lib/cannery_web/components/ammo_group_table_component.ex @@ -89,19 +89,20 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do [%{label: gettext("Ammo type"), key: :ammo_type} | columns] end + extra_data = %{ + current_user: current_user, + ammo_type: ammo_type, + columns: columns, + container: container, + actions: actions, + range: range + } + rows = ammo_groups |> Repo.preload([:ammo_type, :container]) |> Enum.map(fn ammo_group -> - ammo_group - |> get_row_data_for_ammo_group(%{ - current_user: current_user, - ammo_type: ammo_type, - columns: columns, - container: container, - actions: actions, - range: range - }) + ammo_group |> get_row_data_for_ammo_group(extra_data) end) socket |> assign(columns: columns, rows: rows) diff --git a/lib/cannery_web/components/ammo_type_table_component.ex b/lib/cannery_web/components/ammo_type_table_component.ex index 85b97efe..fa366410 100644 --- a/lib/cannery_web/components/ammo_type_table_component.ex +++ b/lib/cannery_web/components/ammo_type_table_component.ex @@ -121,11 +121,12 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do %{label: nil, key: "actions", type: :actions, sortable: false} ]) + extra_data = %{actions: actions, current_user: current_user} + rows = ammo_types |> Enum.map(fn ammo_type -> - ammo_type - |> get_ammo_type_values(columns, %{actions: actions, current_user: current_user}) + ammo_type |> get_ammo_type_values(columns, extra_data) end) socket |> assign(columns: columns, rows: rows) diff --git a/lib/cannery_web/components/container_table_component.ex b/lib/cannery_web/components/container_table_component.ex index cbed7b20..c97c585d 100644 --- a/lib/cannery_web/components/container_table_component.ex +++ b/lib/cannery_web/components/container_table_component.ex @@ -66,15 +66,16 @@ defmodule CanneryWeb.Components.ContainerTableComponent do end) end) + extra_data = %{ + current_user: current_user, + tag_actions: tag_actions, + actions: actions + } + rows = containers |> Enum.map(fn container -> - container - |> get_row_data_for_container(columns, %{ - current_user: current_user, - tag_actions: tag_actions, - actions: actions - }) + container |> get_row_data_for_container(columns, extra_data) end) socket diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 31e3afc1..e4ecef94 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -555,9 +555,9 @@ msgstr "Schießkladde" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -661,8 +661,8 @@ msgstr "Editiere %{name} Tags" msgid "Rounds:" msgstr "Patronen:" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -856,7 +856,7 @@ msgstr "Behälter" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1044,7 +1044,7 @@ msgid "Edit %{ammo_type_name}" msgstr "%{name} bearbeiten" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1094,7 +1094,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 37c5d0b6..6cd3e18e 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -538,9 +538,9 @@ msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -644,8 +644,8 @@ msgstr "" msgid "Rounds:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -839,7 +839,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1027,7 +1027,7 @@ msgid "Edit %{ammo_type_name}" msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1077,7 +1077,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index c77f7d96..a71af166 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -539,9 +539,9 @@ msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -645,8 +645,8 @@ msgstr "" msgid "Rounds:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -840,7 +840,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1028,7 +1028,7 @@ msgid "Edit %{ammo_type_name}" msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1078,7 +1078,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index b9ea4155..e55a218f 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -553,9 +553,9 @@ msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -659,8 +659,8 @@ msgstr "" msgid "Rounds:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -854,7 +854,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1042,7 +1042,7 @@ msgid "Edit %{ammo_type_name}" msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1092,7 +1092,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 5a78871b..78b0cd05 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -557,9 +557,9 @@ msgstr "Évènements de tir" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -663,8 +663,8 @@ msgstr "Éditer les tags de %{name}" msgid "Rounds:" msgstr "Cartouches :" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -859,7 +859,7 @@ msgstr "Conteneur" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1047,7 +1047,7 @@ msgid "Edit %{ammo_type_name}" msgstr "Éditer %{name}" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1097,7 +1097,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr "" diff --git a/priv/gettext/ga/LC_MESSAGES/default.po b/priv/gettext/ga/LC_MESSAGES/default.po index 833d6b5c..9a0199bb 100644 --- a/priv/gettext/ga/LC_MESSAGES/default.po +++ b/priv/gettext/ga/LC_MESSAGES/default.po @@ -549,9 +549,9 @@ msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:78 -#: lib/cannery_web/components/ammo_group_table_component.ex:152 -#: lib/cannery_web/components/ammo_group_table_component.ex:224 -#: lib/cannery_web/components/ammo_type_table_component.ex:179 +#: lib/cannery_web/components/ammo_group_table_component.ex:153 +#: lib/cannery_web/components/ammo_group_table_component.ex:225 +#: lib/cannery_web/components/ammo_type_table_component.ex:180 #: 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/show.html.heex:136 @@ -655,8 +655,8 @@ msgstr "" msgid "Rounds:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:221 -#: lib/cannery_web/components/ammo_type_table_component.ex:178 +#: lib/cannery_web/components/ammo_group_table_component.ex:222 +#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #, elixir-autogen, elixir-format msgid "No cost information" @@ -850,7 +850,7 @@ msgstr "" msgid "Show used" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:192 +#: lib/cannery_web/components/ammo_group_table_component.ex:193 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19 #, elixir-autogen, elixir-format msgid "%{percentage}%" @@ -1038,7 +1038,7 @@ msgid "Edit %{ammo_type_name}" msgstr "" #: lib/cannery_web/components/ammo_group_card.ex:39 -#: lib/cannery_web/components/ammo_group_table_component.ex:230 +#: lib/cannery_web/components/ammo_group_table_component.ex:231 #, elixir-autogen, elixir-format msgid "Empty" msgstr "" @@ -1088,7 +1088,7 @@ msgstr "" msgid "Last used on:" msgstr "" -#: lib/cannery_web/components/ammo_group_table_component.ex:177 +#: lib/cannery_web/components/ammo_group_table_component.ex:178 #, elixir-autogen, elixir-format msgid "Never used" msgstr ""