Compare commits

...

20 Commits

Author SHA1 Message Date
52c4ab45d5 fix class filter helper functions
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-05 23:17:43 -04:00
a35f43d6df rename Ammo.get_average_cost and Ammo.get_historical_count 2023-06-05 23:17:43 -04:00
9edeb1e803 improve Ammo.get_grouped_round_count 2023-06-05 23:17:43 -04:00
7e55446b3e improve ActivityLog.list_shot_records 2023-06-05 23:17:43 -04:00
9643e9f46d improve Ammo.get_round_count 2023-06-05 23:17:39 -04:00
8466fcd1f9 improve ActivityLog.get_grouped_used_counts 2023-06-05 23:16:47 -04:00
e713a2e108 improve ActivityLog.get_used_count 2023-06-05 23:16:00 -04:00
a8fa321040 use sr for shot record in sql 2023-06-05 23:16:00 -04:00
f0536f3030 improve Ammo.get_grouped_packs_count 2023-06-05 23:15:57 -04:00
a94d2eebf4 improve Ammo.get_packs_count 2023-06-05 23:06:28 -04:00
cfc56519f5 fix user registration controller 2023-06-04 00:07:31 -04:00
e80c2018be improve Ammo.list_packs 2023-06-04 00:00:51 -04:00
71fdd42d96 improve Ammo.list_types 2023-06-03 20:14:20 -04:00
8e99a57994 improve Containers.list_containers 2023-06-03 20:12:06 -04:00
7c42dd8a3a improve Containers.list_tags 2023-06-03 19:54:51 -04:00
79c97d7502 fix error/404 pages not rendering properly 2023-05-12 22:59:53 -04:00
2e488fa26c fix ammo type sql naming issues 2023-05-12 22:22:46 -04:00
2179bd5d86 fix table component ids 2023-05-12 21:55:59 -04:00
49628cb9bb pattern match on user struct in more cases 2023-05-12 21:48:19 -04:00
8a58d53dc1 fix pack sql naming issues 2023-05-12 21:48:04 -04:00
45 changed files with 1029 additions and 1006 deletions

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -148,8 +148,8 @@ defmodule CanneryWeb.PackLive.Index do
) do
# get total number of packs to determine whether to display onboarding
# prompts
packs_count = Ammo.get_packs_count!(current_user, true)
packs = Ammo.list_packs(search, class, current_user, show_used)
packs_count = Ammo.get_packs_count(current_user, show_used: true)
packs = Ammo.list_packs(current_user, search: search, class: class, show_used: show_used)
types_count = Ammo.get_types_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}
]
shot_records = ActivityLog.list_shot_records_for_pack(pack, current_user)
shot_records = ActivityLog.list_shot_records(current_user, pack_id: pack.id)
rows =
shot_records

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ defmodule Cannery.MixProject do
def project do
[
app: :cannery,
version: "0.9.3",
version: "0.9.4",
elixir: "1.14.4",
elixirc_paths: elixirc_paths(Mix.env()),
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -574,13 +574,13 @@ msgid "Reconnecting..."
msgstr "Neu verbinden..."
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr "%{name} bearbeiten"
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr "Editiere %{name} Tags"
@ -592,9 +592,9 @@ msgstr "Editiere %{name} Tags"
msgid "Rounds:"
msgstr "Patronen:"
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -780,7 +780,7 @@ msgstr "Behälter"
msgid "Show used"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -957,7 +957,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
@ -997,7 +997,7 @@ msgstr ""
msgid "Last used on:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
msgstr ""

View File

@ -23,7 +23,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:220
#: lib/cannery/containers.ex:224
#, elixir-autogen, elixir-format
msgid "Container must be empty before deleting"
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 "
"%{multiplier}"
#: lib/cannery/ammo.ex:1121
#: lib/cannery/ammo.ex:974
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -568,13 +568,13 @@ msgid "Reconnecting..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -586,9 +586,9 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -774,7 +774,7 @@ msgstr ""
msgid "Show used"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -951,7 +951,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
@ -991,7 +991,7 @@ msgstr ""
msgid "Last used on:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -568,13 +568,13 @@ msgid "Reconnecting..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -586,9 +586,9 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -774,7 +774,7 @@ msgstr ""
msgid "Show used"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -951,7 +951,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
@ -991,7 +991,7 @@ msgstr ""
msgid "Last used on:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
msgstr ""

View File

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

View File

@ -10,7 +10,7 @@
msgid ""
msgstr ""
#: lib/cannery/containers.ex:220
#: lib/cannery/containers.ex:224
#, elixir-autogen, elixir-format
msgid "Container must be empty before deleting"
msgstr ""
@ -152,7 +152,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr ""
#: lib/cannery/ammo.ex:1121
#: lib/cannery/ammo.ex:974
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -575,13 +575,13 @@ msgid "Reconnecting..."
msgstr "Reconectando..."
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr "Editar %{name}"
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr "Editar etiquetas de %{name}"
@ -593,9 +593,9 @@ msgstr "Editar etiquetas de %{name}"
msgid "Rounds:"
msgstr "Balas:"
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -782,7 +782,7 @@ msgstr "Contenedor:"
msgid "Show used"
msgstr "Mostrar usadas"
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -959,7 +959,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr "Vacio"
@ -999,7 +999,7 @@ msgstr "Usada por última vez en"
msgid "Last used on:"
msgstr "Usada por última vez en:"
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
msgstr "Nunca usada"

View File

@ -23,7 +23,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:220
#: lib/cannery/containers.ex:224
#, elixir-autogen, elixir-format
msgid "Container must be empty before deleting"
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}"
msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier"
#: lib/cannery/ammo.ex:1121
#: lib/cannery/ammo.ex:974
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -576,13 +576,13 @@ msgid "Reconnecting..."
msgstr "Reconnexion en cours…"
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr "Éditer %{name}"
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr "Éditer les tags de %{name}"
@ -594,9 +594,9 @@ msgstr "Éditer les tags de %{name}"
msgid "Rounds:"
msgstr "Cartouches:"
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -783,7 +783,7 @@ msgstr "Conteneur"
msgid "Show used"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -960,7 +960,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
@ -1000,7 +1000,7 @@ msgstr ""
msgid "Last used on:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
msgstr ""

