Compare commits

..

No commits in common. "52c4ab45d510e09516845f981b72b94e91e212c7" and "9306d0f970d5b86a66cb45a79981bfc0baea17c8" have entirely different histories.

45 changed files with 1010 additions and 1033 deletions

View File

@ -1,7 +1,3 @@
# v0.9.4
- Code quality fixes
- Fix error/404 pages not rendering properly
# v0.9.3 # v0.9.3
- Update dependencies - Update dependencies
- Add pack lot number to search - Add pack lot number to search

View File

@ -18,10 +18,7 @@ config :cannery, CanneryWeb.Endpoint,
url: [scheme: "https", host: System.get_env("HOST") || "localhost", port: "443"], url: [scheme: "https", host: System.get_env("HOST") || "localhost", port: "443"],
http: [port: String.to_integer(System.get_env("PORT") || "4000")], http: [port: String.to_integer(System.get_env("PORT") || "4000")],
secret_key_base: "KH59P0iZixX5gP/u+zkxxG8vAAj6vgt0YqnwEB5JP5K+E567SsqkCz69uWShjE7I", secret_key_base: "KH59P0iZixX5gP/u+zkxxG8vAAj6vgt0YqnwEB5JP5K+E567SsqkCz69uWShjE7I",
render_errors: [ render_errors: [view: CanneryWeb.ErrorView, accepts: ~w(html json), layout: false],
formats: [html: CanneryWeb.ErrorHTML, json: CanneryWeb.ErrorJSON],
layout: false
],
pubsub_server: Cannery.PubSub, pubsub_server: Cannery.PubSub,
live_view: [signing_salt: "zOLgd3lr"] live_view: [signing_salt: "zOLgd3lr"]

View File

