improve code in table components

This commit is contained in:
shibao 2022-12-03 21:41:54 -05:00
parent 58b32817ba
commit 0894293620
9 changed files with 68 additions and 65 deletions

View File

@ -89,19 +89,20 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
[%{label: gettext("Ammo type"), key: :ammo_type} | columns] [%{label: gettext("Ammo type"), key: :ammo_type} | columns]
end end
extra_data = %{
current_user: current_user,
ammo_type: ammo_type,
columns: columns,
container: container,
actions: actions,
range: range
}
rows = rows =
ammo_groups ammo_groups
|> Repo.preload([:ammo_type, :container]) |> Repo.preload([:ammo_type, :container])
|> Enum.map(fn ammo_group -> |> Enum.map(fn ammo_group ->
ammo_group ammo_group |> get_row_data_for_ammo_group(extra_data)
|> get_row_data_for_ammo_group(%{
current_user: current_user,
ammo_type: ammo_type,
columns: columns,
container: container,
actions: actions,
range: range
})
end) end)
socket |> assign(columns: columns, rows: rows) socket |> assign(columns: columns, rows: rows)

View File

@ -121,11 +121,12 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
%{label: nil, key: "actions", type: :actions, sortable: false} %{label: nil, key: "actions", type: :actions, sortable: false}
]) ])
extra_data = %{actions: actions, current_user: current_user}
rows = rows =
ammo_types ammo_types
|> Enum.map(fn ammo_type -> |> Enum.map(fn ammo_type ->
ammo_type ammo_type |> get_ammo_type_values(columns, extra_data)
|> get_ammo_type_values(columns, %{actions: actions, current_user: current_user})
end) end)
socket |> assign(columns: columns, rows: rows) socket |> assign(columns: columns, rows: rows)

View File

@ -66,15 +66,16 @@ defmodule CanneryWeb.Components.ContainerTableComponent do
end) end)
end) end)
extra_data = %{
current_user: current_user,
tag_actions: tag_actions,
actions: actions
}
rows = rows =
containers containers
|> Enum.map(fn container -> |> Enum.map(fn container ->
container container |> get_row_data_for_container(columns, extra_data)
|> get_row_data_for_container(columns, %{
current_user: current_user,
tag_actions: tag_actions,
actions: actions
})
end) end)
socket socket

View File

@ -555,9 +555,9 @@ msgstr "Schießkladde"
#: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -661,8 +661,8 @@ msgstr "Editiere %{name} Tags"
msgid "Rounds:" msgid "Rounds:"
msgstr "Patronen:" msgstr "Patronen:"
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -856,7 +856,7 @@ msgstr "Behälter"
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1044,7 +1044,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "%{name} bearbeiten" msgstr "%{name} bearbeiten"
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1094,7 +1094,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -538,9 +538,9 @@ msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -644,8 +644,8 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -839,7 +839,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1027,7 +1027,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1077,7 +1077,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -539,9 +539,9 @@ msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -645,8 +645,8 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -840,7 +840,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1028,7 +1028,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1078,7 +1078,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -553,9 +553,9 @@ msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -659,8 +659,8 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -854,7 +854,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1042,7 +1042,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1092,7 +1092,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -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:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -663,8 +663,8 @@ msgstr "Éditer les tags de %{name}"
msgid "Rounds:" msgid "Rounds:"
msgstr "Cartouches:" msgstr "Cartouches:"
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -859,7 +859,7 @@ msgstr "Conteneur"
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1047,7 +1047,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "Éditer %{name}" msgstr "Éditer %{name}"
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1097,7 +1097,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -549,9 +549,9 @@ msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71 #: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78 #: 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:153
#: lib/cannery_web/components/ammo_group_table_component.ex:224 #: lib/cannery_web/components/ammo_group_table_component.ex:225
#: lib/cannery_web/components/ammo_type_table_component.ex:179 #: 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:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44 #: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/show.html.heex:136 #: lib/cannery_web/live/ammo_type_live/show.html.heex:136
@ -655,8 +655,8 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:221 #: lib/cannery_web/components/ammo_group_table_component.ex:222
#: lib/cannery_web/components/ammo_type_table_component.ex:178 #: lib/cannery_web/components/ammo_type_table_component.ex:179
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142 #: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -850,7 +850,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" 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 #: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -1038,7 +1038,7 @@ msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:39 #: 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 #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1088,7 +1088,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""