forked from shibao/cannery
fix shot records table disappearing after selecting an empty ammo class
This commit is contained in:
parent
6ed3312ea8
commit
32801828fa
@ -1,6 +1,7 @@
|
||||
# v0.9.1
|
||||
- Rename ammo type's "type" to "class" to avoid confusion
|
||||
- Fixes ammo type search
|
||||
- Fixes shot records table disappearing after selecting an empty ammo class
|
||||
- Code quality improvements
|
||||
|
||||
# v0.9.0
|
||||
|
@ -92,6 +92,25 @@ defmodule Cannery.ActivityLog do
|
||||
|
||||
defp list_shot_groups_filter_type(query, _all), do: query
|
||||
|
||||
@doc """
|
||||
Returns a count of shot records.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_shot_record_count!(%User{id: 123})
|
||||
3
|
||||
|
||||
"""
|
||||
@spec get_shot_record_count!(User.t()) :: integer()
|
||||
def get_shot_record_count!(%User{id: user_id}) do
|
||||
Repo.one(
|
||||
from sg in ShotGroup,
|
||||
where: sg.user_id == ^user_id,
|
||||
select: count(sg.id),
|
||||
distinct: true
|
||||
) || 0
|
||||
end
|
||||
|
||||
@spec list_shot_groups_for_pack(Pack.t(), User.t()) :: [ShotGroup.t()]
|
||||
def list_shot_groups_for_pack(
|
||||
%Pack{id: pack_id, user_id: user_id},
|
||||
|
@ -127,6 +127,7 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
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)
|
||||
shot_record_count = ActivityLog.get_shot_record_count!(current_user)
|
||||
|
||||
socket
|
||||
|> assign(
|
||||
@ -135,7 +136,8 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
cprs: cprs,
|
||||
last_used_dates: last_used_dates,
|
||||
chart_data: chart_data,
|
||||
shot_groups: shot_groups
|
||||
shot_groups: shot_groups,
|
||||
shot_record_count: shot_record_count
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
<hr class="hr" />
|
||||
|
||||
<%= if @shot_groups |> Enum.empty?() and @search |> is_nil() do %>
|
||||
<%= if @shot_record_count == 0 do %>
|
||||
<h1 class="title text-xl text-primary-600">
|
||||
<%= gettext("No shots recorded") %>
|
||||
<%= display_emoji("😔") %>
|
||||
|
@ -808,7 +808,7 @@ msgstr ""
|
||||
msgid "%{percentage}%"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr "Patronen abgefeuert"
|
||||
|
@ -802,7 +802,7 @@ msgstr ""
|
||||
msgid "%{percentage}%"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr ""
|
||||
|
@ -802,7 +802,7 @@ msgstr ""
|
||||
msgid "%{percentage}%"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr ""
|
||||
|
@ -810,7 +810,7 @@ msgstr "Mostrar usadas"
|
||||
msgid "%{percentage}%"
|
||||
msgstr "%{percentage}%"
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr "Balas disparadas: %{count}"
|
||||
|
@ -811,7 +811,7 @@ msgstr ""
|
||||
msgid "%{percentage}%"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr "Cartouches tirées"
|
||||
|
@ -804,7 +804,7 @@ msgstr ""
|
||||
msgid "%{percentage}%"
|
||||
msgstr ""
|
||||
|
||||
#: lib/cannery_web/live/range_live/index.ex:152
|
||||
#: lib/cannery_web/live/range_live/index.ex:154
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
msgid "Rounds shot: %{count}"
|
||||
msgstr ""
|
||||
|
@ -33,6 +33,26 @@ defmodule Cannery.ActivityLogTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "get_shot_record_count!/1 returns the correct amount of shot records",
|
||||
%{pack: pack, current_user: current_user} do
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 1
|
||||
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 2
|
||||
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 3
|
||||
|
||||
other_user = user_fixture()
|
||||
assert ActivityLog.get_shot_record_count!(other_user) == 0
|
||||
|
||||
container = container_fixture(other_user)
|
||||
ammo_type = ammo_type_fixture(other_user)
|
||||
{1, [pack]} = pack_fixture(%{count: 25}, ammo_type, container, other_user)
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, other_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(other_user) == 1
|
||||
end
|
||||
|
||||
test "get_shot_group!/2 returns the shot_group with given id",
|
||||
%{shot_group: shot_group, current_user: current_user} do
|
||||
assert ActivityLog.get_shot_group!(shot_group.id, current_user) == shot_group
|
||||
|
Loading…
Reference in New Issue
Block a user