@ -8,49 +8,38 @@ defmodule Cannery.ActivityLog do
alias Cannery.{Accounts.User, ActivityLog.ShotRecord, Repo} alias Cannery.{Accounts.User, ActivityLog.ShotRecord, Repo}
alias Ecto.{Multi, Queryable} alias Ecto.{Multi, Queryable}
@type list_shot_records_option ::
{:search, String.t() | nil}
| {:class, Type.class() | :all | nil}
| {:pack_id, Pack.id() | nil}
@type list_shot_records_options :: [list_shot_records_option()]
@doc """ @doc """
Returns the list of shot_records. Returns the list of shot_records.
## Examples ## Examples
iex> list_shot_records(%User{id: 123}) iex> list_shot_records(:all, %User{id: 123})
[%ShotRecord{}, ...] [%ShotRecord{}, ...]
iex> list_shot_records(%User{id: 123}, search: "cool") iex> list_shot_records("cool", :all, %User{id: 123})
[%ShotRecord{notes: "My cool shot record"}, ...] [%ShotRecord{notes: "My cool shot record"}, ...]
iex> list_shot_records(%User{id: 123}, search: "cool", class: :rifle) iex> list_shot_records("cool", :rifle, %User{id: 123})
[%ShotRecord{notes: "Shot some rifle rounds"}, ...] [%ShotRecord{notes: "Shot some rifle rounds"}, ...]
iex> list_shot_records(%User{id: 123}, pack_id: 456)
[%ShotRecord{pack_id: 456}, ...]
""" """
@spec list_shot_records(User.t()) :: [ShotRecord.t()] @spec list_shot_records(Type.class() | :all, User.t()) :: [ShotRecord.t()]
@spec list_shot_records(User.t(), list_shot_records_options()) :: [ShotRecord.t()] @spec list_shot_records(search :: nil | String.t(), Type.class() | :all, User.t()) ::
def list_shot_records(%User{id: user_id}, opts \\ []) do [ShotRecord.t()]
from(sr in ShotRecord, def list_shot_records(search \\ nil, type, %{id: user_id}) do
as: :sr, from(sg in ShotRecord,
left_join: p in Pack, as: :sg,
as: :p, left_join: ag in Pack,
on: sr.pack_id == p.id, as: :ag,
on: p.user_id == ^user_id, on: sg.pack_id == ag.id,
left_join: t in Type, left_join: at in Type,
as: :t, as: :at,
on: p.type_id == t.id, on: ag.type_id == at.id,
on: t.user_id == ^user_id, where: sg.user_id == ^user_id,
where: sr.user_id == ^user_id, distinct: sg.id
distinct: sr.id
) )
|> list_shot_records_search(Keyword.get(opts, :search)) |> list_shot_records_search(search)
|> list_shot_records_class(Keyword.get(opts, :class)) |> list_shot_records_filter_type(type)
|> list_shot_records_pack_id(Keyword.get(opts, :pack_id))
|> Repo.all() |> Repo.all()
end end
@ -63,44 +52,45 @@ defmodule Cannery.ActivityLog do
query query
|> where( |> where(
[sr: sr, p: p, t: t], [sg: sg, ag: ag, at: at],
fragment( fragment(
"? @@ websearch_to_tsquery('english', ?)", "? @@ websearch_to_tsquery('english', ?)",
sr.search, sg.search,
^trimmed_search ^trimmed_search
) or ) or
fragment( fragment(
"? @@ websearch_to_tsquery('english', ?)", "? @@ websearch_to_tsquery('english', ?)",
p.search, ag.search,
^trimmed_search ^trimmed_search
) or ) or
fragment( fragment(
"? @@ websearch_to_tsquery('english', ?)", "? @@ websearch_to_tsquery('english', ?)",
t.search, at.search,
^trimmed_search ^trimmed_search
) )
) )
|> order_by([sr: sr], { |> order_by([sg: sg], {
:desc, :desc,
fragment( fragment(
"ts_rank_cd(?, websearch_to_tsquery('english', ?), 4)", "ts_rank_cd(?, websearch_to_tsquery('english', ?), 4)",
sr.search, sg.search,
^trimmed_search ^trimmed_search
) )
}) })
end end
@spec list_shot_records_class(Queryable.t(), Type.class() | :all | nil) :: Queryable.t() @spec list_shot_records_filter_type(Queryable.t(), Type.class() | :all) ::
defp list_shot_records_class(query, class) when class in [:rifle, :pistol, :shotgun], Queryable.t()
do: query |> where([t: t], t.class == ^class) defp list_shot_records_filter_type(query, :rifle),
do: query |> where([at: at], at.class == :rifle)
defp list_shot_records_class(query, _all), do: query defp list_shot_records_filter_type(query, :pistol),
do: query |> where([at: at], at.class == :pistol)
@spec list_shot_records_pack_id(Queryable.t(), Pack.id() | nil) :: Queryable.t() defp list_shot_records_filter_type(query, :shotgun),
defp list_shot_records_pack_id(query, pack_id) when pack_id |> is_binary(), do: query |> where([at: at], at.class == :shotgun)
do: query |> where([sr: sr], sr.pack_id == ^pack_id)
defp list_shot_records_pack_id(query, _all), do: query defp list_shot_records_filter_type(query, _all), do: query
@doc """ @doc """
Returns a count of shot records. Returns a count of shot records.
@ -114,13 +104,25 @@ defmodule Cannery.ActivityLog do
@spec get_shot_record_count!(User.t()) :: integer() @spec get_shot_record_count!(User.t()) :: integer()
def get_shot_record_count!(%User{id: user_id}) do def get_shot_record_count!(%User{id: user_id}) do
Repo.one( Repo.one(
from sr in ShotRecord, from sg in ShotRecord,
where: sr.user_id == ^user_id, where: sg.user_id == ^user_id,
select: count(sr.id), select: count(sg.id),
distinct: true distinct: true
) || 0 ) || 0
end end
@spec list_shot_records_for_pack(Pack.t(), User.t()) :: [ShotRecord.t()]
def list_shot_records_for_pack(
%Pack{id: pack_id, user_id: user_id},
%User{id: user_id}
) do
Repo.all(
from sg in ShotRecord,
where: sg.pack_id == ^pack_id,
where: sg.user_id == ^user_id
)
end
@doc """ @doc """
Gets a single shot_record. Gets a single shot_record.
@ -138,10 +140,10 @@ defmodule Cannery.ActivityLog do
@spec get_shot_record!(ShotRecord.id(), User.t()) :: ShotRecord.t() @spec get_shot_record!(ShotRecord.id(), User.t()) :: ShotRecord.t()
def get_shot_record!(id, %User{id: user_id}) do def get_shot_record!(id, %User{id: user_id}) do
Repo.one!( Repo.one!(
from sr in ShotRecord, from sg in ShotRecord,
where: sr.id == ^id, where: sg.id == ^id,
where: sr.user_id == ^user_id, where: sg.user_id == ^user_id,
order_by: sr.date order_by: sg.date
) )
end end
@ -170,9 +172,9 @@ defmodule Cannery.ActivityLog do
fn _repo, %{create_shot_record: %{pack_id: pack_id, user_id: user_id}} -> fn _repo, %{create_shot_record: %{pack_id: pack_id, user_id: user_id}} ->
pack = pack =
Repo.one( Repo.one(
from p in Pack, from ag in Pack,
where: p.id == ^pack_id, where: ag.id == ^pack_id,
where: p.user_id == ^user_id where: ag.user_id == ^user_id
) )
{:ok, pack} {:ok, pack}
@ -219,7 +221,7 @@ defmodule Cannery.ActivityLog do
|> Multi.run( |> Multi.run(
:pack, :pack,
fn repo, %{update_shot_record: %{pack_id: pack_id, user_id: user_id}} -> fn repo, %{update_shot_record: %{pack_id: pack_id, user_id: user_id}} ->
{:ok, repo.one(from p in Pack, where: p.id == ^pack_id and p.user_id == ^user_id)} {:ok, repo.one(from ag in Pack, where: ag.id == ^pack_id and ag.user_id == ^user_id)}
end end
) )
|> Multi.update( |> Multi.update(
@ -264,7 +266,7 @@ defmodule Cannery.ActivityLog do
|> Multi.run( |> Multi.run(
:pack, :pack,
fn repo, %{delete_shot_record: %{pack_id: pack_id, user_id: user_id}} -> fn repo, %{delete_shot_record: %{pack_id: pack_id, user_id: user_id}} ->
{:ok, repo.one(from p in Pack, where: p.id == ^pack_id and p.user_id == ^user_id)} {:ok, repo.one(from ag in Pack, where: ag.id == ^pack_id and ag.user_id == ^user_id)}
end end
) )
|> Multi.update( |> Multi.update(
@ -285,6 +287,36 @@ defmodule Cannery.ActivityLog do
end end
end end
@doc """
Returns the number of shot rounds for a pack
"""
@spec get_used_count(Pack.t(), User.t()) :: non_neg_integer()
def get_used_count(%Pack{id: pack_id} = pack, user) do
[pack]
|> get_used_counts(user)
|> Map.get(pack_id, 0)
end
@doc """
Returns the number of shot rounds for multiple packs
"""
@spec get_used_counts([Pack.t()], User.t()) ::
%{optional(Pack.id()) => non_neg_integer()}
def get_used_counts(packs, %User{id: user_id}) do
pack_ids =
packs
|> Enum.map(fn %{id: pack_id} -> pack_id end)
Repo.all(
from sg in ShotRecord,
where: sg.pack_id in ^pack_ids,
where: sg.user_id == ^user_id,
group_by: sg.pack_id,
select: {sg.pack_id, sum(sg.count)}
)
|> Map.new()
end
@doc """ @doc """
Returns the last entered shot record date for a pack Returns the last entered shot record date for a pack
""" """
@ -305,18 +337,15 @@ defmodule Cannery.ActivityLog do
|> Enum.map(fn %Pack{id: pack_id, user_id: ^user_id} -> pack_id end) |> Enum.map(fn %Pack{id: pack_id, user_id: ^user_id} -> pack_id end)
Repo.all( Repo.all(
from sr in ShotRecord, from sg in ShotRecord,
where: sr.pack_id in ^pack_ids, where: sg.pack_id in ^pack_ids,
where: sr.user_id == ^user_id, where: sg.user_id == ^user_id,
group_by: sr.pack_id, group_by: sg.pack_id,
select: {sr.pack_id, max(sr.date)} select: {sg.pack_id, max(sg.date)}
) )
|> Map.new() |> Map.new()
end end
@type get_used_count_option :: {:pack_id, Pack.id() | nil} | {:type_id, Type.id() | nil}
@type get_used_count_options :: [get_used_count_option()]
@doc """ @doc """
Gets the total number of rounds shot for a type Gets the total number of rounds shot for a type
@ -324,116 +353,45 @@ defmodule Cannery.ActivityLog do
## Examples ## Examples
iex> get_used_count(%User{id: 123}, type_id: 123) iex> get_used_count_for_type(123, %User{id: 123})
35 35
iex> get_used_count(%User{id: 123}, pack_id: 456) iex> get_used_count_for_type(456, %User{id: 123})
50 ** (Ecto.NoResultsError)
""" """
@spec get_used_count(User.t(), get_used_count_options()) :: non_neg_integer() @spec get_used_count_for_type(Type.t(), User.t()) :: non_neg_integer()
def get_used_count(%User{id: user_id}, opts) do def get_used_count_for_type(%Type{id: type_id} = type, user) do
from(sr in ShotRecord, [type]
as: :sr, |> get_used_count_for_types(user)
left_join: p in Pack, |> Map.get(type_id, 0)
on: sr.pack_id == p.id,
on: p.user_id == ^user_id,
as: :p,
where: sr.user_id == ^user_id,
where: not (sr.count |> is_nil()),
select: sum(sr.count),
distinct: true
)
|> get_used_count_type_id(Keyword.get(opts, :type_id))
|> get_used_count_pack_id(Keyword.get(opts, :pack_id))
|> Repo.one() || 0
end end
@spec get_used_count_pack_id(Queryable.t(), Pack.id() | nil) :: Queryable.t()
defp get_used_count_pack_id(query, pack_id) when pack_id |> is_binary() do
query |> where([sr: sr], sr.pack_id == ^pack_id)
end
defp get_used_count_pack_id(query, _nil), do: query
@spec get_used_count_type_id(Queryable.t(), Type.id() | nil) :: Queryable.t()
defp get_used_count_type_id(query, type_id) when type_id |> is_binary() do
query |> where([p: p], p.type_id == ^type_id)
end
defp get_used_count_type_id(query, _nil), do: query
@type get_grouped_used_counts_option ::
{:packs, [Pack.t()] | nil}
| {:types, [Type.t()] | nil}
| {:group_by, :type_id | :pack_id}
@type get_grouped_used_counts_options :: [get_grouped_used_counts_option()]
@doc """ @doc """
Gets the total number of rounds shot for multiple types or packs Gets the total number of rounds shot for multiple types
## Examples ## Examples
iex> get_grouped_used_counts( iex> get_used_count_for_types(123, %User{id: 123})
...> %User{id: 123},
...> group_by: :type_id,
...> types: [%Type{id: 456, user_id: 123}]
...> )
35 35
iex> get_grouped_used_counts(
...> %User{id: 123},
...> group_by: :pack_id,
...> packs: [%Pack{id: 456, user_id: 123}]
...> )
22
""" """
@spec get_grouped_used_counts(User.t(), get_grouped_used_counts_options()) :: @spec get_used_count_for_types([Type.t()], User.t()) ::
%{optional(Type.id() | Pack.id()) => non_neg_integer()} %{optional(Type.id()) => non_neg_integer()}
def get_grouped_used_counts(%User{id: user_id}, opts) do def get_used_count_for_types(types, %User{id: user_id}) do
from(p in Pack, type_ids =
as: :p, types
left_join: sr in ShotRecord, |> Enum.map(fn %Type{id: type_id, user_id: ^user_id} -> type_id end)
on: p.id == sr.pack_id,
on: p.user_id == ^user_id, Repo.all(
as: :sr, from ag in Pack,
where: sr.user_id == ^user_id, left_join: sg in ShotRecord,
where: not (sr.count |> is_nil()) on: ag.id == sg.pack_id,
where: ag.type_id in ^type_ids,
where: not (sg.count |> is_nil()),
group_by: ag.type_id,
select: {ag.type_id, sum(sg.count)}
) )
|> get_grouped_used_counts_group_by(Keyword.fetch!(opts, :group_by))
|> get_grouped_used_counts_types(Keyword.get(opts, :types))
|> get_grouped_used_counts_packs(Keyword.get(opts, :packs))
|> Repo.all()
|> Map.new() |> Map.new()
end end
@spec get_grouped_used_counts_group_by(Queryable.t(), :type_id | :pack_id) :: Queryable.t()
defp get_grouped_used_counts_group_by(query, :type_id) do
query
|> group_by([p: p], p.type_id)
|> select([sr: sr, p: p], {p.type_id, sum(sr.count)})
end
defp get_grouped_used_counts_group_by(query, :pack_id) do
query
|> group_by([sr: sr], sr.pack_id)
|> select([sr: sr], {sr.pack_id, sum(sr.count)})
end
@spec get_grouped_used_counts_types(Queryable.t(), [Type.t()] | nil) :: Queryable.t()
defp get_grouped_used_counts_types(query, types) when types |> is_list() do
type_ids = types |> Enum.map(fn %Type{id: type_id} -> type_id end)
query |> where([p: p], p.type_id in ^type_ids)
end
defp get_grouped_used_counts_types(query, _nil), do: query
@spec get_grouped_used_counts_packs(Queryable.t(), [Pack.t()] | nil) :: Queryable.t()
defp get_grouped_used_counts_packs(query, packs) when packs |> is_list() do
pack_ids = packs |> Enum.map(fn %Pack{id: pack_id} -> pack_id end)
query |> where([p: p], p.id in ^pack_ids)
end
defp get_grouped_used_counts_packs(query, _nil), do: query
end end

File diff suppressed because it is too large Load Diff

View File

@ -7,13 +7,10 @@ defmodule Cannery.Containers do
import Ecto.Query, warn: false import Ecto.Query, warn: false
alias Cannery.{Accounts.User, Ammo.Pack, Repo} alias Cannery.{Accounts.User, Ammo.Pack, Repo}
alias Cannery.Containers.{Container, ContainerTag, Tag} alias Cannery.Containers.{Container, ContainerTag, Tag}
alias Ecto.{Changeset, Queryable} alias Ecto.Changeset
@container_preloads [:tags] @container_preloads [:tags]
@type list_containers_option :: {:search, String.t() | nil}
@type list_containers_options :: [list_containers_option()]
@doc """ @doc """
Returns the list of containers. Returns the list of containers.
@ -22,31 +19,30 @@ defmodule Cannery.Containers do
iex> list_containers(%User{id: 123}) iex> list_containers(%User{id: 123})
[%Container{}, ...] [%Container{}, ...]
iex> list_containers(%User{id: 123}, search: "cool") iex> list_containers("cool", %User{id: 123})
[%Container{name: "my cool container"}, ...] [%Container{name: "my cool container"}, ...]
""" """
@spec list_containers(User.t()) :: [Container.t()] @spec list_containers(User.t()) :: [Container.t()]
@spec list_containers(User.t(), list_containers_options()) :: [Container.t()] @spec list_containers(search :: nil | String.t(), User.t()) :: [Container.t()]
def list_containers(%User{id: user_id}, opts \\ []) do def list_containers(search \\ nil, %User{id: user_id}) do
from(c in Container, from(c in Container,
as: :c, as: :c,
left_join: t in assoc(c, :tags), left_join: t in assoc(c, :tags),
on: c.user_id == t.user_id,
as: :t, as: :t,
where: c.user_id == ^user_id, where: c.user_id == ^user_id,
order_by: c.name,
distinct: c.id, distinct: c.id,
preload: ^@container_preloads preload: ^@container_preloads
) )
|> list_containers_search(Keyword.get(opts, :search)) |> list_containers_search(search)
|> Repo.all() |> Repo.all()
end end
@spec list_containers_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t() defp list_containers_search(query, nil), do: query
defp list_containers_search(query, search) when search in ["", nil], defp list_containers_search(query, ""), do: query
do: query |> order_by([c: c], c.name)
defp list_containers_search(query, search) when search |> is_binary() do defp list_containers_search(query, search) do
trimmed_search = String.trim(search) trimmed_search = String.trim(search)
query query
@ -207,9 +203,9 @@ defmodule Cannery.Containers do
{:ok, Container.t()} | {:error, Container.changeset()} {:ok, Container.t()} | {:error, Container.changeset()}
def delete_container(%Container{user_id: user_id} = container, %User{id: user_id}) do def delete_container(%Container{user_id: user_id} = container, %User{id: user_id}) do
Repo.one( Repo.one(
from p in Pack, from ag in Pack,
where: p.container_id == ^container.id, where: ag.container_id == ^container.id,
select: count(p.id) select: count(ag.id)
) )
|> case do |> case do
0 -> 0 ->
@ -293,9 +289,6 @@ defmodule Cannery.Containers do
# Container Tags # Container Tags
@type list_tags_option :: {:search, String.t() | nil}
@type list_tags_options :: [list_tags_option()]
@doc """ @doc """
Returns the list of tags. Returns the list of tags.
@ -304,42 +297,38 @@ defmodule Cannery.Containers do
iex> list_tags(%User{id: 123}) iex> list_tags(%User{id: 123})
[%Tag{}, ...] [%Tag{}, ...]
iex> list_tags(%User{id: 123}, search: "cool") iex> list_tags("cool", %User{id: 123})
[%Tag{name: "my cool tag"}, ...] [%Tag{name: "my cool tag"}, ...]
""" """
@spec list_tags(User.t()) :: [Tag.t()] @spec list_tags(User.t()) :: [Tag.t()]
@spec list_tags(User.t(), list_tags_options()) :: [Tag.t()] @spec list_tags(search :: nil | String.t(), User.t()) :: [Tag.t()]
def list_tags(%User{id: user_id}, opts \\ []) do def list_tags(search \\ nil, user)
from(t in Tag, as: :t, where: t.user_id == ^user_id)
|> list_tags_search(Keyword.get(opts, :search))
|> Repo.all()
end
@spec list_tags_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t() def list_tags(search, %{id: user_id}) when search |> is_nil() or search == "",
defp list_tags_search(query, search) when search in ["", nil], do: Repo.all(from t in Tag, where: t.user_id == ^user_id, order_by: t.name)
do: query |> order_by([t: t], t.name)
defp list_tags_search(query, search) when search |> is_binary() do def list_tags(search, %{id: user_id}) when search |> is_binary() do
trimmed_search = String.trim(search) trimmed_search = String.trim(search)
query Repo.all(
|> where( from t in Tag,
[t: t], where: t.user_id == ^user_id,
where:
fragment( fragment(
"? @@ websearch_to_tsquery('english', ?)", "? @@ websearch_to_tsquery('english', ?)",
t.search, t.search,
^trimmed_search ^trimmed_search
) ),
) order_by: {
|> order_by([t: t], {
:desc, :desc,
fragment( fragment(
"ts_rank_cd(?, websearch_to_tsquery('english', ?), 4)", "ts_rank_cd(?, websearch_to_tsquery('english', ?), 4)",
t.search, t.search,
^trimmed_search ^trimmed_search
) )
}) }
)
end end
@doc """ @doc """

View File

@ -71,10 +71,8 @@ defmodule CanneryWeb.Components.ContainerTableComponent do
current_user: current_user, current_user: current_user,
tag_actions: tag_actions, tag_actions: tag_actions,
actions: actions, actions: actions,
pack_count: pack_count: Ammo.get_packs_count_for_containers(containers, current_user),
Ammo.get_grouped_packs_count(current_user, containers: containers, group_by: :container_id), round_count: Ammo.get_round_count_for_containers(containers, current_user)
round_count:
Ammo.get_grouped_round_count(current_user, containers: containers, group_by: :container_id)
} }
rows = rows =

View File

@ -27,15 +27,15 @@
<%= @container.location %> <%= @container.location %>
</span> </span>
<%= if Ammo.get_packs_count(@current_user, container_id: @container.id) != 0 do %> <%= if @container |> Ammo.get_packs_count_for_container!(@current_user) != 0 do %>
<span class="rounded-lg title text-lg"> <span class="rounded-lg title text-lg">
<%= gettext("Packs:") %> <%= gettext("Packs:") %>
<%= Ammo.get_packs_count(@current_user, container_id: @container.id) %> <%= @container |> Ammo.get_packs_count_for_container!(@current_user) %>
</span> </span>
<span class="rounded-lg title text-lg"> <span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %> <%= gettext("Rounds:") %>
<%= Ammo.get_round_count(@current_user, container_id: @container.id) %> <%= @container |> Ammo.get_round_count_for_container!(@current_user) %>
</span> </span>
<% end %> <% end %>

View File

@ -89,7 +89,7 @@ defmodule CanneryWeb.Components.MovePackComponent do
<% else %> <% else %>
<.live_component <.live_component
module={CanneryWeb.Components.TableComponent} module={CanneryWeb.Components.TableComponent}
id="move-pack-table" id="move_pack_table"
columns={@columns} columns={@columns}
rows={@rows} rows={@rows}
/> />

View File

@ -141,12 +141,7 @@ defmodule CanneryWeb.Components.PackTableComponent do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div id={@id} class="w-full"> <div id={@id} class="w-full">
<.live_component <.live_component module={TableComponent} id={"table-#{@id}"} columns={@columns} rows={@rows} />
module={TableComponent}
id={"pack-table-#{@id}"}
columns={@columns}
rows={@rows}
/>
</div> </div>
""" """
end end

View File

@ -74,7 +74,7 @@ defmodule CanneryWeb.Components.ShotRecordTableComponent do
<div id={@id} class="w-full"> <div id={@id} class="w-full">
<.live_component <.live_component
module={CanneryWeb.Components.TableComponent} module={CanneryWeb.Components.TableComponent}
id={"shot-record-table-#{@id}"} id={"table-#{@id}"}
columns={@columns} columns={@columns}
rows={@rows} rows={@rows}
initial_key={:date} initial_key={:date}

View File

@ -151,25 +151,17 @@ defmodule CanneryWeb.Components.TypeTableComponent do
) )
|> TableComponent.maybe_compose_columns(%{label: gettext("Name"), key: :name, type: :name}) |> TableComponent.maybe_compose_columns(%{label: gettext("Name"), key: :name, type: :name})
round_counts = Ammo.get_grouped_round_count(current_user, types: types, group_by: :type_id) round_counts = types |> Ammo.get_round_count_for_types(current_user)
packs_count = Ammo.get_grouped_packs_count(current_user, types: types, group_by: :type_id) packs_count = types |> Ammo.get_packs_count_for_types(current_user)
average_costs = Ammo.get_average_costs(types, current_user) average_costs = types |> Ammo.get_average_cost_for_types(current_user)
[used_counts, historical_round_counts, historical_pack_counts, used_pack_counts] = [used_counts, historical_round_counts, historical_pack_counts, used_pack_counts] =
if show_used do if show_used do
[ [
ActivityLog.get_grouped_used_counts(current_user, types: types, group_by: :type_id), types |> ActivityLog.get_used_count_for_types(current_user),
Ammo.get_historical_counts(types, current_user), types |> Ammo.get_historical_count_for_types(current_user),
Ammo.get_grouped_packs_count(current_user, types |> Ammo.get_packs_count_for_types(current_user, true),
types: types, types |> Ammo.get_used_packs_count_for_types(current_user)
group_by: :type_id,
show_used: true
),
Ammo.get_grouped_packs_count(current_user,
types: types,
group_by: :type_id,
show_used: :only_used
)
] ]
else else
[nil, nil, nil, nil] [nil, nil, nil, nil]
@ -200,12 +192,7 @@ defmodule CanneryWeb.Components.TypeTableComponent do
def render(assigns) do def render(assigns) do
~H""" ~H"""
<div id={@id} class="w-full"> <div id={@id} class="w-full">
<.live_component <.live_component module={TableComponent} id={"table-#{@id}"} columns={@columns} rows={@rows} />
module={TableComponent}
id={"type-table-#{@id}"}
columns={@columns}
rows={@rows}
/>
</div> </div>
""" """
end end