View File

@ -23,7 +23,7 @@ msgstr ""
# # Run "mix gettext.extract" to bring this file up to
# # date. Leave "msgstr"s empty as changing them here has no
# # effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:220
#: lib/cannery/containers.ex:224
#, elixir-autogen, elixir-format
msgid "Container must be empty before deleting"
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}"
msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
#: lib/cannery/ammo.ex:1121
#: lib/cannery/ammo.ex:974
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
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:47
#: lib/cannery_web/components/pack_table_component.ex:176
#: lib/cannery_web/components/pack_table_component.ex:259
#: lib/cannery_web/components/type_table_component.ex:260
#: lib/cannery_web/components/pack_table_component.ex:181
#: lib/cannery_web/components/pack_table_component.ex:264
#: lib/cannery_web/components/type_table_component.ex:273
#: lib/cannery_web/live/pack_live/show.html.heex:37
#: lib/cannery_web/live/pack_live/show.html.heex:42
#: lib/cannery_web/live/type_live/show.html.heex:150
@ -570,13 +570,13 @@ msgid "Reconnecting..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:28
#: lib/cannery_web/live/container_live/show.ex:116
#: lib/cannery_web/live/container_live/show.ex:118
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:63
#: lib/cannery_web/live/container_live/show.ex:117
#: lib/cannery_web/live/container_live/show.ex:119
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -588,9 +588,9 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:173
#: lib/cannery_web/components/pack_table_component.ex:255
#: lib/cannery_web/components/type_table_component.ex:259
#: lib/cannery_web/components/pack_table_component.ex:178
#: lib/cannery_web/components/pack_table_component.ex:260
#: lib/cannery_web/components/type_table_component.ex:272
#: lib/cannery_web/live/type_live/show.html.heex:154
#, elixir-autogen, elixir-format
msgid "No cost information"
@ -776,7 +776,7 @@ msgstr ""
msgid "Show used"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:214
#: lib/cannery_web/components/pack_table_component.ex:219
#: lib/cannery_web/live/pack_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -953,7 +953,7 @@ msgid "Average CPR"
msgstr ""
#: lib/cannery_web/components/core_components/pack_card.html.heex:17
#: lib/cannery_web/components/pack_table_component.ex:263
#: lib/cannery_web/components/pack_table_component.ex:268
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
@ -993,7 +993,7 @@ msgstr ""
msgid "Last used on:"
msgstr ""
#: lib/cannery_web/components/pack_table_component.ex:194
#: lib/cannery_web/components/pack_table_component.ex:199
#, elixir-autogen, elixir-format
msgid "Never used"
msgstr ""

View File

@ -24,7 +24,7 @@ msgstr ""
## Run "mix gettext.extract" to bring this file up to
## date. Leave "msgstr"s empty as changing them here has no
## effect: edit them in PO (.po) files instead.
#: lib/cannery/containers.ex:220
#: lib/cannery/containers.ex:224
#, elixir-autogen, elixir-format
msgid "Container must be empty before deleting"
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}"
msgstr ""
#: lib/cannery/ammo.ex:1121
#: lib/cannery/ammo.ex:974
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

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

View File

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

View File

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