forked from shibao/cannery
add used filtering to container show page
This commit is contained in:
parent
36a0a1c6c8
commit
9e386f1631
@ -6,6 +6,7 @@
|
||||
- Make ammo type show page include container names for each ammo
|
||||
- Make ammo type show page filter used-up ammo
|
||||
- Make container show page a bit more compact
|
||||
- Make container show page filter used-up ammo
|
||||
- Forgot to add the logo as the favicon whoops
|
||||
|
||||
# v0.5.4
|
||||
|
@ -5,7 +5,7 @@ defmodule Cannery.Ammo do
|
||||
|
||||
import CanneryWeb.Gettext
|
||||
import Ecto.Query, warn: false
|
||||
alias Cannery.{Accounts.User, Containers, Repo}
|
||||
alias Cannery.{Accounts.User, Containers, Containers.Container, Repo}
|
||||
alias Cannery.ActivityLog.ShotGroup
|
||||
alias Cannery.Ammo.{AmmoGroup, AmmoType}
|
||||
alias Ecto.Changeset
|
||||
@ -255,6 +255,51 @@ defmodule Cannery.Ammo do
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of ammo_groups for a user and container.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_ammo_groups_for_container(%AmmoType{id: 123}, %User{id: 123})
|
||||
[%AmmoGroup{}, ...]
|
||||
|
||||
"""
|
||||
@spec list_ammo_groups_for_container(Container.t(), User.t()) :: [AmmoGroup.t()]
|
||||
@spec list_ammo_groups_for_container(Container.t(), User.t(), include_empty :: boolean()) ::
|
||||
[AmmoGroup.t()]
|
||||
def list_ammo_groups_for_container(container, user, include_empty \\ false)
|
||||
|
||||
def list_ammo_groups_for_container(
|
||||
%Container{id: container_id, user_id: user_id},
|
||||
%User{id: user_id},
|
||||
_include_empty = true
|
||||
) do
|
||||
Repo.all(
|
||||
from ag in AmmoGroup,
|
||||
left_join: sg in assoc(ag, :shot_groups),
|
||||
where: ag.container_id == ^container_id,
|
||||
where: ag.user_id == ^user_id,
|
||||
preload: [shot_groups: sg],
|
||||
order_by: ag.id
|
||||
)
|
||||
end
|
||||
|
||||
def list_ammo_groups_for_container(
|
||||
%Container{id: container_id, user_id: user_id},
|
||||
%User{id: user_id},
|
||||
_include_empty = false
|
||||
) do
|
||||
Repo.all(
|
||||
from ag in AmmoGroup,
|
||||
left_join: sg in assoc(ag, :shot_groups),
|
||||
where: ag.container_id == ^container_id,
|
||||
where: ag.user_id == ^user_id,
|
||||
where: not (ag.count == 0),
|
||||
preload: [shot_groups: sg],
|
||||
order_by: ag.id
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the count of ammo_groups for an ammo type.
|
||||
|
||||
|
@ -212,6 +212,7 @@ defmodule Cannery.Containers do
|
||||
container
|
||||
|> Repo.preload(:ammo_groups)
|
||||
|> Map.fetch!(:ammo_groups)
|
||||
|> Enum.reject(fn %{count: count} -> count == 0 end)
|
||||
|> Enum.count()
|
||||
end
|
||||
|
||||
|
@ -5,13 +5,13 @@ defmodule CanneryWeb.ContainerLive.Show do
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
import CanneryWeb.Components.{AmmoGroupCard, TagCard}
|
||||
alias Cannery.{Accounts.User, Containers, Containers.Container, Repo, Tags}
|
||||
alias Cannery.{Ammo, Accounts.User, Containers, Containers.Container, Repo, Tags}
|
||||
alias CanneryWeb.Endpoint
|
||||
alias Ecto.Changeset
|
||||
alias Phoenix.LiveView.Socket
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket), do: {:ok, socket}
|
||||
def mount(_params, _session, socket), do: {:ok, socket |> assign(show_used: false)}
|
||||
|
||||
@impl true
|
||||
def handle_params(
|
||||
@ -39,7 +39,7 @@ defmodule CanneryWeb.ContainerLive.Show do
|
||||
container_name: container.name
|
||||
)
|
||||
|
||||
socket |> put_flash(:info, prompt) |> render_container(container.id, current_user)
|
||||
socket |> put_flash(:info, prompt) |> render_container()
|
||||
|
||||
{:error, error_string} ->
|
||||
socket |> put_flash(:error, error_string)
|
||||
@ -82,12 +82,23 @@ defmodule CanneryWeb.ContainerLive.Show do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("toggle_show_used", _, %{assigns: %{show_used: show_used}} = socket) do
|
||||
{:noreply, socket |> assign(:show_used, !show_used) |> render_container()}
|
||||
end
|
||||
|
||||
@spec render_container(Socket.t(), Container.id(), User.t()) :: Socket.t()
|
||||
defp render_container(%{assigns: %{live_action: live_action}} = socket, id, current_user) do
|
||||
defp render_container(
|
||||
%{assigns: %{live_action: live_action, show_used: show_used}} = socket,
|
||||
id,
|
||||
current_user
|
||||
) do
|
||||
%{name: container_name} =
|
||||
container =
|
||||
Containers.get_container!(id, current_user)
|
||||
|> Repo.preload([:ammo_groups, :tags], force: true)
|
||||
|> Repo.preload([:tags], force: true)
|
||||
|
||||
ammo_groups = Ammo.list_ammo_groups_for_container(container, current_user, show_used)
|
||||
|
||||
page_title =
|
||||
case live_action do
|
||||
@ -96,6 +107,13 @@ defmodule CanneryWeb.ContainerLive.Show do
|
||||
:edit_tags -> gettext("Edit %{name} tags", name: container_name)
|
||||
end
|
||||
|
||||
socket |> assign(container: container, page_title: page_title)
|
||||
socket |> assign(container: container, ammo_groups: ammo_groups, page_title: page_title)
|
||||
end
|
||||
|
||||
@spec render_container(Socket.t()) :: Socket.t()
|
||||
defp render_container(
|
||||
%{assigns: %{container: %{id: container_id}, current_user: current_user}} = socket
|
||||
) do
|
||||
socket |> render_container(container_id, current_user)
|
||||
end
|
||||
end
|
||||
|
@ -22,10 +22,10 @@
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<%= unless @container.ammo_groups |> Enum.empty?() do %>
|
||||
<%= unless @ammo_groups |> Enum.empty?() do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Packs:") %>
|
||||
<%= @container |> Containers.get_container_ammo_group_count!() %>
|
||||
<%= Enum.count(@ammo_groups) %>
|
||||
</span>
|
||||
|
||||
<span class="rounded-lg title text-lg">
|
||||
@ -84,14 +84,22 @@
|
||||
|
||||
<hr class="mb-4 hr" />
|
||||
|
||||
<div class="flex flex-col justify-center items-center">
|
||||
<.toggle_button action="toggle_show_used" value={@show_used}>
|
||||
<span class="title text-lg text-primary-600">
|
||||
<%= gettext("Show used") %>
|
||||
</span>
|
||||
</.toggle_button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= if @container.ammo_groups |> Enum.empty?() do %>
|
||||
<%= if @ammo_groups |> Enum.empty?() do %>
|
||||
<h2 class="mx-8 my-4 title text-lg text-primary-600">
|
||||
<%= gettext("No ammo in this container") %>
|
||||
</h2>
|
||||
<% else %>
|
||||
<div class="flex flex-wrap justify-center items-center">
|
||||
<%= for ammo_group <- @container.ammo_groups do %>
|
||||
<%= for ammo_group <- @ammo_groups do %>
|
||||
<.ammo_group_card ammo_group={ammo_group} />
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -710,13 +710,13 @@ msgstr "Lädt..."
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:27
|
||||
#: lib/cannery_web/live/container_live/show.ex:95
|
||||
#: lib/cannery_web/live/container_live/show.ex:106
|
||||
msgid "Edit %{name}"
|
||||
msgstr "%{name} bearbeiten"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:46
|
||||
#: lib/cannery_web/live/container_live/show.ex:96
|
||||
#: lib/cannery_web/live/container_live/show.ex:107
|
||||
msgid "Edit %{name} tags"
|
||||
msgstr "Editiere %{name} Tags"
|
||||
|
||||
@ -727,7 +727,7 @@ msgid "Rounds:"
|
||||
msgstr "Patronen:"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.ex:94
|
||||
#: lib/cannery_web/live/container_live/show.ex:105
|
||||
msgid "Show %{name}"
|
||||
msgstr "Zeige %{name}"
|
||||
|
||||
@ -900,7 +900,7 @@ msgid "Move Ammo"
|
||||
msgstr "Munition verschieben"
|
||||
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:98
|
||||
msgid "No ammo in this container"
|
||||
msgstr "Keine Munitionsgruppe in diesem Behälter"
|
||||
|
||||
@ -948,5 +948,6 @@ msgstr "Behälter"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:119
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
msgid "Show used"
|
||||
msgstr ""
|
||||
|
@ -188,7 +188,7 @@ msgstr ""
|
||||
"%{multiplier}"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:479
|
||||
#: lib/cannery/ammo.ex:524
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -693,13 +693,13 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:27
|
||||
#: lib/cannery_web/live/container_live/show.ex:95
|
||||
#: lib/cannery_web/live/container_live/show.ex:106
|
||||
msgid "Edit %{name}"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:46
|
||||
#: lib/cannery_web/live/container_live/show.ex:96
|
||||
#: lib/cannery_web/live/container_live/show.ex:107
|
||||
msgid "Edit %{name} tags"
|
||||
msgstr ""
|
||||
|
||||
@ -710,7 +710,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.ex:94
|
||||
#: lib/cannery_web/live/container_live/show.ex:105
|
||||
msgid "Show %{name}"
|
||||
msgstr ""
|
||||
|
||||
@ -883,7 +883,7 @@ msgid "Move Ammo"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:98
|
||||
msgid "No ammo in this container"
|
||||
msgstr ""
|
||||
|
||||
@ -931,5 +931,6 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:119
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
msgid "Show used"
|
||||
msgstr ""
|
||||
|
@ -694,13 +694,13 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:27
|
||||
#: lib/cannery_web/live/container_live/show.ex:95
|
||||
#: lib/cannery_web/live/container_live/show.ex:106
|
||||
msgid "Edit %{name}"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:46
|
||||
#: lib/cannery_web/live/container_live/show.ex:96
|
||||
#: lib/cannery_web/live/container_live/show.ex:107
|
||||
msgid "Edit %{name} tags"
|
||||
msgstr ""
|
||||
|
||||
@ -711,7 +711,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.ex:94
|
||||
#: lib/cannery_web/live/container_live/show.ex:105
|
||||
msgid "Show %{name}"
|
||||
msgstr ""
|
||||
|
||||
@ -884,7 +884,7 @@ msgid "Move Ammo"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:98
|
||||
msgid "No ammo in this container"
|
||||
msgstr ""
|
||||
|
||||
@ -932,5 +932,6 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:119
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
msgid "Show used"
|
||||
msgstr ""
|
||||
|
@ -171,7 +171,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:479
|
||||
#: lib/cannery/ammo.ex:524
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -170,7 +170,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:479
|
||||
#: lib/cannery/ammo.ex:524
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -708,13 +708,13 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:27
|
||||
#: lib/cannery_web/live/container_live/show.ex:95
|
||||
#: lib/cannery_web/live/container_live/show.ex:106
|
||||
msgid "Edit %{name}"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:46
|
||||
#: lib/cannery_web/live/container_live/show.ex:96
|
||||
#: lib/cannery_web/live/container_live/show.ex:107
|
||||
msgid "Edit %{name} tags"
|
||||
msgstr ""
|
||||
|
||||
@ -725,7 +725,7 @@ msgid "Rounds:"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.ex:94
|
||||
#: lib/cannery_web/live/container_live/show.ex:105
|
||||
msgid "Show %{name}"
|
||||
msgstr ""
|
||||
|
||||
@ -898,7 +898,7 @@ msgid "Move Ammo"
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:98
|
||||
msgid "No ammo in this container"
|
||||
msgstr ""
|
||||
|
||||
@ -946,5 +946,6 @@ msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:119
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
msgid "Show used"
|
||||
msgstr ""
|
||||
|
@ -186,7 +186,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:479
|
||||
#: lib/cannery/ammo.ex:524
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -712,13 +712,13 @@ msgstr "Chargement en cours…"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:27
|
||||
#: lib/cannery_web/live/container_live/show.ex:95
|
||||
#: lib/cannery_web/live/container_live/show.ex:106
|
||||
msgid "Edit %{name}"
|
||||
msgstr "Éditer %{name}"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/index.ex:46
|
||||
#: lib/cannery_web/live/container_live/show.ex:96
|
||||
#: lib/cannery_web/live/container_live/show.ex:107
|
||||
msgid "Edit %{name} tags"
|
||||
msgstr "Éditer les tags de %{name}"
|
||||
|
||||
@ -729,7 +729,7 @@ msgid "Rounds:"
|
||||
msgstr "Cartouches :"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/container_live/show.ex:94
|
||||
#: lib/cannery_web/live/container_live/show.ex:105
|
||||
msgid "Show %{name}"
|
||||
msgstr "Montrer %{name}"
|
||||
|
||||
@ -902,7 +902,7 @@ msgid "Move Ammo"
|
||||
msgstr "Déplacer munition"
|
||||
|
||||
#, elixir-autogen, elixir-format, fuzzy
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:98
|
||||
msgid "No ammo in this container"
|
||||
msgstr "Aucun groupe de munition pour ce conteneur"
|
||||
|
||||
@ -950,5 +950,6 @@ msgstr "Conteneur"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery_web/live/ammo_type_live/show.html.heex:119
|
||||
#: lib/cannery_web/live/container_live/show.html.heex:90
|
||||
msgid "Show used"
|
||||
msgstr ""
|
||||
|
@ -187,7 +187,7 @@ 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}"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:479
|
||||
#: lib/cannery/ammo.ex:524
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user