View File

@ -3,18 +3,14 @@ defmodule CanneryWeb.ExportController do
alias Cannery.{ActivityLog, Ammo, Containers} alias Cannery.{ActivityLog, Ammo, Containers}
def export(%{assigns: %{current_user: current_user}} = conn, %{"mode" => "json"}) do def export(%{assigns: %{current_user: current_user}} = conn, %{"mode" => "json"}) do
types = Ammo.list_types(current_user) types = Ammo.list_types(current_user, :all)
used_counts = types |> ActivityLog.get_used_count_for_types(current_user)
round_counts = types |> Ammo.get_round_count_for_types(current_user)
pack_counts = types |> Ammo.get_packs_count_for_types(current_user)
used_counts = total_pack_counts = types |> Ammo.get_packs_count_for_types(current_user, true)
ActivityLog.get_grouped_used_counts(current_user, types: types, group_by: :type_id)
round_counts = Ammo.get_grouped_round_count(current_user, types: types, group_by: :type_id) average_costs = types |> Ammo.get_average_cost_for_types(current_user)
pack_counts = Ammo.get_grouped_packs_count(current_user, types: types, group_by: :type_id)
total_pack_counts =
Ammo.get_grouped_packs_count(current_user, types: types, group_by: :type_id, show_used: true)
average_costs = Ammo.get_average_costs(types, current_user)
types = types =
types types
@ -31,11 +27,8 @@ defmodule CanneryWeb.ExportController do
}) })
end) end)
packs = Ammo.list_packs(current_user, show_used: true) packs = Ammo.list_packs(nil, :all, current_user, true)
used_counts = packs |> ActivityLog.get_used_counts(current_user)
used_counts =
ActivityLog.get_grouped_used_counts(current_user, packs: packs, group_by: :pack_id)
original_counts = packs |> Ammo.get_original_counts(current_user) original_counts = packs |> Ammo.get_original_counts(current_user)
cprs = packs |> Ammo.get_cprs(current_user) cprs = packs |> Ammo.get_cprs(current_user)
percentages_remaining = packs |> Ammo.get_percentages_remaining(current_user) percentages_remaining = packs |> Ammo.get_percentages_remaining(current_user)
@ -54,17 +47,20 @@ defmodule CanneryWeb.ExportController do
}) })
end) end)
shot_records = ActivityLog.list_shot_records(current_user) shot_records = ActivityLog.list_shot_records(:all, current_user)
containers = containers =
Containers.list_containers(current_user) Containers.list_containers(current_user)
|> Enum.map(fn container -> |> Enum.map(fn container ->
pack_count = container |> Ammo.get_packs_count_for_container!(current_user)
round_count = container |> Ammo.get_round_count_for_container!(current_user)
container container
|> Jason.encode!() |> Jason.encode!()
|> Jason.decode!() |> Jason.decode!()
|> Map.merge(%{ |> Map.merge(%{
"pack_count" => Ammo.get_packs_count(current_user, container_id: container.id), "pack_count" => pack_count,
"round_count" => Ammo.get_round_count(current_user, container_id: container.id) "round_count" => round_count
}) })
end) end)

View File

@ -71,7 +71,7 @@ defmodule CanneryWeb.UserRegistrationController do
|> redirect(to: ~p"/") |> redirect(to: ~p"/")
{:error, %Changeset{} = changeset} -> {:error, %Changeset{} = changeset} ->
conn |> render(:new, changeset: changeset, invite_token: invite_token) conn |> render("new.html", changeset: changeset, invite_token: invite_token)
end end
end end
end end

View File

@ -113,6 +113,6 @@ defmodule CanneryWeb.ContainerLive.Index do
end end
defp display_containers(%{assigns: %{search: search, current_user: current_user}} = socket) do defp display_containers(%{assigns: %{search: search, current_user: current_user}} = socket) do
socket |> assign(:containers, Containers.list_containers(current_user, search: search)) socket |> assign(:containers, Containers.list_containers(search, current_user))
end end
end end

View File

@ -51,7 +51,7 @@
<%= if @view_table do %> <%= if @view_table do %>
<.live_component <.live_component
module={CanneryWeb.Components.ContainerTableComponent} module={CanneryWeb.Components.ContainerTableComponent}
id="containers-index-table" id="containers_index_table"
action={@live_action} action={@live_action}
containers={@containers} containers={@containers}
current_user={@current_user} current_user={@current_user}

View File

@ -104,10 +104,8 @@ defmodule CanneryWeb.ContainerLive.Show do
id, id,
current_user current_user
) do ) do
%{id: container_id, name: container_name} = %{name: container_name} = container = Containers.get_container!(id, current_user)
container = Containers.get_container!(id, current_user) packs = Ammo.list_packs_for_container(container, class, current_user)
packs = Ammo.list_packs(current_user, container_id: container_id, class: class)
original_counts = packs |> Ammo.get_original_counts(current_user) original_counts = packs |> Ammo.get_original_counts(current_user)
cprs = packs |> Ammo.get_cprs(current_user) cprs = packs |> Ammo.get_cprs(current_user)
last_used_dates = packs |> ActivityLog.get_last_used_dates(current_user) last_used_dates = packs |> ActivityLog.get_last_used_dates(current_user)
@ -122,8 +120,8 @@ defmodule CanneryWeb.ContainerLive.Show do
socket socket
|> assign( |> assign(
container: container, container: container,
round_count: Ammo.get_round_count(current_user, container_id: container.id), round_count: Ammo.get_round_count_for_container!(container, current_user),
packs_count: Ammo.get_packs_count(current_user, container_id: container.id), packs_count: Ammo.get_packs_count_for_container!(container, current_user),
packs: packs, packs: packs,
original_counts: original_counts, original_counts: original_counts,
cprs: cprs, cprs: cprs,

View File

@ -120,7 +120,7 @@
<%= if @view_table do %> <%= if @view_table do %>
<.live_component <.live_component
module={CanneryWeb.Components.PackTableComponent} module={CanneryWeb.Components.PackTableComponent}
id="pack-show-table" id="type-show-table"
packs={@packs} packs={@packs}
current_user={@current_user} current_user={@current_user}
show_used={false} show_used={false}

View File

@ -26,7 +26,7 @@ defmodule CanneryWeb.PackLive.FormComponent do
socket = socket =
socket socket
|> assign(:pack_create_limit, @pack_create_limit) |> assign(:pack_create_limit, @pack_create_limit)
|> assign(:types, Ammo.list_types(current_user)) |> assign(:types, Ammo.list_types(current_user, :all))
|> assign_new(:containers, fn -> Containers.list_containers(current_user) end) |> assign_new(:containers, fn -> Containers.list_containers(current_user) end)
params = params =

View File

@ -148,8 +148,8 @@ defmodule CanneryWeb.PackLive.Index do
) do ) do
# get total number of packs to determine whether to display onboarding # get total number of packs to determine whether to display onboarding
# prompts # prompts
packs_count = Ammo.get_packs_count(current_user, show_used: true) packs_count = Ammo.get_packs_count!(current_user, true)
packs = Ammo.list_packs(current_user, search: search, class: class, show_used: show_used) packs = Ammo.list_packs(search, class, current_user, show_used)
types_count = Ammo.get_types_count!(current_user) types_count = Ammo.get_types_count!(current_user)
containers_count = Containers.get_containers_count!(current_user) containers_count = Containers.get_containers_count!(current_user)

View File

@ -92,7 +92,7 @@ defmodule CanneryWeb.PackLive.Show do
%{label: gettext("Actions"), key: :actions, sortable: false} %{label: gettext("Actions"), key: :actions, sortable: false}
] ]
shot_records = ActivityLog.list_shot_records(current_user, pack_id: pack.id) shot_records = ActivityLog.list_shot_records_for_pack(pack, current_user)
rows = rows =
shot_records shot_records

View File

@ -115,7 +115,7 @@
<.live_component <.live_component
module={CanneryWeb.Components.TableComponent} module={CanneryWeb.Components.TableComponent}
id="pack-shot-records-table" id="pack_shot_records_table"
columns={@columns} columns={@columns}
rows={@rows} rows={@rows}
/> />

View File

@ -120,8 +120,8 @@ defmodule CanneryWeb.RangeLive.Index do
defp display_shot_records( defp display_shot_records(
%{assigns: %{class: class, search: search, current_user: current_user}} = socket %{assigns: %{class: class, search: search, current_user: current_user}} = socket
) do ) do
shot_records = ActivityLog.list_shot_records(current_user, search: search, class: class) shot_records = ActivityLog.list_shot_records(search, class, current_user)
packs = Ammo.list_packs(current_user, staged: true) packs = Ammo.list_staged_packs(current_user)
chart_data = shot_records |> get_chart_data_for_shot_record() chart_data = shot_records |> get_chart_data_for_shot_record()
original_counts = packs |> Ammo.get_original_counts(current_user) original_counts = packs |> Ammo.get_original_counts(current_user)
cprs = packs |> Ammo.get_cprs(current_user) cprs = packs |> Ammo.get_cprs(current_user)

View File

@ -122,7 +122,7 @@
<% else %> <% else %>
<.live_component <.live_component
module={CanneryWeb.Components.ShotRecordTableComponent} module={CanneryWeb.Components.ShotRecordTableComponent}
id="shot-records-index-table" id="shot_records_index_table"
shot_records={@shot_records} shot_records={@shot_records}
current_user={@current_user} current_user={@current_user}
> >

View File

