rename ammo groups to packs
This commit is contained in:
@ -4,7 +4,7 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo.AmmoGroup}
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo.Pack}
|
||||
alias Ecto.Changeset
|
||||
alias Phoenix.LiveView.{JS, Socket}
|
||||
|
||||
@ -12,15 +12,15 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
@spec update(
|
||||
%{
|
||||
required(:current_user) => User.t(),
|
||||
required(:ammo_group) => AmmoGroup.t(),
|
||||
required(:pack) => Pack.t(),
|
||||
optional(any()) => any()
|
||||
},
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(%{ammo_group: ammo_group, current_user: current_user} = assigns, socket) do
|
||||
def update(%{pack: pack, current_user: current_user} = assigns, socket) do
|
||||
changeset =
|
||||
%ShotGroup{date: Date.utc_today()}
|
||||
|> ShotGroup.create_changeset(current_user, ammo_group, %{})
|
||||
|> ShotGroup.create_changeset(current_user, pack, %{})
|
||||
|
||||
{:ok, socket |> assign(assigns) |> assign(:changeset, changeset)}
|
||||
end
|
||||
@ -29,11 +29,11 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
def handle_event(
|
||||
"validate",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
|
||||
%{assigns: %{pack: pack, current_user: current_user}} = socket
|
||||
) do
|
||||
params = shot_group_params |> process_params(ammo_group)
|
||||
params = shot_group_params |> process_params(pack)
|
||||
|
||||
changeset = %ShotGroup{} |> ShotGroup.create_changeset(current_user, ammo_group, params)
|
||||
changeset = %ShotGroup{} |> ShotGroup.create_changeset(current_user, pack, params)
|
||||
|
||||
changeset =
|
||||
case changeset |> Changeset.apply_action(:validate) do
|
||||
@ -48,13 +48,13 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
"save",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{
|
||||
assigns: %{ammo_group: ammo_group, current_user: current_user, return_to: return_to}
|
||||
assigns: %{pack: pack, current_user: current_user, return_to: return_to}
|
||||
} = socket
|
||||
) do
|
||||
socket =
|
||||
shot_group_params
|
||||
|> process_params(ammo_group)
|
||||
|> ActivityLog.create_shot_group(current_user, ammo_group)
|
||||
|> process_params(pack)
|
||||
|> ActivityLog.create_shot_group(current_user, pack)
|
||||
|> case do
|
||||
{:ok, _shot_group} ->
|
||||
prompt = dgettext("prompts", "Shots recorded successfully")
|
||||
@ -68,7 +68,7 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
end
|
||||
|
||||
# calculate count from shots left
|
||||
defp process_params(params, %AmmoGroup{count: count}) do
|
||||
defp process_params(params, %Pack{count: count}) do
|
||||
shot_group_count =
|
||||
if params |> Map.get("ammo_left", "") == "" do
|
||||
nil
|
||||
|
@ -22,7 +22,7 @@
|
||||
<%= label(f, :ammo_left, gettext("Rounds left"), class: "title text-lg text-primary-600") %>
|
||||
<%= number_input(f, :ammo_left,
|
||||
min: 0,
|
||||
max: @ammo_group.count - 1,
|
||||
max: @pack.count - 1,
|
||||
placeholder: gettext("Rounds left"),
|
||||
class: "input input-primary"
|
||||
) %>
|
||||
|
@ -1,9 +1,9 @@
|
||||
defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
defmodule CanneryWeb.Components.PackTableComponent do
|
||||
@moduledoc """
|
||||
A component that displays a list of ammo groups
|
||||
"""
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, Ammo.AmmoGroup, ComparableDate}
|
||||
alias Cannery.{Accounts.User, Ammo.Pack, ComparableDate}
|
||||
alias Cannery.{ActivityLog, Ammo, Containers}
|
||||
alias CanneryWeb.Components.TableComponent
|
||||
alias Ecto.UUID
|
||||
@ -14,7 +14,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
%{
|
||||
required(:id) => UUID.t(),
|
||||
required(:current_user) => User.t(),
|
||||
required(:ammo_groups) => [AmmoGroup.t()],
|
||||
required(:packs) => [Pack.t()],
|
||||
required(:show_used) => boolean(),
|
||||
optional(:ammo_type) => Rendered.t(),
|
||||
optional(:range) => Rendered.t(),
|
||||
@ -25,8 +25,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(
|
||||
%{id: _id, ammo_groups: _ammo_group, current_user: _current_user, show_used: _show_used} =
|
||||
assigns,
|
||||
%{id: _id, packs: _pack, current_user: _current_user, show_used: _show_used} = assigns,
|
||||
socket
|
||||
) do
|
||||
socket =
|
||||
@ -36,15 +35,15 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
|> assign_new(:range, fn -> [] end)
|
||||
|> assign_new(:container, fn -> [] end)
|
||||
|> assign_new(:actions, fn -> [] end)
|
||||
|> display_ammo_groups()
|
||||
|> display_packs()
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
defp display_ammo_groups(
|
||||
defp display_packs(
|
||||
%{
|
||||
assigns: %{
|
||||
ammo_groups: ammo_groups,
|
||||
packs: packs,
|
||||
current_user: current_user,
|
||||
ammo_type: ammo_type,
|
||||
range: range,
|
||||
@ -98,7 +97,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
)
|
||||
|
||||
containers =
|
||||
ammo_groups
|
||||
packs
|
||||
|> Enum.map(fn %{container_id: container_id} -> container_id end)
|
||||
|> Containers.get_containers(current_user)
|
||||
|
||||
@ -108,18 +107,18 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
columns: columns,
|
||||
container: container,
|
||||
containers: containers,
|
||||
original_counts: Ammo.get_original_counts(ammo_groups, current_user),
|
||||
cprs: Ammo.get_cprs(ammo_groups, current_user),
|
||||
last_used_dates: ActivityLog.get_last_used_dates(ammo_groups, current_user),
|
||||
percentages_remaining: Ammo.get_percentages_remaining(ammo_groups, current_user),
|
||||
original_counts: Ammo.get_original_counts(packs, current_user),
|
||||
cprs: Ammo.get_cprs(packs, current_user),
|
||||
last_used_dates: ActivityLog.get_last_used_dates(packs, current_user),
|
||||
percentages_remaining: Ammo.get_percentages_remaining(packs, current_user),
|
||||
actions: actions,
|
||||
range: range
|
||||
}
|
||||
|
||||
rows =
|
||||
ammo_groups
|
||||
|> Enum.map(fn ammo_group ->
|
||||
ammo_group |> get_row_data_for_ammo_group(extra_data)
|
||||
packs
|
||||
|> Enum.map(fn pack ->
|
||||
pack |> get_row_data_for_pack(extra_data)
|
||||
end)
|
||||
|
||||
socket |> assign(columns: columns, rows: rows)
|
||||
@ -134,15 +133,15 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
"""
|
||||
end
|
||||
|
||||
@spec get_row_data_for_ammo_group(AmmoGroup.t(), additional_data :: map()) :: map()
|
||||
defp get_row_data_for_ammo_group(ammo_group, %{columns: columns} = additional_data) do
|
||||
@spec get_row_data_for_pack(Pack.t(), additional_data :: map()) :: map()
|
||||
defp get_row_data_for_pack(pack, %{columns: columns} = additional_data) do
|
||||
columns
|
||||
|> Map.new(fn %{key: key} ->
|
||||
{key, get_value_for_key(key, ammo_group, additional_data)}
|
||||
{key, get_value_for_key(key, pack, additional_data)}
|
||||
end)
|
||||
end
|
||||
|
||||
@spec get_value_for_key(atom(), AmmoGroup.t(), additional_data :: map()) ::
|
||||
@spec get_value_for_key(atom(), Pack.t(), additional_data :: map()) ::
|
||||
any() | {any(), Rendered.t()}
|
||||
defp get_value_for_key(
|
||||
:ammo_type,
|
||||
@ -170,9 +169,9 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
"""}
|
||||
end
|
||||
|
||||
defp get_value_for_key(:used_up_on, %{id: ammo_group_id}, %{last_used_dates: last_used_dates}) do
|
||||
last_used_date = last_used_dates |> Map.get(ammo_group_id)
|
||||
assigns = %{id: ammo_group_id, last_used_date: last_used_date}
|
||||
defp get_value_for_key(:used_up_on, %{id: pack_id}, %{last_used_dates: last_used_dates}) do
|
||||
last_used_date = last_used_dates |> Map.get(pack_id)
|
||||
assigns = %{id: pack_id, last_used_date: last_used_date}
|
||||
|
||||
{last_used_date,
|
||||
~H"""
|
||||
@ -184,29 +183,29 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
"""}
|
||||
end
|
||||
|
||||
defp get_value_for_key(:range, %{staged: staged} = ammo_group, %{range: range}) do
|
||||
assigns = %{range: range, ammo_group: ammo_group}
|
||||
defp get_value_for_key(:range, %{staged: staged} = pack, %{range: range}) do
|
||||
assigns = %{range: range, pack: pack}
|
||||
|
||||
{staged,
|
||||
~H"""
|
||||
<%= render_slot(@range, @ammo_group) %>
|
||||
<%= render_slot(@range, @pack) %>
|
||||
"""}
|
||||
end
|
||||
|
||||
defp get_value_for_key(
|
||||
:remaining,
|
||||
%{id: ammo_group_id},
|
||||
%{id: pack_id},
|
||||
%{percentages_remaining: percentages_remaining}
|
||||
) do
|
||||
percentage = Map.fetch!(percentages_remaining, ammo_group_id)
|
||||
percentage = Map.fetch!(percentages_remaining, pack_id)
|
||||
{percentage, gettext("%{percentage}%", percentage: percentage)}
|
||||
end
|
||||
|
||||
defp get_value_for_key(:actions, ammo_group, %{actions: actions}) do
|
||||
assigns = %{actions: actions, ammo_group: ammo_group}
|
||||
defp get_value_for_key(:actions, pack, %{actions: actions}) do
|
||||
assigns = %{actions: actions, pack: pack}
|
||||
|
||||
~H"""
|
||||
<%= render_slot(@actions, @ammo_group) %>
|
||||
<%= render_slot(@actions, @pack) %>
|
||||
"""
|
||||
end
|
||||
|
||||
@ -214,7 +213,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
|
||||
defp get_value_for_key(
|
||||
:container,
|
||||
%{container_id: container_id} = ammo_group,
|
||||
%{container_id: container_id} = pack,
|
||||
%{container: container_block, containers: containers}
|
||||
) do
|
||||
container = %{name: container_name} = Map.fetch!(containers, container_id)
|
||||
@ -222,35 +221,35 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
|
||||
assigns = %{
|
||||
container: container,
|
||||
container_block: container_block,
|
||||
ammo_group: ammo_group
|
||||
pack: pack
|
||||
}
|
||||
|
||||
{container_name,
|
||||
~H"""
|
||||
<%= render_slot(@container_block, {@ammo_group, @container}) %>
|
||||
<%= render_slot(@container_block, {@pack, @container}) %>
|
||||
"""}
|
||||
end
|
||||
|
||||
defp get_value_for_key(
|
||||
:original_count,
|
||||
%{id: ammo_group_id},
|
||||
%{id: pack_id},
|
||||
%{original_counts: original_counts}
|
||||
) do
|
||||
Map.fetch!(original_counts, ammo_group_id)
|
||||
Map.fetch!(original_counts, pack_id)
|
||||
end
|
||||
|
||||
defp get_value_for_key(:cpr, %{price_paid: nil}, _additional_data),
|
||||
do: {0, gettext("No cost information")}
|
||||
|
||||
defp get_value_for_key(:cpr, %{id: ammo_group_id}, %{cprs: cprs}) do
|
||||
amount = Map.fetch!(cprs, ammo_group_id)
|
||||
defp get_value_for_key(:cpr, %{id: pack_id}, %{cprs: cprs}) do
|
||||
amount = Map.fetch!(cprs, pack_id)
|
||||
{amount, gettext("$%{amount}", amount: display_currency(amount))}
|
||||
end
|
||||
|
||||
defp get_value_for_key(:count, %{count: count}, _additional_data),
|
||||
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)
|
||||
defp get_value_for_key(key, pack, _additional_data), do: pack |> Map.get(key)
|
||||
|
||||
@spec display_currency(float()) :: String.t()
|
||||
defp display_currency(float), do: :erlang.float_to_binary(float, decimals: 2)
|
||||
|
@ -153,7 +153,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
|
||||
|> TableComponent.maybe_compose_columns(%{label: gettext("Name"), key: :name, type: :name})
|
||||
|
||||
round_counts = ammo_types |> Ammo.get_round_count_for_ammo_types(current_user)
|
||||
packs_count = ammo_types |> Ammo.get_ammo_groups_count_for_types(current_user)
|
||||
packs_count = ammo_types |> Ammo.get_packs_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] =
|
||||
@ -161,8 +161,8 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent 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)
|
||||
ammo_types |> Ammo.get_packs_count_for_types(current_user, true),
|
||||
ammo_types |> Ammo.get_used_packs_count_for_types(current_user)
|
||||
]
|
||||
else
|
||||
[nil, nil, nil, nil]
|
||||
|
@ -71,7 +71,7 @@ defmodule CanneryWeb.Components.ContainerTableComponent do
|
||||
current_user: current_user,
|
||||
tag_actions: tag_actions,
|
||||
actions: actions,
|
||||
pack_count: Ammo.get_ammo_groups_count_for_containers(containers, current_user),
|
||||
pack_count: Ammo.get_packs_count_for_containers(containers, current_user),
|
||||
round_count: Ammo.get_round_count_for_containers(containers, current_user)
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ defmodule CanneryWeb.CoreComponents do
|
||||
use Phoenix.Component
|
||||
import CanneryWeb.{Gettext, ViewHelpers}
|
||||
alias Cannery.{Accounts, Accounts.Invite, Accounts.User}
|
||||
alias Cannery.{Ammo, Ammo.AmmoGroup}
|
||||
alias Cannery.{Ammo, Ammo.Pack}
|
||||
alias Cannery.{Containers.Container, Containers.Tag}
|
||||
alias CanneryWeb.{Endpoint, HomeLive}
|
||||
alias CanneryWeb.Router.Helpers, as: Routes
|
||||
@ -86,7 +86,7 @@ defmodule CanneryWeb.CoreComponents do
|
||||
|
||||
def simple_tag_card(assigns)
|
||||
|
||||
attr :ammo_group, AmmoGroup, required: true
|
||||
attr :pack, Pack, required: true
|
||||
attr :current_user, User, required: true
|
||||
attr :original_count, :integer, default: nil
|
||||
attr :cpr, :integer, default: nil
|
||||
|
@ -1,48 +1,45 @@
|
||||
<div
|
||||
id={"ammo_group-#{@ammo_group.id}"}
|
||||
id={"pack-#{@pack.id}"}
|
||||
class="mx-4 my-2 px-8 py-4
|
||||
flex flex-col justify-center items-center
|
||||
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
|
||||
transition-all duration-300 ease-in-out"
|
||||
>
|
||||
<.link navigate={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)} class="mb-2 link">
|
||||
<.link navigate={Routes.pack_show_path(Endpoint, :show, @pack)} class="mb-2 link">
|
||||
<h1 class="title text-xl title-primary-500">
|
||||
<%= @ammo_group.ammo_type.name %>
|
||||
<%= @pack.ammo_type.name %>
|
||||
</h1>
|
||||
</.link>
|
||||
|
||||
<div class="flex flex-col justify-center items-center">
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Count:") %>
|
||||
<%= if @ammo_group.count == 0, do: gettext("Empty"), else: @ammo_group.count %>
|
||||
<%= if @pack.count == 0, do: gettext("Empty"), else: @pack.count %>
|
||||
</span>
|
||||
|
||||
<span
|
||||
:if={@original_count && @original_count != @ammo_group.count}
|
||||
class="rounded-lg title text-lg"
|
||||
>
|
||||
<span :if={@original_count && @original_count != @pack.count} class="rounded-lg title text-lg">
|
||||
<%= gettext("Original Count:") %>
|
||||
<%= @original_count %>
|
||||
</span>
|
||||
|
||||
<span :if={@ammo_group.notes} class="rounded-lg title text-lg">
|
||||
<span :if={@pack.notes} class="rounded-lg title text-lg">
|
||||
<%= gettext("Notes:") %>
|
||||
<%= @ammo_group.notes %>
|
||||
<%= @pack.notes %>
|
||||
</span>
|
||||
|
||||
<span :if={@ammo_group.purchased_on} class="rounded-lg title text-lg">
|
||||
<span :if={@pack.purchased_on} class="rounded-lg title text-lg">
|
||||
<%= gettext("Purchased on:") %>
|
||||
<.date id={"#{@ammo_group.id}-purchased-on"} date={@ammo_group.purchased_on} />
|
||||
<.date id={"#{@pack.id}-purchased-on"} date={@pack.purchased_on} />
|
||||
</span>
|
||||
|
||||
<span :if={@last_used_date} class="rounded-lg title text-lg">
|
||||
<%= gettext("Last used on:") %>
|
||||
<.date id={"#{@ammo_group.id}-last-used-on"} date={@last_used_date} />
|
||||
<.date id={"#{@pack.id}-last-used-on"} date={@last_used_date} />
|
||||
</span>
|
||||
|
||||
<span :if={@ammo_group.price_paid} class="rounded-lg title text-lg">
|
||||
<span :if={@pack.price_paid} class="rounded-lg title text-lg">
|
||||
<%= gettext("Price paid:") %>
|
||||
<%= gettext("$%{amount}", amount: display_currency(@ammo_group.price_paid)) %>
|
||||
<%= gettext("$%{amount}", amount: display_currency(@pack.price_paid)) %>
|
||||
</span>
|
||||
|
||||
<span :if={@cpr} class="rounded-lg title text-lg">
|
||||
|
@ -27,10 +27,10 @@
|
||||
<%= @container.location %>
|
||||
</span>
|
||||
|
||||
<%= if @container |> Ammo.get_ammo_groups_count_for_container!(@current_user) != 0 do %>
|
||||
<%= if @container |> Ammo.get_packs_count_for_container!(@current_user) != 0 do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Packs:") %>
|
||||
<%= @container |> Ammo.get_ammo_groups_count_for_container!(@current_user) %>
|
||||
<%= @container |> Ammo.get_packs_count_for_container!(@current_user) %>
|
||||
</span>
|
||||
|
||||
<span class="rounded-lg title text-lg">
|
||||
|
@ -52,7 +52,7 @@
|
||||
</li>
|
||||
<li class="mx-2 my-1">
|
||||
<.link
|
||||
navigate={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
navigate={Routes.pack_index_path(Endpoint, :index)}
|
||||
class="text-white hover:underline"
|
||||
>
|
||||
<%= gettext("Ammo") %>
|
||||
|
@ -1,10 +1,10 @@
|
||||
defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
|
||||
defmodule CanneryWeb.Components.MovePackComponent do
|
||||
@moduledoc """
|
||||
Livecomponent that can move an ammo group to another container
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, Ammo, Ammo.AmmoGroup, Containers, Containers.Container}
|
||||
alias Cannery.{Accounts.User, Ammo, Ammo.Pack, Containers, Containers.Container}
|
||||
alias CanneryWeb.Endpoint
|
||||
alias Ecto.Changeset
|
||||
alias Phoenix.LiveView.Socket
|
||||
@ -13,17 +13,16 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
|
||||
@spec update(
|
||||
%{
|
||||
required(:current_user) => User.t(),
|
||||
required(:ammo_group) => AmmoGroup.t(),
|
||||
required(:pack) => Pack.t(),
|
||||
optional(any()) => any()
|
||||
},
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(
|
||||
%{ammo_group: %{container_id: container_id} = ammo_group, current_user: current_user} =
|
||||
assigns,
|
||||
%{pack: %{container_id: container_id} = pack, current_user: current_user} = assigns,
|
||||
socket
|
||||
) do
|
||||
changeset = ammo_group |> AmmoGroup.update_changeset(%{}, current_user)
|
||||
changeset = pack |> Pack.update_changeset(%{}, current_user)
|
||||
|
||||
containers =
|
||||
Containers.list_containers(current_user)
|
||||
@ -41,16 +40,15 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
|
||||
def handle_event(
|
||||
"move",
|
||||
%{"container_id" => container_id},
|
||||
%{assigns: %{ammo_group: ammo_group, current_user: current_user, return_to: return_to}} =
|
||||
socket
|
||||
%{assigns: %{pack: pack, current_user: current_user, return_to: return_to}} = socket
|
||||
) do
|
||||
%{name: container_name} = Containers.get_container!(container_id, current_user)
|
||||
|
||||
socket =
|
||||
ammo_group
|
||||
|> Ammo.update_ammo_group(%{"container_id" => container_id}, current_user)
|
||||
pack
|
||||
|> Ammo.update_pack(%{"container_id" => container_id}, current_user)
|
||||
|> case do
|
||||
{:ok, _ammo_group} ->
|
||||
{:ok, _pack} ->
|
||||
prompt = dgettext("prompts", "Ammo moved to %{name} successfully", name: container_name)
|
||||
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
|
||||
|
||||
@ -92,7 +90,7 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
|
||||
<% else %>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.TableComponent}
|
||||
id="move_ammo_group_table"
|
||||
id="move_pack_table"
|
||||
columns={@columns}
|
||||
rows={@rows}
|
||||
/>
|
||||
|
@ -45,12 +45,12 @@ defmodule CanneryWeb.Components.ShotGroupTableComponent do
|
||||
%{label: gettext("Actions"), key: :actions, sortable: false}
|
||||
]
|
||||
|
||||
ammo_groups =
|
||||
packs =
|
||||
shot_groups
|
||||
|> Enum.map(fn %{ammo_group_id: ammo_group_id} -> ammo_group_id end)
|
||||
|> Ammo.get_ammo_groups(current_user)
|
||||
|> Enum.map(fn %{pack_id: pack_id} -> pack_id end)
|
||||
|> Ammo.get_packs(current_user)
|
||||
|
||||
extra_data = %{current_user: current_user, actions: actions, ammo_groups: ammo_groups}
|
||||
extra_data = %{current_user: current_user, actions: actions, packs: packs}
|
||||
|
||||
rows =
|
||||
shot_groups
|
||||
@ -90,13 +90,13 @@ defmodule CanneryWeb.Components.ShotGroupTableComponent do
|
||||
end)
|
||||
end
|
||||
|
||||
defp get_row_value(:name, %{ammo_group_id: ammo_group_id}, %{ammo_groups: ammo_groups}) do
|
||||
assigns = %{ammo_group: ammo_group = Map.fetch!(ammo_groups, ammo_group_id)}
|
||||
defp get_row_value(:name, %{pack_id: pack_id}, %{packs: packs}) do
|
||||
assigns = %{pack: pack = Map.fetch!(packs, pack_id)}
|
||||
|
||||
{ammo_group.ammo_type.name,
|
||||
{pack.ammo_type.name,
|
||||
~H"""
|
||||
<.link navigate={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)} class="link">
|
||||
<%= @ammo_group.ammo_type.name %>
|
||||
<.link navigate={Routes.pack_show_path(Endpoint, :show, @pack)} class="link">
|
||||
<%= @pack.ammo_type.name %>
|
||||
</.link>
|
||||
"""}
|
||||
end
|
||||
|
Reference in New Issue
Block a user