rename ammo_type type to class

This commit is contained in:
2023-03-28 23:08:40 -04:00
parent 1e645b5bb8
commit 0cae7c2940
48 changed files with 412 additions and 372 deletions

View File

@ -23,8 +23,8 @@ defmodule Cannery.ActivityLog do
[%ShotGroup{notes: "Shot some rifle rounds"}, ...]
"""
@spec list_shot_groups(AmmoType.type() | :all, User.t()) :: [ShotGroup.t()]
@spec list_shot_groups(search :: nil | String.t(), AmmoType.type() | :all, User.t()) ::
@spec list_shot_groups(AmmoType.class() | :all, User.t()) :: [ShotGroup.t()]
@spec list_shot_groups(search :: nil | String.t(), AmmoType.class() | :all, User.t()) ::
[ShotGroup.t()]
def list_shot_groups(search \\ nil, type, %{id: user_id}) do
from(sg in ShotGroup,
@ -79,16 +79,16 @@ defmodule Cannery.ActivityLog do
})
end
@spec list_shot_groups_filter_type(Queryable.t(), AmmoType.type() | :all) ::
@spec list_shot_groups_filter_type(Queryable.t(), AmmoType.class() | :all) ::
Queryable.t()
defp list_shot_groups_filter_type(query, :rifle),
do: query |> where([at: at], at.type == :rifle)
do: query |> where([at: at], at.class == :rifle)
defp list_shot_groups_filter_type(query, :pistol),
do: query |> where([at: at], at.type == :pistol)
do: query |> where([at: at], at.class == :pistol)
defp list_shot_groups_filter_type(query, :shotgun),
do: query |> where([at: at], at.type == :shotgun)
do: query |> where([at: at], at.class == :shotgun)
defp list_shot_groups_filter_type(query, _all), do: query

View File

@ -24,11 +24,11 @@ defmodule Cannery.Ammo do
[%AmmoType{}, ...]
iex> list_ammo_types("cool", %User{id: 123}, :shotgun)
[%AmmoType{name: "My cool ammo type", type: :shotgun}, ...]
[%AmmoType{name: "My cool ammo type", class: :shotgun}, ...]
"""
@spec list_ammo_types(User.t(), AmmoType.type() | :all) :: [AmmoType.t()]
@spec list_ammo_types(search :: nil | String.t(), User.t(), AmmoType.type() | :all) ::
@spec list_ammo_types(User.t(), AmmoType.class() | :all) :: [AmmoType.t()]
@spec list_ammo_types(search :: nil | String.t(), User.t(), AmmoType.class() | :all) ::
[AmmoType.t()]
def list_ammo_types(search \\ nil, user, type)
@ -72,14 +72,15 @@ defmodule Cannery.Ammo do
)
end
@spec list_ammo_types_filter_type(Queryable.t(), AmmoType.type() | :all) :: Queryable.t()
defp list_ammo_types_filter_type(query, :rifle), do: query |> where([at: at], at.type == :rifle)
@spec list_ammo_types_filter_type(Queryable.t(), AmmoType.class() | :all) :: Queryable.t()
defp list_ammo_types_filter_type(query, :rifle),
do: query |> where([at: at], at.class == :rifle)
defp list_ammo_types_filter_type(query, :pistol),
do: query |> where([at: at], at.type == :pistol)
do: query |> where([at: at], at.class == :pistol)
defp list_ammo_types_filter_type(query, :shotgun),
do: query |> where([at: at], at.type == :shotgun)
do: query |> where([at: at], at.class == :shotgun)
defp list_ammo_types_filter_type(query, _all), do: query
@ -463,16 +464,16 @@ defmodule Cannery.Ammo do
|> Repo.all()
end
@spec list_ammo_groups_for_container_filter_type(Queryable.t(), AmmoType.type() | :all) ::
@spec list_ammo_groups_for_container_filter_type(Queryable.t(), AmmoType.class() | :all) ::
Queryable.t()
defp list_ammo_groups_for_container_filter_type(query, :rifle),
do: query |> where([at: at], at.type == :rifle)
do: query |> where([at: at], at.class == :rifle)
defp list_ammo_groups_for_container_filter_type(query, :pistol),
do: query |> where([at: at], at.type == :pistol)
do: query |> where([at: at], at.class == :pistol)
defp list_ammo_groups_for_container_filter_type(query, :shotgun),
do: query |> where([at: at], at.type == :shotgun)
do: query |> where([at: at], at.class == :shotgun)
defp list_ammo_groups_for_container_filter_type(query, _all), do: query
@ -747,11 +748,11 @@ defmodule Cannery.Ammo do
[%AmmoGroup{notes: "My cool ammo group"}, ...]
"""
@spec list_ammo_groups(search :: String.t() | nil, AmmoType.type() | :all, User.t()) ::
@spec list_ammo_groups(search :: String.t() | nil, AmmoType.class() | :all, User.t()) ::
[AmmoGroup.t()]
@spec list_ammo_groups(
search :: nil | String.t(),
AmmoType.type() | :all,
AmmoType.class() | :all,
User.t(),
show_used :: boolean()
) :: [AmmoGroup.t()]
@ -780,15 +781,15 @@ defmodule Cannery.Ammo do
|> Repo.all()
end
@spec list_ammo_groups_filter_on_type(Queryable.t(), AmmoType.type() | :all) :: Queryable.t()
@spec list_ammo_groups_filter_on_type(Queryable.t(), AmmoType.class() | :all) :: Queryable.t()
defp list_ammo_groups_filter_on_type(query, :rifle),
do: query |> where([at: at], at.type == :rifle)
do: query |> where([at: at], at.class == :rifle)
defp list_ammo_groups_filter_on_type(query, :pistol),
do: query |> where([at: at], at.type == :pistol)
do: query |> where([at: at], at.class == :pistol)
defp list_ammo_groups_filter_on_type(query, :shotgun),
do: query |> where([at: at], at.type == :shotgun)
do: query |> where([at: at], at.class == :shotgun)
defp list_ammo_groups_filter_on_type(query, _all), do: query

View File

@ -42,7 +42,7 @@ defmodule Cannery.Ammo.AmmoType do
field :name, :string
field :desc, :string
field :type, Ecto.Enum, values: [:rifle, :shotgun, :pistol]
field :class, Ecto.Enum, values: [:rifle, :shotgun, :pistol]
# common fields
# https://shootersreference.com/reloadingdata/bullet_abbreviations/
@ -92,7 +92,7 @@ defmodule Cannery.Ammo.AmmoType do
id: id(),
name: String.t(),
desc: String.t() | nil,
type: type(),
class: class(),
bullet_type: String.t() | nil,
bullet_core: String.t() | nil,
cartridge: String.t() | nil,
@ -130,14 +130,14 @@ defmodule Cannery.Ammo.AmmoType do
@type new_ammo_type :: %__MODULE__{}
@type id :: UUID.t()
@type changeset :: Changeset.t(t() | new_ammo_type())
@type type :: :rifle | :shotgun | :pistol | nil
@type class :: :rifle | :shotgun | :pistol | nil
@spec changeset_fields() :: [atom()]
defp changeset_fields,
do: [
:name,
:desc,
:type,
:class,
:bullet_type,
:bullet_core,
:cartridge,

View File

@ -13,7 +13,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
%{
required(:id) => UUID.t(),
required(:current_user) => User.t(),
optional(:type) => AmmoType.type() | nil,
optional(:class) => AmmoType.class() | nil,
optional(:show_used) => boolean(),
optional(:ammo_types) => [AmmoType.t()],
optional(:actions) => Rendered.t(),
@ -26,7 +26,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
socket
|> assign(assigns)
|> assign_new(:show_used, fn -> false end)
|> assign_new(:type, fn -> :all end)
|> assign_new(:class, fn -> :all end)
|> assign_new(:actions, fn -> [] end)
|> display_ammo_types()
@ -39,7 +39,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
ammo_types: ammo_types,
current_user: current_user,
show_used: show_used,
type: type,
class: class,
actions: actions
}
} = socket
@ -48,7 +48,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
[
%{label: gettext("Cartridge"), key: :cartridge, type: :string},
%{
label: if(type == :shotgun, do: gettext("Gauge"), else: gettext("Caliber")),
label: if(class == :shotgun, do: gettext("Gauge"), else: gettext("Caliber")),
key: :caliber,
type: :string
},
@ -59,7 +59,7 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
%{label: gettext("Grains"), key: :grains, type: :string},
%{label: gettext("Bullet type"), key: :bullet_type, type: :string},
%{
label: if(type == :shotgun, do: gettext("Slug core"), else: gettext("Bullet core")),
label: if(class == :shotgun, do: gettext("Slug core"), else: gettext("Bullet core")),
key: :bullet_core,
type: :string
},
@ -147,8 +147,8 @@ defmodule CanneryWeb.Components.AmmoTypeTableComponent do
})
|> TableComponent.maybe_compose_columns(filtered_columns)
|> TableComponent.maybe_compose_columns(
%{label: gettext("Type"), key: :type, type: :atom},
type in [:all, nil]
%{label: gettext("Class"), key: :type, type: :atom},
class in [:all, nil]
)
|> TableComponent.maybe_compose_columns(%{label: gettext("Name"), key: :name, type: :name})

View File

@ -8,11 +8,16 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
@impl true
def mount(%{"search" => search}, _session, socket) do
{:ok, socket |> assign(type: :all, show_used: false, search: search) |> display_ammo_groups()}
socket =
socket
|> assign(class: :all, show_used: false, search: search)
|> display_ammo_groups()
{:ok, socket}
end
def mount(_params, _session, socket) do
{:ok, socket |> assign(type: :all, show_used: false, search: nil) |> display_ammo_groups()}
{:ok, socket |> assign(class: :all, show_used: false, search: nil) |> display_ammo_groups()}
end
@impl true
@ -119,26 +124,26 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
{:noreply, socket}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
{:noreply, socket |> assign(:type, :rifle) |> display_ammo_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
{:noreply, socket |> assign(:class, :rifle) |> display_ammo_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:type, :shotgun) |> display_ammo_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:class, :shotgun) |> display_ammo_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
{:noreply, socket |> assign(:type, :pistol) |> display_ammo_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
{:noreply, socket |> assign(:class, :pistol) |> display_ammo_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
{:noreply, socket |> assign(:type, :all) |> display_ammo_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
{:noreply, socket |> assign(:class, :all) |> display_ammo_groups()}
end
defp display_ammo_groups(
%{
assigns: %{
type: type,
class: class,
search: search,
current_user: current_user,
show_used: show_used
@ -148,7 +153,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
# get total number of ammo groups to determine whether to display onboarding
# prompts
ammo_groups_count = Ammo.get_ammo_groups_count!(current_user, true)
ammo_groups = Ammo.list_ammo_groups(search, type, current_user, show_used)
ammo_groups = Ammo.list_ammo_groups(search, class, current_user, show_used)
ammo_types_count = Ammo.get_ammo_types_count!(current_user)
containers_count = Containers.get_containers_count!(current_user)

View File

@ -43,15 +43,17 @@
:let={f}
for={%{}}
as={:ammo_type}
phx-change="change_type"
phx-submit="change_type"
phx-change="change_class"
phx-submit="change_class"
class="flex items-center"
>
<%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
<%= label(f, :class, gettext("Class"),
class: "title text-primary-600 text-lg text-center"
) %>
<%= select(
f,
:type,
:class,
[
{gettext("All"), :all},
{gettext("Rifle"), :rifle},
@ -59,7 +61,7 @@
{gettext("Pistol"), :pistol}
],
class: "mx-2 my-1 min-w-md input input-primary",
value: @type
value: @class
) %>
</.form>

View File

@ -18,15 +18,15 @@
<%= dgettext("errors", "Oops, something went wrong! Please check the errors below.") %>
</div>
<%= label(f, :type, gettext("Type"), class: "title text-lg text-primary-600") %>
<%= label(f, :class, gettext("Class"), class: "title text-lg text-primary-600") %>
<%= select(
f,
:type,
:class,
[{gettext("Rifle"), :rifle}, {gettext("Shotgun"), :shotgun}, {gettext("Pistol"), :pistol}],
class: "text-center col-span-2 input input-primary",
maxlength: 255
) %>
<%= error_tag(f, :type, "col-span-3 text-center") %>
<%= error_tag(f, :class, "col-span-3 text-center") %>
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :name,
@ -48,7 +48,7 @@
<%= gettext("Dimensions") %>
</h2>
<%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
<%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
<%= label(f, :cartridge, gettext("Cartridge"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :cartridge,
class: "text-center col-span-2 input input-primary",
@ -63,7 +63,7 @@
<%= label(
f,
:caliber,
if(Changeset.get_field(@changeset, :type) == :shotgun,
if(Changeset.get_field(@changeset, :class) == :shotgun,
do: gettext("Gauge"),
else: gettext("Caliber")
),
@ -76,7 +76,7 @@
) %>
<%= error_tag(f, :caliber, "col-span-3 text-center") %>
<%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
<%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
<%= label(f, :unfired_length, gettext("Unfired shell length"),
class: "title text-lg text-primary-600"
) %>
@ -139,7 +139,7 @@
<%= label(
f,
:bullet_core,
if(Changeset.get_field(@changeset, :type) == :shotgun,
if(Changeset.get_field(@changeset, :class) == :shotgun,
do: gettext("Slug core"),
else: gettext("Bullet core")
),
@ -152,7 +152,7 @@
) %>
<%= error_tag(f, :bullet_core, "col-span-3 text-center") %>
<%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
<%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
<%= label(f, :jacket_type, gettext("Jacket type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :jacket_type,
class: "text-center col-span-2 input input-primary",
@ -172,7 +172,7 @@
) %>
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
<%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
<%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
<%= label(f, :wadding, gettext("Wadding"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :wadding,
class: "text-center col-span-2 input input-primary",
@ -240,7 +240,7 @@
) %>
<%= error_tag(f, :powder_type, "col-span-3 text-center") %>
<%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
<%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
<%= label(f, :powder_grains_per_charge, gettext("Powder grains per charge"),
class: "title text-lg text-primary-600"
) %>
@ -262,7 +262,7 @@
) %>
<%= error_tag(f, :pressure, "col-span-3 text-center") %>
<%= if Changeset.get_field(@changeset, :type) == :shotgun do %>
<%= if Changeset.get_field(@changeset, :class) == :shotgun do %>
<%= label(f, :dram_equivalent, gettext("Dram equivalent"),
class: "title text-lg text-primary-600"
) %>
@ -275,7 +275,7 @@
<%= hidden_input(f, :dram_equivalent, value: nil) %>
<% end %>
<%= if Changeset.get_field(@changeset, :type) in [:rifle, :pistol] do %>
<%= if Changeset.get_field(@changeset, :class) in [:rifle, :pistol] do %>
<%= label(f, :muzzle_velocity, gettext("Muzzle velocity"),
class: "title text-lg text-primary-600"
) %>

View File

@ -8,11 +8,11 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
@impl true
def mount(%{"search" => search}, _session, socket) do
{:ok, socket |> assign(type: :all, show_used: false, search: search) |> list_ammo_types()}
{:ok, socket |> assign(class: :all, show_used: false, search: search) |> list_ammo_types()}
end
def mount(_params, _session, socket) do
{:ok, socket |> assign(type: :all, show_used: false, search: nil) |> list_ammo_types()}
{:ok, socket |> assign(class: :all, show_used: false, search: nil) |> list_ammo_types()}
end
@impl true
@ -86,28 +86,28 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
{:noreply, socket |> push_patch(to: search_path)}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
{:noreply, socket |> assign(:type, :rifle) |> list_ammo_types()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
{:noreply, socket |> assign(:class, :rifle) |> list_ammo_types()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:type, :shotgun) |> list_ammo_types()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:class, :shotgun) |> list_ammo_types()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
{:noreply, socket |> assign(:type, :pistol) |> list_ammo_types()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
{:noreply, socket |> assign(:class, :pistol) |> list_ammo_types()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
{:noreply, socket |> assign(:type, :all) |> list_ammo_types()}
def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
{:noreply, socket |> assign(:class, :all) |> list_ammo_types()}
end
defp list_ammo_types(
%{assigns: %{type: type, search: search, current_user: current_user}} = socket
%{assigns: %{class: class, search: search, current_user: current_user}} = socket
) do
socket
|> assign(
ammo_types: Ammo.list_ammo_types(search, current_user, type),
ammo_types: Ammo.list_ammo_types(search, current_user, class),
ammo_types_count: Ammo.get_ammo_types_count!(current_user)
)
end

View File

@ -22,15 +22,15 @@
:let={f}
for={%{}}
as={:ammo_type}
phx-change="change_type"
phx-submit="change_type"
phx-change="change_class"
phx-submit="change_class"
class="flex items-center"
>
<%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
<%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
<%= select(
f,
:type,
:class,
[
{gettext("All"), :all},
{gettext("Rifle"), :rifle},
@ -38,7 +38,7 @@
{gettext("Pistol"), :pistol}
],
class: "mx-2 my-1 min-w-md input input-primary",
value: @type
value: @class
) %>
</.form>
@ -79,7 +79,7 @@
ammo_types={@ammo_types}
current_user={@current_user}
show_used={@show_used}
type={@type}
class={@class}
>
<:actions :let={ammo_type}>
<div class="px-4 py-2 space-x-4 flex justify-center items-center">

View File

@ -116,11 +116,11 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
socket |> display_ammo_type(ammo_type)
end
defp fields_to_display(%AmmoType{type: type}) do
defp fields_to_display(%AmmoType{class: class}) do
[
%{label: gettext("Cartridge:"), key: :cartridge, type: :string},
%{
label: if(type == :shotgun, do: gettext("Gauge:"), else: gettext("Caliber:")),
label: if(class == :shotgun, do: gettext("Gauge:"), else: gettext("Caliber:")),
key: :caliber,
type: :string
},

View File

@ -42,14 +42,14 @@
<hr class="hr" />
<%= if @ammo_type.type || @custom_fields? do %>
<%= if @ammo_type.class || @custom_fields? do %>
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
<h3 class="title text-lg">
<%= gettext("Type") %>
<%= gettext("Class") %>
</h3>
<span class="text-primary-600">
<%= case @ammo_type.type do %>
<%= case @ammo_type.class do %>
<% :shotgun -> %>
<%= gettext("Shotgun") %>
<% :rifle -> %>

View File

@ -11,13 +11,13 @@ defmodule CanneryWeb.ContainerLive.Show do
@impl true
def mount(_params, _session, socket),
do: {:ok, socket |> assign(type: :all, view_table: true)}
do: {:ok, socket |> assign(class: :all, view_table: true)}
@impl true
def handle_params(%{"id" => id}, _session, %{assigns: %{current_user: current_user}} = socket) do
socket =
socket
|> assign(view_table: true)
|> assign(:view_table, true)
|> render_container(id, current_user)
{:noreply, socket}
@ -86,30 +86,30 @@ defmodule CanneryWeb.ContainerLive.Show do
{:noreply, socket |> assign(:view_table, !view_table) |> render_container()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
{:noreply, socket |> assign(:type, :rifle) |> render_container()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
{:noreply, socket |> assign(:class, :rifle) |> render_container()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:type, :shotgun) |> render_container()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:class, :shotgun) |> render_container()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
{:noreply, socket |> assign(:type, :pistol) |> render_container()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
{:noreply, socket |> assign(:class, :pistol) |> render_container()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
{:noreply, socket |> assign(:type, :all) |> render_container()}
def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
{:noreply, socket |> assign(:class, :all) |> render_container()}
end
@spec render_container(Socket.t(), Container.id(), User.t()) :: Socket.t()
defp render_container(
%{assigns: %{type: type, live_action: live_action}} = socket,
%{assigns: %{class: class, live_action: live_action}} = socket,
id,
current_user
) do
%{name: container_name} = container = Containers.get_container!(id, current_user)
ammo_groups = Ammo.list_ammo_groups_for_container(container, type, current_user)
ammo_groups = Ammo.list_ammo_groups_for_container(container, class, current_user)
original_counts = ammo_groups |> Ammo.get_original_counts(current_user)
cprs = ammo_groups |> Ammo.get_cprs(current_user)
last_used_dates = ammo_groups |> ActivityLog.get_last_used_dates(current_user)

View File

@ -90,15 +90,15 @@
:let={f}
for={%{}}
as={:ammo_type}
phx-change="change_type"
phx-submit="change_type"
phx-change="change_class"
phx-submit="change_class"
class="flex items-center"
>
<%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
<%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
<%= select(
f,
:type,
:class,
[
{gettext("All"), :all},
{gettext("Rifle"), :rifle},
@ -106,7 +106,7 @@
{gettext("Pistol"), :pistol}
],
class: "mx-2 my-1 min-w-md input input-primary",
value: @type
value: @class
) %>
</.form>

View File

@ -10,11 +10,11 @@ defmodule CanneryWeb.RangeLive.Index do
@impl true
def mount(%{"search" => search}, _session, socket) do
{:ok, socket |> assign(type: :all, search: search) |> display_shot_groups()}
{:ok, socket |> assign(class: :all, search: search) |> display_shot_groups()}
end
def mount(_params, _session, socket) do
{:ok, socket |> assign(type: :all, search: nil) |> display_shot_groups()}
{:ok, socket |> assign(class: :all, search: nil) |> display_shot_groups()}
end
@impl true
@ -102,27 +102,27 @@ defmodule CanneryWeb.RangeLive.Index do
{:noreply, socket |> push_patch(to: Routes.range_index_path(Endpoint, :search, search_term))}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
{:noreply, socket |> assign(:type, :rifle) |> display_shot_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "rifle"}}, socket) do
{:noreply, socket |> assign(:class, :rifle) |> display_shot_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:type, :shotgun) |> display_shot_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "shotgun"}}, socket) do
{:noreply, socket |> assign(:class, :shotgun) |> display_shot_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
{:noreply, socket |> assign(:type, :pistol) |> display_shot_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => "pistol"}}, socket) do
{:noreply, socket |> assign(:class, :pistol) |> display_shot_groups()}
end
def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
{:noreply, socket |> assign(:type, :all) |> display_shot_groups()}
def handle_event("change_class", %{"ammo_type" => %{"class" => _all}}, socket) do
{:noreply, socket |> assign(:class, :all) |> display_shot_groups()}
end
@spec display_shot_groups(Socket.t()) :: Socket.t()
defp display_shot_groups(
%{assigns: %{type: type, search: search, current_user: current_user}} = socket
%{assigns: %{class: class, search: search, current_user: current_user}} = socket
) do
shot_groups = ActivityLog.list_shot_groups(search, type, current_user)
shot_groups = ActivityLog.list_shot_groups(search, class, current_user)
ammo_groups = Ammo.list_staged_ammo_groups(current_user)
chart_data = shot_groups |> get_chart_data_for_shot_group()
original_counts = ammo_groups |> Ammo.get_original_counts(current_user)

View File

@ -79,15 +79,15 @@
:let={f}
for={%{}}
as={:ammo_type}
phx-change="change_type"
phx-submit="change_type"
phx-change="change_class"
phx-submit="change_class"
class="flex items-center"
>
<%= label(f, :type, gettext("Type"), class: "title text-primary-600 text-lg text-center") %>
<%= label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center") %>
<%= select(
f,
:type,
:class,
[
{gettext("All"), :all},
{gettext("Rifle"), :rifle},
@ -95,7 +95,7 @@
{gettext("Pistol"), :pistol}
],
class: "mx-2 my-1 min-w-md input input-primary",
value: @type
value: @class
) %>
</.form>