@ -75,6 +75,6 @@ defmodule CanneryWeb.TagLive.Index do
end end
defp display_tags(%{assigns: %{search: search, current_user: current_user}} = socket) do defp display_tags(%{assigns: %{search: search, current_user: current_user}} = socket) do
socket |> assign(tags: Containers.list_tags(current_user, search: search)) socket |> assign(tags: Containers.list_tags(search, current_user))
end end
end end

View File

@ -106,7 +106,7 @@ defmodule CanneryWeb.TypeLive.Index do
) do ) do
socket socket
|> assign( |> assign(
types: Ammo.list_types(current_user, class: class, search: search), types: Ammo.list_types(search, current_user, class),
types_count: Ammo.get_types_count!(current_user) types_count: Ammo.get_types_count!(current_user)
) )
end end

View File

@ -74,7 +74,7 @@
<% else %> <% else %>
<.live_component <.live_component
module={CanneryWeb.Components.TypeTableComponent} module={CanneryWeb.Components.TypeTableComponent}
id="types-index-table" id="types_index_table"
action={@live_action} action={@live_action}
types={@types} types={@types}
current_user={@current_user} current_user={@current_user}

View File

@ -40,7 +40,7 @@ defmodule CanneryWeb.TypeLive.Show do
defp display_type( defp display_type(
%{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} = %{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} =
socket, socket,
%Type{id: type_id, name: type_name} = type %Type{name: type_name} = type
) do ) do
custom_fields? = custom_fields? =
fields_to_display(type) fields_to_display(type)
@ -54,7 +54,7 @@ defmodule CanneryWeb.TypeLive.Show do
type |> Map.get(field) != default_value type |> Map.get(field) != default_value
end) end)
packs = Ammo.list_packs(current_user, type_id: type_id, show_used: show_used) packs = type |> Ammo.list_packs_for_type(current_user, show_used)
[ [
original_counts, original_counts,
@ -66,10 +66,10 @@ defmodule CanneryWeb.TypeLive.Show do
if show_used do if show_used do
[ [
packs |> Ammo.get_original_counts(current_user), packs |> Ammo.get_original_counts(current_user),
Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used), type |> Ammo.get_used_packs_count_for_type(current_user),
Ammo.get_packs_count(current_user, type_id: type.id, show_used: true), type |> Ammo.get_packs_count_for_type(current_user, true),
ActivityLog.get_used_count(current_user, type_id: type.id), type |> ActivityLog.get_used_count_for_type(current_user),
Ammo.get_historical_count(type, current_user) type |> Ammo.get_historical_count_for_type(current_user)
] ]
else else
[nil, nil, nil, nil, nil] [nil, nil, nil, nil, nil]
@ -94,12 +94,12 @@ defmodule CanneryWeb.TypeLive.Show do
containers: containers, containers: containers,
cprs: packs |> Ammo.get_cprs(current_user), cprs: packs |> Ammo.get_cprs(current_user),
last_used_dates: packs |> ActivityLog.get_last_used_dates(current_user), last_used_dates: packs |> ActivityLog.get_last_used_dates(current_user),
avg_cost_per_round: Ammo.get_average_cost(type, current_user), avg_cost_per_round: type |> Ammo.get_average_cost_for_type(current_user),
rounds: Ammo.get_round_count(current_user, type_id: type.id), rounds: type |> Ammo.get_round_count_for_type(current_user),
original_counts: original_counts, original_counts: original_counts,
used_rounds: used_rounds, used_rounds: used_rounds,
historical_round_count: historical_round_count, historical_round_count: historical_round_count,
packs_count: Ammo.get_packs_count(current_user, type_id: type.id), packs_count: type |> Ammo.get_packs_count_for_type(current_user),
used_packs_count: used_packs_count, used_packs_count: used_packs_count,
historical_packs_count: historical_packs_count, historical_packs_count: historical_packs_count,
fields_to_display: fields_to_display(type), fields_to_display: fields_to_display(type),

View File

@ -4,7 +4,7 @@ defmodule Cannery.MixProject do
def project do def project do
[ [
app: :cannery, app: :cannery,
version: "0.9.4", version: "0.9.3",
elixir: "1.14.4", elixir: "1.14.4",
elixirc_paths: elixirc_paths(Mix.env()), elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,

View File

@ -500,9 +500,9 @@ msgstr "Schießkladde"
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -574,13 +574,13 @@ msgid "Reconnecting..."
msgstr "Neu verbinden..." msgstr "Neu verbinden..."
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "%{name} bearbeiten" msgstr "%{name} bearbeiten"
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "Editiere %{name} Tags" msgstr "Editiere %{name} Tags"
@ -592,9 +592,9 @@ msgstr "Editiere %{name} Tags"
msgid "Rounds:" msgid "Rounds:"
msgstr "Patronen:" msgstr "Patronen:"
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -780,7 +780,7 @@ msgstr "Behälter"
msgid "Show used" msgid "Show used"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -957,7 +957,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -997,7 +997,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -23,7 +23,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to ## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no ## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead. ## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "Behälter muss vor dem Löschen leer sein" msgstr "Behälter muss vor dem Löschen leer sein"
@ -170,7 +170,7 @@ msgstr ""
"Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War " "Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War "
"%{multiplier}" "%{multiplier}"
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "" msgstr ""

View File

@ -494,9 +494,9 @@ msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -568,13 +568,13 @@ msgid "Reconnecting..."
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "" msgstr ""
@ -586,9 +586,9 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -774,7 +774,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -951,7 +951,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -991,7 +991,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -494,9 +494,9 @@ msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -568,13 +568,13 @@ msgid "Reconnecting..."
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "" msgstr ""
@ -586,9 +586,9 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -774,7 +774,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -951,7 +951,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -991,7 +991,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -10,7 +10,7 @@ msgid ""
msgstr "" msgstr ""
"Language: en\n" "Language: en\n"
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "" msgstr ""
@ -153,7 +153,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr "" msgstr ""
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "" msgstr ""

View File

@ -10,7 +10,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "" msgstr ""
@ -152,7 +152,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr "" msgstr ""
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "" msgstr ""

View File

@ -501,9 +501,9 @@ msgstr "Registro de tiros"
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -575,13 +575,13 @@ msgid "Reconnecting..."
msgstr "Reconectando..." msgstr "Reconectando..."
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "Editar %{name}" msgstr "Editar %{name}"
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "Editar etiquetas de %{name}" msgstr "Editar etiquetas de %{name}"
@ -593,9 +593,9 @@ msgstr "Editar etiquetas de %{name}"
msgid "Rounds:" msgid "Rounds:"
msgstr "Balas:" msgstr "Balas:"
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -782,7 +782,7 @@ msgstr "Contenedor:"
msgid "Show used" msgid "Show used"
msgstr "Mostrar usadas" msgstr "Mostrar usadas"
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -959,7 +959,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "Vacio" msgstr "Vacio"
@ -999,7 +999,7 @@ msgstr "Usada por última vez en"
msgid "Last used on:" msgid "Last used on:"
msgstr "Usada por última vez en:" msgstr "Usada por última vez en:"
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "Nunca usada" msgstr "Nunca usada"

View File

@ -23,7 +23,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to ## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no ## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead. ## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "El contenedor debe estar vacío antes de ser borrado" msgstr "El contenedor debe estar vacío antes de ser borrado"
@ -168,7 +168,7 @@ msgstr "No se ha podido procesar el número de copias"
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier" msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier"
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "Multiplicador inválido" msgstr "Multiplicador inválido"

View File

@ -502,9 +502,9 @@ msgstr "Évènements de tir"
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -576,13 +576,13 @@ msgid "Reconnecting..."
msgstr "Reconnexion en cours…" msgstr "Reconnexion en cours…"
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "Éditer %{name}" msgstr "Éditer %{name}"
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "Éditer les tags de %{name}" msgstr "Éditer les tags de %{name}"
@ -594,9 +594,9 @@ msgstr "Éditer les tags de %{name}"
msgid "Rounds:" msgid "Rounds:"
msgstr "Cartouches:" msgstr "Cartouches:"
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -783,7 +783,7 @@ msgstr "Conteneur"
msgid "Show used" msgid "Show used"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -960,7 +960,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -1000,7 +1000,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -23,7 +23,7 @@ msgstr ""
# # Run "mix gettext.extract" to bring this file up to # # Run "mix gettext.extract" to bring this file up to
# # date. Leave "msgstr"s empty as changing them here has no # # date. Leave "msgstr"s empty as changing them here has no
# # effect: edit them in PO (.po) files instead. # # effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "Le conteneur doit être vide pour être supprimé" msgstr "Le conteneur doit être vide pour être supprimé"
@ -169,7 +169,7 @@ msgstr "Impossible d'analyser le nombre de copies"
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" 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}" msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "Multiplicateur invalide" msgstr "Multiplicateur invalide"

View File

@ -496,9 +496,9 @@ msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:42 #: lib/cannery_web/components/core_components/pack_card.html.heex:42
#: lib/cannery_web/components/core_components/pack_card.html.heex:47 #: lib/cannery_web/components/core_components/pack_card.html.heex:47
#: lib/cannery_web/components/pack_table_component.ex:181 #: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:264 #: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:273 #: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/live/pack_live/show.html.heex:37 #: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42 #: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150 #: lib/cannery_web/live/type_live/show.html.heex:150
@ -570,13 +570,13 @@ msgid "Reconnecting..."
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28 #: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:118 #: lib/cannery_web/live/container_live/show.ex:116
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name}" msgid "Edit %{name}"
msgstr "" msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63 #: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:119 #: lib/cannery_web/live/container_live/show.ex:117
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Edit %{name} tags" msgid "Edit %{name} tags"
msgstr "" msgstr ""
@ -588,9 +588,9 @@ msgstr ""
msgid "Rounds:" msgid "Rounds:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:178 #: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:260 #: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:272 #: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/live/type_live/show.html.heex:154 #: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "No cost information" msgid "No cost information"
@ -776,7 +776,7 @@ msgstr ""
msgid "Show used" msgid "Show used"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:219 #: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/live/pack_live/show.html.heex:19 #: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{percentage}%" msgid "%{percentage}%"
@ -953,7 +953,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17 #: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:268 #: lib/cannery_web/components/pack_table_component.ex:263
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Empty" msgid "Empty"
msgstr "" msgstr ""
@ -993,7 +993,7 @@ msgstr ""
msgid "Last used on:" msgid "Last used on:"
msgstr "" msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:199 #: lib/cannery_web/components/pack_table_component.ex:194
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Never used" msgid "Never used"
msgstr "" msgstr ""

View File

@ -24,7 +24,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to ## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no ## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead. ## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:224 #: lib/cannery/containers.ex:220
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Container must be empty before deleting" msgid "Container must be empty before deleting"
msgstr "Caithfidh an coimeádán a bheidh follamh roimh scriosadh" msgstr "Caithfidh an coimeádán a bheidh follamh roimh scriosadh"
@ -168,7 +168,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr "" msgstr ""
#: lib/cannery/ammo.ex:974 #: lib/cannery/ammo.ex:1121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Invalid multiplier" msgid "Invalid multiplier"
msgstr "" msgstr ""

View File

@ -188,27 +188,27 @@ defmodule Cannery.ActivityLogTest do
end end
end end
test "get_used_count/2 returns accurate used count for pack_id", %{ test "get_used_count/2 returns accurate used count", %{
pack: pack, pack: pack,
type: type, type: type,
container: container, container: container,
current_user: current_user current_user: current_user
} do } do
{1, [another_pack]} = pack_fixture(type, container, current_user) {1, [another_pack]} = pack_fixture(type, container, current_user)
assert 0 = ActivityLog.get_used_count(current_user, pack_id: another_pack.id) assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
assert 5 = ActivityLog.get_used_count(current_user, pack_id: pack.id) assert 5 = pack |> ActivityLog.get_used_count(current_user)
shot_record_fixture(%{count: 15}, current_user, pack) shot_record_fixture(%{count: 15}, current_user, pack)
assert 20 = ActivityLog.get_used_count(current_user, pack_id: pack.id) assert 20 = pack |> ActivityLog.get_used_count(current_user)
shot_record_fixture(%{count: 10}, current_user, pack) shot_record_fixture(%{count: 10}, current_user, pack)
assert 30 = ActivityLog.get_used_count(current_user, pack_id: pack.id) assert 30 = pack |> ActivityLog.get_used_count(current_user)
{1, [another_pack]} = pack_fixture(type, container, current_user) {1, [another_pack]} = pack_fixture(type, container, current_user)
assert 0 = ActivityLog.get_used_count(current_user, pack_id: another_pack.id) assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
end end
test "get_grouped_used_counts/2 returns accurate used counts for packs", %{ test "get_used_counts/2 returns accurate used counts", %{
pack: %{id: pack_id} = pack, pack: %{id: pack_id} = pack,
type: type, type: type,
container: container, container: container,
@ -217,41 +217,20 @@ defmodule Cannery.ActivityLogTest do
{1, [%{id: another_pack_id} = another_pack]} = pack_fixture(type, container, current_user) {1, [%{id: another_pack_id} = another_pack]} = pack_fixture(type, container, current_user)
assert %{pack_id => 5} == assert %{pack_id => 5} ==
ActivityLog.get_grouped_used_counts(current_user, [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
packs: [pack, another_pack],
group_by: :pack_id
)
shot_record_fixture(%{count: 5}, current_user, another_pack) shot_record_fixture(%{count: 5}, current_user, another_pack)
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
used_counts =
ActivityLog.get_grouped_used_counts(current_user,
packs: [pack, another_pack],
group_by: :pack_id
)
assert %{^pack_id => 5} = used_counts assert %{^pack_id => 5} = used_counts
assert %{^another_pack_id => 5} = used_counts assert %{^another_pack_id => 5} = used_counts
shot_record_fixture(%{count: 15}, current_user, pack) shot_record_fixture(%{count: 15}, current_user, pack)
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
used_counts =
ActivityLog.get_grouped_used_counts(current_user,
packs: [pack, another_pack],
group_by: :pack_id
)
assert %{^pack_id => 20} = used_counts assert %{^pack_id => 20} = used_counts
assert %{^another_pack_id => 5} = used_counts assert %{^another_pack_id => 5} = used_counts
shot_record_fixture(%{count: 10}, current_user, pack) shot_record_fixture(%{count: 10}, current_user, pack)
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
used_counts =
ActivityLog.get_grouped_used_counts(current_user,
packs: [pack, another_pack],
group_by: :pack_id
)
assert %{^pack_id => 30} = used_counts assert %{^pack_id => 30} = used_counts
assert %{^another_pack_id => 5} = used_counts assert %{^another_pack_id => 5} = used_counts
end end
@ -315,17 +294,17 @@ defmodule Cannery.ActivityLogTest do
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records
end end
test "get_used_count/2 gets accurate used round count for type_id", test "get_used_count_for_type/2 gets accurate used round count for type",
%{type: type, pack: pack, current_user: current_user} do %{type: type, pack: pack, current_user: current_user} do
another_type = type_fixture(current_user) another_type = type_fixture(current_user)
assert 0 = ActivityLog.get_used_count(current_user, type_id: another_type.id) assert 0 = another_type |> ActivityLog.get_used_count_for_type(current_user)
assert 5 = ActivityLog.get_used_count(current_user, type_id: type.id) assert 5 = type |> ActivityLog.get_used_count_for_type(current_user)
shot_record_fixture(%{count: 5}, current_user, pack) shot_record_fixture(%{count: 5}, current_user, pack)
assert 10 = ActivityLog.get_used_count(current_user, type_id: type.id) assert 10 = type |> ActivityLog.get_used_count_for_type(current_user)
shot_record_fixture(%{count: 1}, current_user, pack) shot_record_fixture(%{count: 1}, current_user, pack)
assert 11 = ActivityLog.get_used_count(current_user, type_id: type.id) assert 11 = type |> ActivityLog.get_used_count_for_type(current_user)
end end
test "get_used_count_for_types/2 gets accurate used round count for types", %{ test "get_used_count_for_types/2 gets accurate used round count for types", %{
@ -338,19 +317,13 @@ defmodule Cannery.ActivityLogTest do
{1, [pack]} = pack_fixture(another_type, container, current_user) {1, [pack]} = pack_fixture(another_type, container, current_user)
assert %{type_id => 5} == assert %{type_id => 5} ==
ActivityLog.get_grouped_used_counts(current_user, [type, another_type]
types: [type, another_type], |> ActivityLog.get_used_count_for_types(current_user)
group_by: :type_id
)
# use generated pack # use generated pack
shot_record_fixture(%{count: 5}, current_user, pack) shot_record_fixture(%{count: 5}, current_user, pack)
used_counts = used_counts = [type, another_type] |> ActivityLog.get_used_count_for_types(current_user)
ActivityLog.get_grouped_used_counts(current_user,
types: [type, another_type],
group_by: :type_id
)
assert %{^type_id => 5} = used_counts assert %{^type_id => 5} = used_counts
assert %{^another_type_id => 5} = used_counts assert %{^another_type_id => 5} = used_counts
@ -358,11 +331,7 @@ defmodule Cannery.ActivityLogTest do
# use generated pack again # use generated pack again
shot_record_fixture(%{count: 1}, current_user, pack) shot_record_fixture(%{count: 1}, current_user, pack)
used_counts = used_counts = [type, another_type] |> ActivityLog.get_used_count_for_types(current_user)
ActivityLog.get_grouped_used_counts(current_user,
types: [type, another_type],
group_by: :type_id
)
assert %{^type_id => 5} = used_counts assert %{^type_id => 5} = used_counts
assert %{^another_type_id => 6} = used_counts assert %{^another_type_id => 6} = used_counts
@ -407,17 +376,17 @@ defmodule Cannery.ActivityLogTest do
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user) {1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
pistol_shot_record = shot_record_fixture(current_user, pistol_pack) pistol_shot_record = shot_record_fixture(current_user, pistol_pack)
assert [^rifle_shot_record] = ActivityLog.list_shot_records(current_user, class: :rifle) assert [^rifle_shot_record] = ActivityLog.list_shot_records(:rifle, current_user)
assert [^shotgun_shot_record] = ActivityLog.list_shot_records(current_user, class: :shotgun) assert [^shotgun_shot_record] = ActivityLog.list_shot_records(:shotgun, current_user)
assert [^pistol_shot_record] = ActivityLog.list_shot_records(current_user, class: :pistol) assert [^pistol_shot_record] = ActivityLog.list_shot_records(:pistol, current_user)
shot_records = ActivityLog.list_shot_records(current_user, class: :all) shot_records = ActivityLog.list_shot_records(:all, current_user)
assert Enum.count(shot_records) == 3 assert Enum.count(shot_records) == 3
assert rifle_shot_record in shot_records assert rifle_shot_record in shot_records
assert shotgun_shot_record in shot_records assert shotgun_shot_record in shot_records
assert pistol_shot_record in shot_records assert pistol_shot_record in shot_records
shot_records = ActivityLog.list_shot_records(current_user, class: nil) shot_records = ActivityLog.list_shot_records(nil, current_user)
assert Enum.count(shot_records) == 3 assert Enum.count(shot_records) == 3
assert rifle_shot_record in shot_records assert rifle_shot_record in shot_records
assert shotgun_shot_record in shot_records assert shotgun_shot_record in shot_records
@ -451,13 +420,13 @@ defmodule Cannery.ActivityLogTest do
_shouldnt_return = shot_record_fixture(another_user, another_pack) _shouldnt_return = shot_record_fixture(another_user, another_pack)
# notes # notes
assert ActivityLog.list_shot_records(current_user, search: "amazing") == [shot_record_a] assert ActivityLog.list_shot_records("amazing", :all, current_user) == [shot_record_a]
# pack attributes # pack attributes
assert ActivityLog.list_shot_records(current_user, search: "stupendous") == [shot_record_b] assert ActivityLog.list_shot_records("stupendous", :all, current_user) == [shot_record_b]
# type attributes # type attributes
assert ActivityLog.list_shot_records(current_user, search: "fabulous") == [shot_record_c] assert ActivityLog.list_shot_records("fabulous", :all, current_user) == [shot_record_c]
end end
end end
end end

View File

@ -85,7 +85,7 @@ defmodule Cannery.AmmoTest do
pistol_type: pistol_type, pistol_type: pistol_type,
current_user: current_user current_user: current_user
} do } do
results = Ammo.list_types(current_user, class: :all) results = Ammo.list_types(current_user, :all)
assert results |> Enum.count() == 3 assert results |> Enum.count() == 3
assert rifle_type in results assert rifle_type in results
assert shotgun_type in results assert shotgun_type in results
@ -96,21 +96,21 @@ defmodule Cannery.AmmoTest do
rifle_type: rifle_type, rifle_type: rifle_type,
current_user: current_user current_user: current_user
} do } do
assert [^rifle_type] = Ammo.list_types(current_user, class: :rifle) assert [^rifle_type] = Ammo.list_types(current_user, :rifle)
end end
test "list_types/2 returns shotgun types", %{ test "list_types/2 returns shotgun types", %{
shotgun_type: shotgun_type, shotgun_type: shotgun_type,
current_user: current_user current_user: current_user
} do } do
assert [^shotgun_type] = Ammo.list_types(current_user, class: :shotgun) assert [^shotgun_type] = Ammo.list_types(current_user, :shotgun)
end end
test "list_types/2 returns pistol types", %{ test "list_types/2 returns pistol types", %{
pistol_type: pistol_type, pistol_type: pistol_type,
current_user: current_user current_user: current_user
} do } do
assert [^pistol_type] = Ammo.list_types(current_user, class: :pistol) assert [^pistol_type] = Ammo.list_types(current_user, :pistol)
end end
test "list_types/2 returns relevant types for a user", %{ test "list_types/2 returns relevant types for a user", %{
@ -120,22 +120,22 @@ defmodule Cannery.AmmoTest do
current_user: current_user current_user: current_user
} do } do
# name # name
assert Ammo.list_types(current_user, search: "bullet") == [rifle_type] assert Ammo.list_types("bullet", current_user, :all) == [rifle_type]
assert Ammo.list_types(current_user, search: "bullets") == [rifle_type] assert Ammo.list_types("bullets", current_user, :all) == [rifle_type]
assert Ammo.list_types(current_user, search: "hollow") == [shotgun_type] assert Ammo.list_types("hollow", current_user, :all) == [shotgun_type]
assert Ammo.list_types(current_user, search: "jacket") == [pistol_type] assert Ammo.list_types("jacket", current_user, :all) == [pistol_type]
# desc # desc
assert Ammo.list_types(current_user, search: "pew") == [rifle_type] assert Ammo.list_types("pew", current_user, :all) == [rifle_type]
assert Ammo.list_types(current_user, search: "brass") == [pistol_type] assert Ammo.list_types("brass", current_user, :all) == [pistol_type]
assert Ammo.list_types(current_user, search: "shell") == [pistol_type] assert Ammo.list_types("shell", current_user, :all) == [pistol_type]
# grains (integer) # grains (integer)
assert Ammo.list_types(current_user, search: "53453") == [rifle_type] assert Ammo.list_types("53453", current_user, :all) == [rifle_type]
assert Ammo.list_types(current_user, search: "3234234") == [shotgun_type] assert Ammo.list_types("3234234", current_user, :all) == [shotgun_type]
# tracer (boolean) # tracer (boolean)
assert Ammo.list_types(current_user, search: "tracer") == [pistol_type] assert Ammo.list_types("tracer", current_user, :all) == [pistol_type]
end end
end end
@ -222,7 +222,7 @@ defmodule Cannery.AmmoTest do
] ]
end end
test "get_average_cost/2 gets average cost for type", test "get_average_cost_for_type/2 gets average cost for type",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -232,7 +232,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
assert 25.0 = Ammo.get_average_cost(type, current_user) assert 25.0 = Ammo.get_average_cost_for_type(type, current_user)
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -242,7 +242,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
assert 25.0 = Ammo.get_average_cost(type, current_user) assert 25.0 = Ammo.get_average_cost_for_type(type, current_user)
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -252,7 +252,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
assert 40.0 = Ammo.get_average_cost(type, current_user) assert 40.0 = Ammo.get_average_cost_for_type(type, current_user)
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -262,21 +262,21 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
assert 37.5 = Ammo.get_average_cost(type, current_user) assert 37.5 = Ammo.get_average_cost_for_type(type, current_user)
end end
test "get_average_costs/2 gets average costs for types", %{ test "get_average_cost_for_types/2 gets average costs for types", %{
type: %{id: type_id} = type, type: %{id: type_id} = type,
current_user: current_user, current_user: current_user,
container: container container: container
} do } do
assert %{} == [type] |> Ammo.get_average_costs(current_user) assert %{} == [type] |> Ammo.get_average_cost_for_types(current_user)
%{id: another_type_id} = another_type = type_fixture(current_user) %{id: another_type_id} = another_type = type_fixture(current_user)
assert %{} == assert %{} ==
[type, another_type] [type, another_type]
|> Ammo.get_average_costs(current_user) |> Ammo.get_average_cost_for_types(current_user)
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -288,7 +288,7 @@ defmodule Cannery.AmmoTest do
assert %{another_type_id => 25.0} == assert %{another_type_id => 25.0} ==
[type, another_type] [type, another_type]
|> Ammo.get_average_costs(current_user) |> Ammo.get_average_cost_for_types(current_user)
{1, [_pack]} = {1, [_pack]} =
pack_fixture( pack_fixture(
@ -298,7 +298,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
average_costs = [type, another_type] |> Ammo.get_average_costs(current_user) average_costs = [type, another_type] |> Ammo.get_average_cost_for_types(current_user)
assert %{^type_id => 25.0} = average_costs assert %{^type_id => 25.0} = average_costs
assert %{^another_type_id => 25.0} = average_costs assert %{^another_type_id => 25.0} = average_costs
@ -311,7 +311,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
average_costs = [type, another_type] |> Ammo.get_average_costs(current_user) average_costs = [type, another_type] |> Ammo.get_average_cost_for_types(current_user)
assert %{^type_id => 25.0} = average_costs assert %{^type_id => 25.0} = average_costs
assert %{^another_type_id => 25.0} = average_costs assert %{^another_type_id => 25.0} = average_costs
@ -324,7 +324,7 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
average_costs = [type, another_type] |> Ammo.get_average_costs(current_user) average_costs = [type, another_type] |> Ammo.get_average_cost_for_types(current_user)
assert %{^type_id => 40.0} = average_costs assert %{^type_id => 40.0} = average_costs
assert %{^another_type_id => 25.0} = average_costs assert %{^another_type_id => 25.0} = average_costs
@ -337,30 +337,30 @@ defmodule Cannery.AmmoTest do
current_user current_user
) )
average_costs = [type, another_type] |> Ammo.get_average_costs(current_user) average_costs = [type, another_type] |> Ammo.get_average_cost_for_types(current_user)
assert %{^type_id => 37.5} = average_costs assert %{^type_id => 37.5} = average_costs
assert %{^another_type_id => 25.0} = average_costs assert %{^another_type_id => 25.0} = average_costs
end end
test "get_round_count/2 gets accurate round count for type", test "get_round_count_for_type/2 gets accurate round count for type",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
another_type = type_fixture(current_user) another_type = type_fixture(current_user)
assert 0 = Ammo.get_round_count(current_user, type_id: another_type.id) assert 0 = Ammo.get_round_count_for_type(another_type, current_user)
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert 1 = Ammo.get_round_count(current_user, type_id: type.id) assert 1 = Ammo.get_round_count_for_type(type, current_user)
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
assert 51 = Ammo.get_round_count(current_user, type_id: type.id) assert 51 = Ammo.get_round_count_for_type(type, current_user)
shot_record_fixture(%{count: 26}, current_user, pack) shot_record_fixture(%{count: 26}, current_user, pack)
assert 25 = Ammo.get_round_count(current_user, type_id: type.id) assert 25 = Ammo.get_round_count_for_type(type, current_user)
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
assert 24 = Ammo.get_round_count(current_user, type_id: type.id) assert 24 = Ammo.get_round_count_for_type(type, current_user)
end end
test "get_round_count_for_types/2 gets accurate round counts for types", %{ test "get_round_count_for_types/2 gets accurate round counts for types", %{
@ -371,158 +371,147 @@ defmodule Cannery.AmmoTest do
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert %{type_id => 1} == assert %{type_id => 1} ==
Ammo.get_grouped_round_count(current_user, types: [type], group_by: :type_id) [type] |> Ammo.get_round_count_for_types(current_user)
%{id: another_type_id} = another_type = type_fixture(current_user) %{id: another_type_id} = another_type = type_fixture(current_user)
{1, [_another_pack]} = pack_fixture(%{count: 1}, another_type, container, current_user) {1, [_another_pack]} = pack_fixture(%{count: 1}, another_type, container, current_user)
round_counts = round_counts = [type, another_type] |> Ammo.get_round_count_for_types(current_user)
Ammo.get_grouped_round_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 1} = round_counts assert %{^type_id => 1} = round_counts
assert %{^another_type_id => 1} = round_counts assert %{^another_type_id => 1} = round_counts
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
round_counts = round_counts = [type, another_type] |> Ammo.get_round_count_for_types(current_user)
Ammo.get_grouped_round_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 51} = round_counts assert %{^type_id => 51} = round_counts
assert %{^another_type_id => 1} = round_counts assert %{^another_type_id => 1} = round_counts
shot_record_fixture(%{count: 26}, current_user, pack) shot_record_fixture(%{count: 26}, current_user, pack)
round_counts = round_counts = [type, another_type] |> Ammo.get_round_count_for_types(current_user)
Ammo.get_grouped_round_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 25} = round_counts assert %{^type_id => 25} = round_counts
assert %{^another_type_id => 1} = round_counts assert %{^another_type_id => 1} = round_counts
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
round_counts = round_counts = [type, another_type] |> Ammo.get_round_count_for_types(current_user)
Ammo.get_grouped_round_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 24} = round_counts assert %{^type_id => 24} = round_counts
assert %{^another_type_id => 1} = round_counts assert %{^another_type_id => 1} = round_counts
end end
test "get_historical_count/2 gets accurate total round count for type", test "get_historical_count_for_type/2 gets accurate total round count for type",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
assert 0 = Ammo.get_historical_count(type, current_user) assert 0 = Ammo.get_historical_count_for_type(type, current_user)
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert 1 = Ammo.get_historical_count(type, current_user) assert 1 = Ammo.get_historical_count_for_type(type, current_user)
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
assert 51 = Ammo.get_historical_count(type, current_user) assert 51 = Ammo.get_historical_count_for_type(type, current_user)
shot_record_fixture(%{count: 26}, current_user, pack) shot_record_fixture(%{count: 26}, current_user, pack)
assert 51 = Ammo.get_historical_count(type, current_user) assert 51 = Ammo.get_historical_count_for_type(type, current_user)
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
assert 51 = Ammo.get_historical_count(type, current_user) assert 51 = Ammo.get_historical_count_for_type(type, current_user)
end end
test "get_historical_counts/2 gets accurate total round counts for types", test "get_historical_count_for_types/2 gets accurate total round counts for types",
%{ %{
type: %{id: type_id} = type, type: %{id: type_id} = type,
current_user: current_user, current_user: current_user,
container: container container: container
} do } do
assert %{} == [type] |> Ammo.get_historical_counts(current_user) assert %{} == [type] |> Ammo.get_historical_count_for_types(current_user)
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert %{type_id => 1} == assert %{type_id => 1} ==
[type] |> Ammo.get_historical_counts(current_user) [type] |> Ammo.get_historical_count_for_types(current_user)
%{id: another_type_id} = another_type = type_fixture(current_user) %{id: another_type_id} = another_type = type_fixture(current_user)
{1, [_pack]} = pack_fixture(%{count: 1}, another_type, container, current_user) {1, [_pack]} = pack_fixture(%{count: 1}, another_type, container, current_user)
historical_counts = [type, another_type] |> Ammo.get_historical_counts(current_user) historical_counts =
[type, another_type] |> Ammo.get_historical_count_for_types(current_user)
assert %{^type_id => 1} = historical_counts assert %{^type_id => 1} = historical_counts
assert %{^another_type_id => 1} = historical_counts assert %{^another_type_id => 1} = historical_counts
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
historical_counts = [type, another_type] |> Ammo.get_historical_counts(current_user) historical_counts =
[type, another_type] |> Ammo.get_historical_count_for_types(current_user)
assert %{^type_id => 51} = historical_counts assert %{^type_id => 51} = historical_counts
assert %{^another_type_id => 1} = historical_counts assert %{^another_type_id => 1} = historical_counts
shot_record_fixture(%{count: 26}, current_user, pack) shot_record_fixture(%{count: 26}, current_user, pack)
historical_counts = [type, another_type] |> Ammo.get_historical_counts(current_user) historical_counts =
[type, another_type] |> Ammo.get_historical_count_for_types(current_user)
assert %{^type_id => 51} = historical_counts assert %{^type_id => 51} = historical_counts
assert %{^another_type_id => 1} = historical_counts assert %{^another_type_id => 1} = historical_counts
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
historical_counts = [type, another_type] |> Ammo.get_historical_counts(current_user) historical_counts =
[type, another_type] |> Ammo.get_historical_count_for_types(current_user)
assert %{^type_id => 51} = historical_counts assert %{^type_id => 51} = historical_counts
assert %{^another_type_id => 1} = historical_counts assert %{^another_type_id => 1} = historical_counts
end end
test "get_packs_count/2 gets accurate total ammo count for type with show_used", test "get_used_packs_count_for_type/2 gets accurate total ammo count for type",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
assert 0 = Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used) assert 0 = Ammo.get_used_packs_count_for_type(type, current_user)
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert 0 = Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used) assert 0 = Ammo.get_used_packs_count_for_type(type, current_user)
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
assert 0 = Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used) assert 0 = Ammo.get_used_packs_count_for_type(type, current_user)
shot_record_fixture(%{count: 50}, current_user, pack) shot_record_fixture(%{count: 50}, current_user, pack)
assert 1 = Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used) assert 1 = Ammo.get_used_packs_count_for_type(type, current_user)
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
assert 2 = Ammo.get_packs_count(current_user, type_id: type.id, show_used: :only_used) assert 2 = Ammo.get_used_packs_count_for_type(type, current_user)
end end
test "get_grouped_packs_count/2 gets accurate total ammo counts for types", test "get_used_packs_count_for_types/2 gets accurate total ammo counts for types",
%{ %{
type: %{id: type_id} = type, type: %{id: type_id} = type,
current_user: current_user, current_user: current_user,
container: container container: container
} do } do
# testing empty type # testing empty type
assert %{} == assert %{} == [type] |> Ammo.get_used_packs_count_for_types(current_user)
Ammo.get_grouped_packs_count(current_user,
types: [type],
group_by: :type_id,
show_used: :only_used
)
# testing two empty types # testing two empty types
%{id: another_type_id} = another_type = type_fixture(current_user) %{id: another_type_id} = another_type = type_fixture(current_user)
assert %{} == assert %{} ==
Ammo.get_grouped_packs_count(current_user, [type, another_type]
types: [type, another_type], |> Ammo.get_used_packs_count_for_types(current_user)
group_by: :type_id,
show_used: :only_used
)
# testing type with pack # testing type with pack
{1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 1}, type, container, current_user)
assert %{} == assert %{} ==
Ammo.get_grouped_packs_count(current_user, [type, another_type]
types: [type, another_type], |> Ammo.get_used_packs_count_for_types(current_user)
group_by: :type_id,
show_used: :only_used
)
# testing type with used pack # testing type with used pack
{1, [another_pack]} = pack_fixture(%{count: 50}, another_type, container, current_user) {1, [another_pack]} = pack_fixture(%{count: 50}, another_type, container, current_user)
@ -530,22 +519,14 @@ defmodule Cannery.AmmoTest do
shot_record_fixture(%{count: 50}, current_user, another_pack) shot_record_fixture(%{count: 50}, current_user, another_pack)
assert %{another_type_id => 1} == assert %{another_type_id => 1} ==
Ammo.get_grouped_packs_count(current_user, [type, another_type]
types: [type, another_type], |> Ammo.get_used_packs_count_for_types(current_user)
group_by: :type_id,
show_used: :only_used
)
# testing two types with zero and one used packs # testing two types with zero and one used packs
{1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user) {1, [pack]} = pack_fixture(%{count: 50}, type, container, current_user)
shot_record_fixture(%{count: 50}, current_user, pack) shot_record_fixture(%{count: 50}, current_user, pack)
used_counts = used_counts = [type, another_type] |> Ammo.get_used_packs_count_for_types(current_user)
Ammo.get_grouped_packs_count(current_user,
types: [type, another_type],
group_by: :type_id,
show_used: :only_used
)
assert %{^type_id => 1} = used_counts assert %{^type_id => 1} = used_counts
assert %{^another_type_id => 1} = used_counts assert %{^another_type_id => 1} = used_counts
@ -553,35 +534,30 @@ defmodule Cannery.AmmoTest do
# testing two type with one and two used packs # testing two type with one and two used packs
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
used_counts = used_counts = [type, another_type] |> Ammo.get_used_packs_count_for_types(current_user)
Ammo.get_grouped_packs_count(current_user,
types: [type, another_type],
group_by: :type_id,
show_used: :only_used
)
assert %{^type_id => 2} = used_counts assert %{^type_id => 2} = used_counts
assert %{^another_type_id => 1} = used_counts assert %{^another_type_id => 1} = used_counts
end end
test "get_packs_count/2 gets accurate ammo count for container by container_id", test "get_packs_count_for_container!/2 gets accurate ammo count for container",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
{1, [first_pack]} = pack_fixture(%{count: 5}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 5}, type, container, current_user)
assert 1 = Ammo.get_packs_count(current_user, container_id: container.id) assert 1 = Ammo.get_packs_count_for_container!(container, current_user)
{25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user) {25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user)
assert 26 = Ammo.get_packs_count(current_user, container_id: container.id) assert 26 = Ammo.get_packs_count_for_container!(container, current_user)
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
assert 26 = Ammo.get_packs_count(current_user, container_id: container.id) assert 26 = Ammo.get_packs_count_for_container!(container, current_user)
shot_record_fixture(%{count: 4}, current_user, first_pack) shot_record_fixture(%{count: 4}, current_user, first_pack)
assert 25 = Ammo.get_packs_count(current_user, container_id: container.id) assert 25 = Ammo.get_packs_count_for_container!(container, current_user)
end end
test "get_grouped_packs_count/2 gets accurate ammo count for containers", %{ test "get_packs_count_for_containers/2 gets accurate ammo count for containers", %{
type: type, type: type,
current_user: current_user, current_user: current_user,
container: %{id: container_id} = container container: %{id: container_id} = container
@ -593,10 +569,8 @@ defmodule Cannery.AmmoTest do
{1, [_first_pack]} = pack_fixture(%{count: 5}, type, another_container, current_user) {1, [_first_pack]} = pack_fixture(%{count: 5}, type, another_container, current_user)
packs_count = packs_count =
Ammo.get_grouped_packs_count(current_user, [container, another_container]
containers: [container, another_container], |> Ammo.get_packs_count_for_containers(current_user)
group_by: :container_id
)
assert %{^container_id => 1} = packs_count assert %{^container_id => 1} = packs_count
assert %{^another_container_id => 1} = packs_count assert %{^another_container_id => 1} = packs_count
@ -604,10 +578,8 @@ defmodule Cannery.AmmoTest do
{25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user) {25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user)
packs_count = packs_count =
Ammo.get_grouped_packs_count(current_user, [container, another_container]
containers: [container, another_container], |> Ammo.get_packs_count_for_containers(current_user)
group_by: :container_id
)
assert %{^container_id => 26} = packs_count assert %{^container_id => 26} = packs_count
assert %{^another_container_id => 1} = packs_count assert %{^another_container_id => 1} = packs_count
@ -615,10 +587,8 @@ defmodule Cannery.AmmoTest do
shot_record_fixture(%{count: 1}, current_user, first_pack) shot_record_fixture(%{count: 1}, current_user, first_pack)
packs_count = packs_count =
Ammo.get_grouped_packs_count(current_user, [container, another_container]
containers: [container, another_container], |> Ammo.get_packs_count_for_containers(current_user)
group_by: :container_id
)
assert %{^container_id => 26} = packs_count assert %{^container_id => 26} = packs_count
assert %{^another_container_id => 1} = packs_count assert %{^another_container_id => 1} = packs_count
@ -626,30 +596,28 @@ defmodule Cannery.AmmoTest do
shot_record_fixture(%{count: 4}, current_user, first_pack) shot_record_fixture(%{count: 4}, current_user, first_pack)
packs_count = packs_count =
Ammo.get_grouped_packs_count(current_user, [container, another_container]
containers: [container, another_container], |> Ammo.get_packs_count_for_containers(current_user)
group_by: :container_id
)
assert %{^container_id => 25} = packs_count assert %{^container_id => 25} = packs_count
assert %{^another_container_id => 1} = packs_count assert %{^another_container_id => 1} = packs_count
end end
test "get_round_count/2 gets accurate total round count for container_id", test "get_round_count_for_container!/2 gets accurate total round count for container",
%{type: type, current_user: current_user, container: container} do %{type: type, current_user: current_user, container: container} do
{1, [first_pack]} = pack_fixture(%{count: 5}, type, container, current_user) {1, [first_pack]} = pack_fixture(%{count: 5}, type, container, current_user)
assert 5 = Ammo.get_round_count(current_user, container_id: container.id) assert 5 = Ammo.get_round_count_for_container!(container, current_user)
{25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user) {25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user)
assert 130 = Ammo.get_round_count(current_user, container_id: container.id) assert 130 = Ammo.get_round_count_for_container!(container, current_user)
shot_record_fixture(%{count: 5}, current_user, first_pack) shot_record_fixture(%{count: 5}, current_user, first_pack)
assert 125 = Ammo.get_round_count(current_user, container_id: container.id) assert 125 = Ammo.get_round_count_for_container!(container, current_user)
end end
test "get_grouped_round_count/2 gets accurate total round count for containers", test "get_round_count_for_containers/2 gets accurate total round count for containers",
%{ %{
type: type, type: type,
current_user: current_user, current_user: current_user,
@ -662,10 +630,7 @@ defmodule Cannery.AmmoTest do
{1, [_first_pack]} = pack_fixture(%{count: 5}, type, another_container, current_user) {1, [_first_pack]} = pack_fixture(%{count: 5}, type, another_container, current_user)
round_counts = round_counts =
Ammo.get_grouped_round_count(current_user, [container, another_container] |> Ammo.get_round_count_for_containers(current_user)
containers: [container, another_container],
group_by: :container_id
)
assert %{^container_id => 5} = round_counts assert %{^container_id => 5} = round_counts
assert %{^another_container_id => 5} = round_counts assert %{^another_container_id => 5} = round_counts
@ -673,10 +638,7 @@ defmodule Cannery.AmmoTest do
{25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user) {25, _packs} = pack_fixture(%{count: 5}, 25, type, container, current_user)
round_counts = round_counts =
Ammo.get_grouped_round_count(current_user, [container, another_container] |> Ammo.get_round_count_for_containers(current_user)
containers: [container, another_container],
group_by: :container_id
)
assert %{^container_id => 130} = round_counts assert %{^container_id => 130} = round_counts
assert %{^another_container_id => 5} = round_counts assert %{^another_container_id => 5} = round_counts
@ -684,10 +646,7 @@ defmodule Cannery.AmmoTest do
shot_record_fixture(%{count: 5}, current_user, first_pack) shot_record_fixture(%{count: 5}, current_user, first_pack)
round_counts = round_counts =
Ammo.get_grouped_round_count(current_user, [container, another_container] |> Ammo.get_round_count_for_containers(current_user)
containers: [container, another_container],
group_by: :container_id
)
assert %{^container_id => 125} = round_counts assert %{^container_id => 125} = round_counts
assert %{^another_container_id => 5} = round_counts assert %{^another_container_id => 5} = round_counts
@ -733,19 +692,19 @@ defmodule Cannery.AmmoTest do
] ]
end end
test "get_packs_count/2 returns the correct amount of ammo", test "get_packs_count!/2 returns the correct amount of ammo",
%{type: type, container: container, current_user: current_user} do %{type: type, container: container, current_user: current_user} do
assert Ammo.get_packs_count(current_user) == 1 assert Ammo.get_packs_count!(current_user) == 1
pack_fixture(type, container, current_user) pack_fixture(type, container, current_user)
assert Ammo.get_packs_count(current_user) == 2 assert Ammo.get_packs_count!(current_user) == 2
pack_fixture(type, container, current_user) pack_fixture(type, container, current_user)
assert Ammo.get_packs_count(current_user) == 3 assert Ammo.get_packs_count!(current_user) == 3
other_user = user_fixture() other_user = user_fixture()
assert Ammo.get_packs_count(other_user) == 0 assert Ammo.get_packs_count!(other_user) == 0
assert Ammo.get_packs_count(other_user, show_used: true) == 0 assert Ammo.get_packs_count!(other_user, true) == 0
other_type = type_fixture(other_user) other_type = type_fixture(other_user)
other_container = container_fixture(other_user) other_container = container_fixture(other_user)
@ -753,11 +712,11 @@ defmodule Cannery.AmmoTest do
{1, [another_pack]} = pack_fixture(%{count: 30}, other_type, other_container, other_user) {1, [another_pack]} = pack_fixture(%{count: 30}, other_type, other_container, other_user)
shot_record_fixture(%{count: 30}, other_user, another_pack) shot_record_fixture(%{count: 30}, other_user, another_pack)
assert Ammo.get_packs_count(other_user) == 0 assert Ammo.get_packs_count!(other_user) == 0
assert Ammo.get_packs_count(other_user, show_used: true) == 1 assert Ammo.get_packs_count!(other_user, true) == 1
end end
test "list_packs/2 returns all packs for a type" do test "list_packs/4 returns all packs for a type" do
current_user = user_fixture() current_user = user_fixture()
container = container_fixture(current_user) container = container_fixture(current_user)
@ -768,24 +727,24 @@ defmodule Cannery.AmmoTest do
pistol_type = type_fixture(%{class: :pistol}, current_user) pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user) {1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
assert [^rifle_pack] = Ammo.list_packs(current_user, class: :rifle) assert [^rifle_pack] = Ammo.list_packs(nil, :rifle, current_user, false)
assert [^shotgun_pack] = Ammo.list_packs(current_user, class: :shotgun) assert [^shotgun_pack] = Ammo.list_packs(nil, :shotgun, current_user, false)
assert [^pistol_pack] = Ammo.list_packs(current_user, class: :pistol) assert [^pistol_pack] = Ammo.list_packs(nil, :pistol, current_user, false)
packs = Ammo.list_packs(current_user, class: :all) packs = Ammo.list_packs(nil, :all, current_user, false)
assert Enum.count(packs) == 3 assert Enum.count(packs) == 3
assert rifle_pack in packs assert rifle_pack in packs
assert shotgun_pack in packs assert shotgun_pack in packs
assert pistol_pack in packs assert pistol_pack in packs
packs = Ammo.list_packs(current_user) packs = Ammo.list_packs(nil, nil, current_user, false)
assert Enum.count(packs) == 3 assert Enum.count(packs) == 3
assert rifle_pack in packs assert rifle_pack in packs
assert shotgun_pack in packs assert shotgun_pack in packs
assert pistol_pack in packs assert pistol_pack in packs
end end
test "list_packs/2 returns all relevant packs including used", %{ test "list_packs/4 returns all relevant packs including used", %{
type: type, type: type,
pack: pack, pack: pack,
container: container, container: container,
@ -797,15 +756,15 @@ defmodule Cannery.AmmoTest do
shot_record_fixture(%{count: 30}, current_user, another_pack) shot_record_fixture(%{count: 30}, current_user, another_pack)
another_pack = Ammo.get_pack!(another_pack_id, current_user) another_pack = Ammo.get_pack!(another_pack_id, current_user)
assert Ammo.list_packs(current_user, show_used: false) == [pack] assert Ammo.list_packs(nil, :all, current_user, false) == [pack]
packs = Ammo.list_packs(current_user, show_used: true) packs = Ammo.list_packs(nil, :all, current_user, true)
assert Enum.count(packs) == 2 assert Enum.count(packs) == 2
assert another_pack in packs assert another_pack in packs
assert pack in packs assert pack in packs
end end
test "list_packs/2 returns relevant packs when searched", %{ test "list_packs/4 returns relevant packs when searched", %{
type: type, type: type,
pack: pack, pack: pack,
container: container, container: container,
@ -825,7 +784,7 @@ defmodule Cannery.AmmoTest do
{1, [fantastic_pack]} = pack_fixture(%{count: 47}, type, another_container, current_user) {1, [fantastic_pack]} = pack_fixture(%{count: 47}, type, another_container, current_user)
packs = Ammo.list_packs(current_user, search: nil) packs = Ammo.list_packs(nil, :all, current_user, false)
assert Enum.count(packs) == 4 assert Enum.count(packs) == 4
assert fantastic_pack in packs assert fantastic_pack in packs
assert amazing_pack in packs assert amazing_pack in packs
@ -833,51 +792,37 @@ defmodule Cannery.AmmoTest do
assert pack in packs assert pack in packs
# search works for pack attributes # search works for pack attributes
assert Ammo.list_packs(current_user, search: "cool") == [another_pack] assert Ammo.list_packs("cool", :all, current_user, true) == [another_pack]
# search works for type attributes # search works for type attributes
assert Ammo.list_packs(current_user, search: "amazing") == [amazing_pack] assert Ammo.list_packs("amazing", :all, current_user, true) == [amazing_pack]
# search works for container attributes # search works for container attributes
assert Ammo.list_packs(current_user, search: "fantastic") == [fantastic_pack] assert Ammo.list_packs("fantastic", :all, current_user, true) ==
[fantastic_pack]
# search works for container tag attributes # search works for container tag attributes
assert Ammo.list_packs(current_user, search: "stupendous") == [fantastic_pack] assert Ammo.list_packs("stupendous", :all, current_user, true) ==
assert Ammo.list_packs(current_user, search: "random") == [] [fantastic_pack]
assert Ammo.list_packs("random", :all, current_user, true) == []
end end
test "list_packs/2 returns all relevant packs including staged", %{ test "list_packs_for_type/3 returns all packs for a type", %{
type: type,
container: container,
pack: unstaged_pack,
current_user: current_user
} do
{1, [staged_pack]} = pack_fixture(%{staged: true}, type, container, current_user)
assert Ammo.list_packs(current_user, staged: false) == [unstaged_pack]
assert Ammo.list_packs(current_user, staged: true) == [staged_pack]
packs = Ammo.list_packs(current_user)
assert Enum.count(packs) == 2
assert unstaged_pack in packs
assert staged_pack in packs
end
test "list_packs/2 returns all relevant packs for a type", %{
container: container, container: container,
current_user: current_user current_user: current_user
} do } do
type = type_fixture(current_user) type = type_fixture(current_user)
{1, [pack]} = pack_fixture(type, container, current_user) {1, [pack]} = pack_fixture(type, container, current_user)
assert [^pack] = Ammo.list_packs(current_user, type_id: type.id) assert [^pack] = Ammo.list_packs_for_type(type, current_user)
shot_record_fixture(current_user, pack) shot_record_fixture(current_user, pack)
pack = Ammo.get_pack!(pack.id, current_user) pack = Ammo.get_pack!(pack.id, current_user)
assert [] == Ammo.list_packs(current_user, type_id: type.id) assert [] == Ammo.list_packs_for_type(type, current_user)
assert [^pack] = Ammo.list_packs(current_user, type_id: type.id, show_used: true) assert [^pack] = Ammo.list_packs_for_type(type, current_user, true)
end end
test "list_packs/2 returns all relevant packs for a container" do test "list_packs_for_container/3 returns all packs for a container" do
current_user = user_fixture() current_user = user_fixture()
container = container_fixture(current_user) container = container_fixture(current_user)
@ -893,75 +838,78 @@ defmodule Cannery.AmmoTest do
pack_fixture(shotgun_type, another_container, current_user) pack_fixture(shotgun_type, another_container, current_user)
pack_fixture(pistol_type, another_container, current_user) pack_fixture(pistol_type, another_container, current_user)
assert [^rifle_pack] = assert [^rifle_pack] = Ammo.list_packs_for_container(container, :rifle, current_user)
Ammo.list_packs(current_user, container_id: container.id, class: :rifle)
assert [^shotgun_pack] = assert [^shotgun_pack] = Ammo.list_packs_for_container(container, :shotgun, current_user)
Ammo.list_packs(current_user, container_id: container.id, class: :shotgun)
assert [^pistol_pack] = assert [^pistol_pack] = Ammo.list_packs_for_container(container, :pistol, current_user)
Ammo.list_packs(current_user, container_id: container.id, class: :pistol)
packs = Ammo.list_packs(current_user, container_id: container.id, class: :all) packs = Ammo.list_packs_for_container(container, :all, current_user)
assert Enum.count(packs) == 3 assert Enum.count(packs) == 3
assert rifle_pack in packs assert rifle_pack in packs
assert shotgun_pack in packs assert shotgun_pack in packs
assert pistol_pack in packs assert pistol_pack in packs
packs = Ammo.list_packs(current_user, container_id: container.id) packs = Ammo.list_packs_for_container(container, nil, current_user)
assert Enum.count(packs) == 3 assert Enum.count(packs) == 3
assert rifle_pack in packs assert rifle_pack in packs
assert shotgun_pack in packs assert shotgun_pack in packs
assert pistol_pack in packs assert pistol_pack in packs
end end
test "get_packs_count/2 with type_id returns count of packs for a type", %{ test "get_packs_count_for_type/2 returns count of packs for a type", %{
type: type, type: type,
container: container, container: container,
current_user: current_user current_user: current_user
} do } do
assert 1 = Ammo.get_packs_count(current_user, type_id: type.id) assert 1 = Ammo.get_packs_count_for_type(type, current_user)
another_type = type_fixture(current_user) another_type = type_fixture(current_user)
assert 0 = Ammo.get_packs_count(current_user, type_id: another_type.id) assert 0 = Ammo.get_packs_count_for_type(another_type, current_user)
{5, _packs} = pack_fixture(%{}, 5, type, container, current_user) {5, _packs} = pack_fixture(%{}, 5, type, container, current_user)
assert 6 = Ammo.get_packs_count(current_user, type_id: type.id) assert 6 = Ammo.get_packs_count_for_type(type, current_user)
end end
test "get_grouped_packs_count/2 returns counts of packs for types", %{ test "get_packs_count_for_types/2 returns counts of packs for types", %{
type: %{id: type_id} = type, type: %{id: type_id} = type,
container: container, container: container,
current_user: current_user current_user: current_user
} do } do
assert %{type_id => 1} == assert %{type_id => 1} ==
Ammo.get_grouped_packs_count(current_user, types: [type], group_by: :type_id) [type] |> Ammo.get_packs_count_for_types(current_user)
%{id: another_type_id} = another_type = type_fixture(current_user) %{id: another_type_id} = another_type = type_fixture(current_user)
assert %{type_id => 1} == assert %{type_id => 1} ==
Ammo.get_grouped_packs_count(current_user, [type, another_type]
types: [type, another_type], |> Ammo.get_packs_count_for_types(current_user)
group_by: :type_id
)
{1, [_pack]} = pack_fixture(another_type, container, current_user) {1, [_pack]} = pack_fixture(another_type, container, current_user)
packs_count = packs_count = [type, another_type] |> Ammo.get_packs_count_for_types(current_user)
Ammo.get_grouped_packs_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 1} = packs_count assert %{^type_id => 1} = packs_count
assert %{^another_type_id => 1} = packs_count assert %{^another_type_id => 1} = packs_count
{5, _packs} = pack_fixture(%{}, 5, type, container, current_user) {5, _packs} = pack_fixture(%{}, 5, type, container, current_user)
packs_count = packs_count = [type, another_type] |> Ammo.get_packs_count_for_types(current_user)
Ammo.get_grouped_packs_count(current_user, types: [type, another_type], group_by: :type_id)
assert %{^type_id => 6} = packs_count assert %{^type_id => 6} = packs_count
assert %{^another_type_id => 1} = packs_count assert %{^another_type_id => 1} = packs_count
end end
test "list_staged_packs/1 returns all packs that are staged", %{
type: type,
container: container,
current_user: current_user
} do
{1, [another_pack]} = pack_fixture(%{staged: true}, type, container, current_user)
assert Ammo.list_staged_packs(current_user) == [another_pack]
end
test "get_pack!/2 returns the pack with given id", test "get_pack!/2 returns the pack with given id",
%{pack: %{id: pack_id} = pack, current_user: current_user} do %{pack: %{id: pack_id} = pack, current_user: current_user} do
assert Ammo.get_pack!(pack_id, current_user) == pack assert Ammo.get_pack!(pack_id, current_user) == pack

View File

@ -77,16 +77,16 @@ defmodule Cannery.ContainersTest do
_shouldnt_return = container_fixture(%{name: "another person's container"}, user_fixture()) _shouldnt_return = container_fixture(%{name: "another person's container"}, user_fixture())
# attributes # attributes
assert Containers.list_containers(current_user, search: "cool") == [container_a] assert Containers.list_containers("cool", current_user) == [container_a]
assert Containers.list_containers(current_user, search: "fascinating") == [container_b] assert Containers.list_containers("fascinating", current_user) == [container_b]
assert Containers.list_containers(current_user, search: "secret") == [container_c] assert Containers.list_containers("secret", current_user) == [container_c]
assert Containers.list_containers(current_user, search: "box") == [container_d] assert Containers.list_containers("box", current_user) == [container_d]
# tags # tags
assert Containers.list_containers(current_user, search: "stupendous") == [container_c] assert Containers.list_containers("stupendous", current_user) == [container_c]
assert Containers.list_containers(current_user, search: "amazing") == [container_d] assert Containers.list_containers("amazing", current_user) == [container_d]
assert Containers.list_containers(current_user, search: "asajslkdflskdf") == [] assert Containers.list_containers("asajslkdflskdf", current_user) == []
end end
test "get_container!/2 returns the container with given id", test "get_container!/2 returns the container with given id",
@ -168,10 +168,10 @@ defmodule Cannery.ContainersTest do
tag_fixture(%{name: "bullet", desc: "pews brass shell"}, user_fixture()) tag_fixture(%{name: "bullet", desc: "pews brass shell"}, user_fixture())
# name # name
assert Containers.list_tags(current_user, search: "bullet") == [tag_a] assert Containers.list_tags("bullet", current_user) == [tag_a]
assert Containers.list_tags(current_user, search: "bullets") == [tag_a] assert Containers.list_tags("bullets", current_user) == [tag_a]
assert Containers.list_tags(current_user, search: "hollow") == [tag_b] assert Containers.list_tags("hollow", current_user) == [tag_b]
assert Containers.list_tags(current_user, search: "hollows") == [tag_b] assert Containers.list_tags("hollows", current_user) == [tag_b]
end end
test "get_tag!/2 returns the tag with given id", %{tag: tag, current_user: current_user} do test "get_tag!/2 returns the tag with given id", %{tag: tag, current_user: current_user} do

View File

@ -51,7 +51,7 @@ defmodule CanneryWeb.ExportControllerTest do
"price_paid" => pack.price_paid, "price_paid" => pack.price_paid,
"lot_number" => pack.lot_number, "lot_number" => pack.lot_number,
"staged" => pack.staged, "staged" => pack.staged,
"used_count" => ActivityLog.get_used_count(current_user, pack_id: pack.id), "used_count" => pack |> ActivityLog.get_used_count(current_user),
"original_count" => pack |> Ammo.get_original_count(current_user), "original_count" => pack |> Ammo.get_original_count(current_user),
"cpr" => pack |> Ammo.get_cpr(current_user), "cpr" => pack |> Ammo.get_cpr(current_user),
"percentage_remaining" => pack |> Ammo.get_percentage_remaining(current_user) "percentage_remaining" => pack |> Ammo.get_percentage_remaining(current_user)
@ -90,12 +90,11 @@ defmodule CanneryWeb.ExportControllerTest do
"load_grains" => type.load_grains, "load_grains" => type.load_grains,
"shot_charge_weight" => type.shot_charge_weight, "shot_charge_weight" => type.shot_charge_weight,
"dram_equivalent" => type.dram_equivalent, "dram_equivalent" => type.dram_equivalent,
"average_cost" => Ammo.get_average_cost(type, current_user), "average_cost" => type |> Ammo.get_average_cost_for_type(current_user),
"round_count" => Ammo.get_round_count(current_user, type_id: type.id), "round_count" => type |> Ammo.get_round_count_for_type(current_user),
"used_count" => ActivityLog.get_used_count(current_user, type_id: type.id), "used_count" => type |> ActivityLog.get_used_count_for_type(current_user),
"pack_count" => Ammo.get_packs_count(current_user, type_id: type.id), "pack_count" => type |> Ammo.get_packs_count_for_type(current_user),
"total_pack_count" => "total_pack_count" => type |> Ammo.get_packs_count_for_type(current_user, true)
Ammo.get_packs_count(current_user, type_id: type.id, show_used: true)
} }
ideal_container = %{ ideal_container = %{
@ -112,8 +111,8 @@ defmodule CanneryWeb.ExportControllerTest do
} }
], ],
"type" => container.type, "type" => container.type,
"pack_count" => Ammo.get_packs_count(current_user, container_id: container.id), "pack_count" => container |> Ammo.get_packs_count_for_container!(current_user),
"round_count" => Ammo.get_round_count(current_user, container_id: container.id) "round_count" => container |> Ammo.get_round_count_for_container!(current_user)
} }
ideal_shot_record = %{ ideal_shot_record = %{

View File

@ -177,7 +177,7 @@ defmodule CanneryWeb.PackLiveTest do
|> follow_redirect(conn, ~p"/ammo") |> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo added successfully" assert html =~ "Ammo added successfully"
assert Ammo.list_packs(current_user) |> Enum.count() == multiplier + 1 assert Ammo.list_packs(nil, :all, current_user) |> Enum.count() == multiplier + 1
end end
test "does not save invalid number of new packs", %{conn: conn} do test "does not save invalid number of new packs", %{conn: conn} do