fix tests
This commit is contained in:
parent
9e754fe630
commit
7f9e6f9eff
@ -5,8 +5,8 @@ defmodule Cannery.Ammo do
|
|||||||
|
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
alias Cannery.{Accounts.User, Containers, Repo}
|
alias Cannery.{Accounts.User, Containers, Repo}
|
||||||
alias Cannery.Ammo.{AmmoGroup, AmmoType}
|
|
||||||
alias Cannery.ActivityLog.ShotGroup
|
alias Cannery.ActivityLog.ShotGroup
|
||||||
|
alias Cannery.Ammo.{AmmoGroup, AmmoType}
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
|
|
||||||
@ammo_group_create_limit 10_000
|
@ammo_group_create_limit 10_000
|
||||||
@ -45,8 +45,6 @@ defmodule Cannery.Ammo do
|
|||||||
@doc """
|
@doc """
|
||||||
Gets the average cost of a single ammo type
|
Gets the average cost of a single ammo type
|
||||||
|
|
||||||
Raises `Ecto.NoResultsError` if the Ammo type does not exist.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
iex> get_average_cost_for_ammo_type!(%AmmoType{id: 123}, %User{id: 123})
|
iex> get_average_cost_for_ammo_type!(%AmmoType{id: 123}, %User{id: 123})
|
||||||
|
@ -96,26 +96,28 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp get_ammo_type_values(ammo_type, columns, current_user) do
|
defp get_ammo_type_values(ammo_type, columns, current_user) do
|
||||||
assigns = %{ammo_type: ammo_type}
|
|
||||||
|
|
||||||
columns
|
columns
|
||||||
|> Enum.into(%{}, fn %{key: key, type: type} ->
|
|> Enum.into(%{}, fn %{key: key, type: type} ->
|
||||||
value =
|
{key, get_ammo_type_value(type, key, ammo_type, current_user)}
|
||||||
case type do
|
end)
|
||||||
:boolean ->
|
end
|
||||||
ammo_type |> Map.get(key |> String.to_existing_atom()) |> humanize()
|
|
||||||
|
|
||||||
:round_count ->
|
defp get_ammo_type_value(:boolean, key, ammo_type, _current_user),
|
||||||
ammo_type |> Ammo.get_round_count_for_ammo_type(current_user)
|
do: ammo_type |> Map.get(key |> String.to_existing_atom()) |> humanize()
|
||||||
|
|
||||||
:avg_price_paid ->
|
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(:avg_price_paid, _key, ammo_type, current_user) do
|
||||||
case ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user) do
|
case ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user) do
|
||||||
nil -> gettext("No cost information")
|
nil -> gettext("No cost information")
|
||||||
count -> gettext("$%{amount}", amount: count |> :erlang.float_to_binary(decimals: 2))
|
count -> gettext("$%{amount}", amount: count |> :erlang.float_to_binary(decimals: 2))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_ammo_type_value(:actions, _key, ammo_type, _current_user) do
|
||||||
|
assigns = %{ammo_type: ammo_type}
|
||||||
|
|
||||||
:actions ->
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
|
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
|
||||||
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
|
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
|
||||||
@ -142,15 +144,10 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
nil ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
_other ->
|
|
||||||
ammo_type |> Map.get(key |> String.to_existing_atom())
|
|
||||||
end
|
end
|
||||||
|
|
||||||
{key, value}
|
defp get_ammo_type_value(nil, _key, _ammo_type, _current_user), do: nil
|
||||||
end)
|
|
||||||
end
|
defp get_ammo_type_value(_other, key, ammo_type, _current_user),
|
||||||
|
do: ammo_type |> Map.get(key |> String.to_existing_atom())
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user