add range mode
This commit is contained in:
198
lib/cannery/activity_log.ex
Normal file
198
lib/cannery/activity_log.ex
Normal file
@ -0,0 +1,198 @@
|
||||
defmodule Cannery.ActivityLog do
|
||||
@moduledoc """
|
||||
The ActivityLog context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo, Ammo.AmmoGroup, Repo}
|
||||
alias Ecto.{Changeset, Multi}
|
||||
|
||||
@doc """
|
||||
Returns the list of shot_groups.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_shot_groups(%User{id: 123})
|
||||
[%ShotGroup{}, ...]
|
||||
|
||||
"""
|
||||
@spec list_shot_groups(User.t()) :: [ShotGroup.t()]
|
||||
def list_shot_groups(%User{id: user_id}) do
|
||||
Repo.all(from(sg in ShotGroup, where: sg.user_id == ^user_id))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single shot_group.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Shot group does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_shot_group!(123, %User{id: 123})
|
||||
%ShotGroup{}
|
||||
|
||||
iex> get_shot_group!(456, %User{id: 123})
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
@spec get_shot_group!(ShotGroup.id(), User.t()) :: ShotGroup.t()
|
||||
def get_shot_group!(id, %User{id: user_id}) do
|
||||
Repo.one!(
|
||||
from sg in ShotGroup,
|
||||
where: sg.id == ^id,
|
||||
where: sg.user_id == ^user_id,
|
||||
order_by: sg.date
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a shot_group.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_shot_group(%{field: value}, %User{id: 123})
|
||||
{:ok, %ShotGroup{}}
|
||||
|
||||
iex> create_shot_group(%{field: bad_value}, %User{id: 123})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec create_shot_group(attrs :: map(), User.t(), AmmoGroup.t()) ::
|
||||
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t()) | nil}
|
||||
def create_shot_group(
|
||||
attrs,
|
||||
%User{id: user_id},
|
||||
%AmmoGroup{id: ammo_group_id, count: ammo_group_count, user_id: user_id} = ammo_group
|
||||
) do
|
||||
attrs = attrs |> Map.merge(%{"user_id" => user_id, "ammo_group_id" => ammo_group_id})
|
||||
changeset = %ShotGroup{} |> ShotGroup.create_changeset(attrs)
|
||||
shot_group_count = changeset |> Changeset.get_field(:count)
|
||||
|
||||
if shot_group_count > ammo_group_count do
|
||||
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
|
||||
changeset = changeset |> Changeset.add_error(:count, error)
|
||||
{:error, changeset}
|
||||
else
|
||||
Multi.new()
|
||||
|> Multi.insert(:create_shot_group, changeset)
|
||||
|> Multi.update(
|
||||
:update_ammo_group,
|
||||
ammo_group |> AmmoGroup.range_changeset(%{"count" => ammo_group_count - shot_group_count})
|
||||
)
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, %{create_shot_group: shot_group}} -> {:ok, shot_group}
|
||||
{:error, :create_shot_group, changeset, _changes_so_far} -> {:error, changeset}
|
||||
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a shot_group.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_shot_group(shot_group, %{field: new_value}, %User{id: 123})
|
||||
{:ok, %ShotGroup{}}
|
||||
|
||||
iex> update_shot_group(shot_group, %{field: bad_value}, %User{id: 123})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec update_shot_group(ShotGroup.t(), attrs :: map(), User.t()) ::
|
||||
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t()) | nil}
|
||||
def update_shot_group(
|
||||
%ShotGroup{count: count, user_id: user_id, ammo_group_id: ammo_group_id} = shot_group,
|
||||
attrs,
|
||||
%User{id: user_id} = user
|
||||
) do
|
||||
%{count: ammo_group_count, user_id: ^user_id} =
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(user)
|
||||
|
||||
changeset = shot_group |> ShotGroup.update_changeset(attrs)
|
||||
new_shot_group_count = changeset |> Changeset.get_field(:count)
|
||||
shot_diff_to_add = new_shot_group_count - count
|
||||
|
||||
cond do
|
||||
shot_diff_to_add > ammo_group_count ->
|
||||
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
|
||||
changeset = changeset |> Changeset.add_error(:count, error)
|
||||
{:error, changeset}
|
||||
|
||||
new_shot_group_count <= 0 ->
|
||||
error = dgettext("errors", "Count must be at least 1")
|
||||
changeset = changeset |> Changeset.add_error(:count, error)
|
||||
{:error, changeset}
|
||||
|
||||
true ->
|
||||
Multi.new()
|
||||
|> Multi.update(:update_shot_group, changeset)
|
||||
|> Multi.update(
|
||||
:update_ammo_group,
|
||||
ammo_group
|
||||
|> AmmoGroup.range_changeset(%{"count" => ammo_group_count - shot_diff_to_add})
|
||||
)
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, %{update_shot_group: shot_group}} -> {:ok, shot_group}
|
||||
{:error, :update_shot_group, changeset, _changes_so_far} -> {:error, changeset}
|
||||
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a shot_group.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_shot_group(shot_group, %User{id: 123})
|
||||
{:ok, %ShotGroup{}}
|
||||
|
||||
iex> delete_shot_group(shot_group, %User{id: 123})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec delete_shot_group(ShotGroup.t(), User.t()) ::
|
||||
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t())}
|
||||
def delete_shot_group(
|
||||
%ShotGroup{count: count, user_id: user_id, ammo_group_id: ammo_group_id} = shot_group,
|
||||
%User{id: user_id} = user
|
||||
) do
|
||||
%{count: ammo_group_count, user_id: ^user_id} =
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(user)
|
||||
|
||||
Multi.new()
|
||||
|> Multi.delete(:delete_shot_group, shot_group)
|
||||
|> Multi.update(
|
||||
:update_ammo_group,
|
||||
ammo_group
|
||||
|> AmmoGroup.range_changeset(%{"count" => ammo_group_count + count})
|
||||
)
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, %{delete_shot_group: shot_group}} -> {:ok, shot_group}
|
||||
{:error, :delete_shot_group, changeset, _changes_so_far} -> {:error, changeset}
|
||||
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking shot_group changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_shot_group(shot_group)
|
||||
%Ecto.Changeset{data: %ShotGroup{}}
|
||||
|
||||
"""
|
||||
@spec change_shot_group(ShotGroup.t() | ShotGroup.new_shot_group()) ::
|
||||
Changeset.t(ShotGroup.t() | ShotGroup.new_shot_group())
|
||||
@spec change_shot_group(ShotGroup.t() | ShotGroup.new_shot_group(), attrs :: map()) ::
|
||||
Changeset.t(ShotGroup.t() | ShotGroup.new_shot_group())
|
||||
def change_shot_group(%ShotGroup{} = shot_group, attrs \\ %{}) do
|
||||
shot_group |> ShotGroup.update_changeset(attrs)
|
||||
end
|
||||
end
|
57
lib/cannery/activity_log/shot_group.ex
Normal file
57
lib/cannery/activity_log/shot_group.ex
Normal file
@ -0,0 +1,57 @@
|
||||
defmodule Cannery.ActivityLog.ShotGroup do
|
||||
@moduledoc """
|
||||
A shot group records a group of ammo shot during a range trip
|
||||
"""
|
||||
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Cannery.{Accounts.User, Ammo.AmmoGroup, ActivityLog.ShotGroup}
|
||||
alias Ecto.{Changeset, UUID}
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
schema "shot_groups" do
|
||||
field :count, :integer
|
||||
field :date, :date
|
||||
field :notes, :string
|
||||
|
||||
belongs_to :user, User
|
||||
belongs_to :ammo_group, AmmoGroup
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@type t :: %ShotGroup{
|
||||
id: id(),
|
||||
count: integer,
|
||||
notes: String.t() | nil,
|
||||
date: Date.t() | nil,
|
||||
ammo_group: AmmoGroup.t() | nil,
|
||||
ammo_group_id: AmmoGroup.id(),
|
||||
user: User.t() | nil,
|
||||
user_id: User.id(),
|
||||
inserted_at: NaiveDateTime.t(),
|
||||
updated_at: NaiveDateTime.t()
|
||||
}
|
||||
@type new_shot_group :: %ShotGroup{}
|
||||
@type id :: UUID.t()
|
||||
|
||||
@doc false
|
||||
@spec create_changeset(new_shot_group(), attrs :: map()) :: Changeset.t(new_shot_group())
|
||||
def create_changeset(shot_group, attrs) do
|
||||
shot_group
|
||||
|> cast(attrs, [:count, :notes, :date, :ammo_group_id, :user_id])
|
||||
|> validate_number(:count, greater_than: 0)
|
||||
|> validate_required([:count, :ammo_group_id, :user_id])
|
||||
end
|
||||
|
||||
@doc false
|
||||
@spec update_changeset(t() | new_shot_group(), attrs :: map()) ::
|
||||
Changeset.t(t() | new_shot_group())
|
||||
def update_changeset(shot_group, attrs) do
|
||||
shot_group
|
||||
|> cast(attrs, [:count, :notes, :date])
|
||||
|> validate_number(:count, greater_than: 0)
|
||||
|> validate_required([:count])
|
||||
end
|
||||
end
|
@ -177,8 +177,28 @@ defmodule Cannery.Ammo do
|
||||
|
||||
"""
|
||||
@spec list_ammo_groups(User.t()) :: [AmmoGroup.t()]
|
||||
def list_ammo_groups(%User{id: user_id}) do
|
||||
Repo.all(from am in AmmoGroup, where: am.user_id == ^user_id)
|
||||
@spec list_ammo_groups(User.t(), include_empty :: boolean()) :: [AmmoGroup.t()]
|
||||
def list_ammo_groups(%User{id: user_id}, include_empty \\ false) do
|
||||
if include_empty do
|
||||
from am in AmmoGroup, where: am.user_id == ^user_id
|
||||
else
|
||||
from am in AmmoGroup, where: am.user_id == ^user_id, where: not (am.count == 0)
|
||||
end
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of staged ammo_groups for a user.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_staged_ammo_groups(%User{id: 123})
|
||||
[%AmmoGroup{}, ...]
|
||||
|
||||
"""
|
||||
@spec list_staged_ammo_groups(User.t()) :: [AmmoGroup.t()]
|
||||
def list_staged_ammo_groups(%User{id: user_id}) do
|
||||
Repo.all(from am in AmmoGroup, where: am.user_id == ^user_id, where: am.staged == true)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -18,6 +18,7 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
field :count, :integer
|
||||
field :notes, :string
|
||||
field :price_paid, :float
|
||||
field :staged, :boolean, default: false
|
||||
|
||||
belongs_to :ammo_type, AmmoType
|
||||
belongs_to :container, Container
|
||||
@ -31,6 +32,7 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
count: integer,
|
||||
notes: String.t() | nil,
|
||||
price_paid: float() | nil,
|
||||
staged: boolean(),
|
||||
ammo_type: AmmoType.t() | nil,
|
||||
ammo_type_id: AmmoType.id(),
|
||||
container: Container.t() | nil,
|
||||
@ -47,9 +49,9 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
@spec create_changeset(new_ammo_group(), attrs :: map()) :: Changeset.t(new_ammo_group())
|
||||
def create_changeset(ammo_group, attrs) do
|
||||
ammo_group
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :ammo_type_id, :container_id, :user_id])
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged, :ammo_type_id, :container_id, :user_id])
|
||||
|> validate_number(:count, greater_than: 0)
|
||||
|> validate_required([:count, :ammo_type_id, :container_id, :user_id])
|
||||
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|
||||
end
|
||||
|
||||
@doc false
|
||||
@ -57,9 +59,9 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
Changeset.t(t() | new_ammo_group())
|
||||
def update_changeset(ammo_group, attrs) do
|
||||
ammo_group
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :ammo_type_id, :container_id])
|
||||
|> cast(attrs, [:count, :price_paid, :notes, :staged, :ammo_type_id, :container_id])
|
||||
|> validate_number(:count, greater_than: 0)
|
||||
|> validate_required([:count, :ammo_type_id, :container_id, :user_id])
|
||||
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -70,7 +72,7 @@ defmodule Cannery.Ammo.AmmoGroup do
|
||||
Changeset.t(t() | new_ammo_group())
|
||||
def range_changeset(ammo_group, attrs) do
|
||||
ammo_group
|
||||
|> cast(attrs, [:count])
|
||||
|> validate_required([:count, :ammo_type_id, :container_id, :user_id])
|
||||
|> cast(attrs, [:count, :staged])
|
||||
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|
||||
end
|
||||
end
|
||||
|
90
lib/cannery_web/components/add_shot_group_component.ex
Normal file
90
lib/cannery_web/components/add_shot_group_component.ex
Normal file
@ -0,0 +1,90 @@
|
||||
defmodule CanneryWeb.Components.AddShotGroupComponent do
|
||||
@moduledoc """
|
||||
Livecomponent that can create a ShotGroup
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo.AmmoGroup}
|
||||
alias Phoenix.LiveView.Socket
|
||||
|
||||
@impl true
|
||||
@spec update(
|
||||
%{
|
||||
required(:current_user) => User.t(),
|
||||
required(:ammo_group) => AmmoGroup.t(),
|
||||
optional(any()) => any()
|
||||
},
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(%{ammo_group: _ammo_group, current_user: _current_user} = assigns, socket) do
|
||||
changeset =
|
||||
%ShotGroup{date: NaiveDateTime.utc_now(), count: 1} |> ActivityLog.change_shot_group()
|
||||
|
||||
{:ok, socket |> assign(assigns) |> assign(:changeset, changeset)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event(
|
||||
"validate",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{
|
||||
assigns: %{
|
||||
ammo_group: %AmmoGroup{id: ammo_group_id} = ammo_group,
|
||||
current_user: %User{id: user_id}
|
||||
}
|
||||
} = socket
|
||||
) do
|
||||
shot_group_params =
|
||||
shot_group_params
|
||||
|> process_params(ammo_group)
|
||||
|> Map.merge(%{"ammo_group_id" => ammo_group_id, "user_id" => user_id})
|
||||
|
||||
changeset =
|
||||
%ShotGroup{}
|
||||
|> ActivityLog.change_shot_group(shot_group_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
{:noreply, socket |> assign(:changeset, changeset)}
|
||||
end
|
||||
|
||||
def handle_event(
|
||||
"save",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{
|
||||
assigns: %{
|
||||
ammo_group: %{id: ammo_group_id} = ammo_group,
|
||||
current_user: %{id: user_id} = current_user,
|
||||
return_to: return_to
|
||||
}
|
||||
} = socket
|
||||
) do
|
||||
socket =
|
||||
shot_group_params
|
||||
|> process_params(ammo_group)
|
||||
|> Map.merge(%{"ammo_group_id" => ammo_group_id, "user_id" => user_id})
|
||||
|> ActivityLog.create_shot_group(current_user, ammo_group)
|
||||
|> case do
|
||||
{:ok, _shot_group} ->
|
||||
prompt = dgettext("prompts", "Shots recorded successfully")
|
||||
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
socket |> assign(changeset: changeset)
|
||||
end
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
# calculate count from shots left
|
||||
defp process_params(params, %AmmoGroup{count: count}) do
|
||||
new_count =
|
||||
if params |> Map.get("ammo_left", "0") == "" do
|
||||
"0"
|
||||
else
|
||||
params |> Map.get("ammo_left", "0")
|
||||
end
|
||||
|> String.to_integer()
|
||||
|
||||
params |> Map.put("count", count - new_count)
|
||||
end
|
||||
end
|
@ -0,0 +1,47 @@
|
||||
<div>
|
||||
<h2 class="text-center title text-xl text-primary-500">
|
||||
<%= gettext("Record shots") %>
|
||||
</h2>
|
||||
|
||||
<.form
|
||||
let={f}
|
||||
for={@changeset}
|
||||
id="shot-group-form"
|
||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
<%= unless @changeset.valid? do %>
|
||||
<div class="invalid-feedback col-span-3 text-center">
|
||||
<%= changeset_errors(@changeset) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label(f, :ammo_left, gettext("Rounds left"), class: "title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :ammo_left,
|
||||
min: 0,
|
||||
max: @ammo_group.count - 1,
|
||||
placeholder: 0,
|
||||
class: "input input-primary col-span-2"
|
||||
) %>
|
||||
<%= error_tag(f, :ammo_left, "col-span-3") %>
|
||||
|
||||
<%= label(f, :notes, gettext("Notes"), class: "title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :notes,
|
||||
class: "input input-primary col-span-2",
|
||||
placeholder: "Really great weather",
|
||||
phx_hook: "MaintainAttrs"
|
||||
) %>
|
||||
<%= error_tag(f, :notes, "col-span-3") %>
|
||||
|
||||
<%= label(f, :date, gettext("Date (UTC)"), class: "title text-lg text-primary-500") %>
|
||||
<%= date_input(f, :date, class: "input input-primary col-span-2") %>
|
||||
<%= error_tag(f, :notes, "col-span-3") %>
|
||||
|
||||
<%= submit(dgettext("actions", "Save"),
|
||||
class: "mx-auto btn btn-primary col-span-3",
|
||||
phx_disable_with: dgettext("prompts", "Saving...")
|
||||
) %>
|
||||
</.form>
|
||||
</div>
|
@ -42,6 +42,12 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= if assigns |> Map.has_key?(:inner_block) do %>
|
||||
<div class="mt-4 flex space-x-4 justify-center items-center">
|
||||
<%= render_slot(@inner_block) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
@ -55,6 +55,12 @@ defmodule CanneryWeb.Components.Topbar do
|
||||
to: Routes.ammo_group_index_path(Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link(gettext("Range"),
|
||||
class: "hover:underline",
|
||||
to: Routes.range_index_path(Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<%= if @current_user.role == :admin do %>
|
||||
<li>
|
||||
<%= link(gettext("Invites"),
|
||||
|
@ -4,8 +4,8 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
alias Cannery.Ammo
|
||||
alias Cannery.Ammo.AmmoGroup
|
||||
alias Cannery.{Ammo, Ammo.AmmoGroup, Repo}
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
@ -42,7 +42,22 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> display_ammo_groups()}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event(
|
||||
"toggle_staged",
|
||||
%{"ammo_group_id" => id},
|
||||
%{assigns: %{current_user: current_user}} = socket
|
||||
) do
|
||||
ammo_group = Ammo.get_ammo_group!(id, current_user)
|
||||
|
||||
{:ok, _ammo_group} =
|
||||
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
|
||||
|
||||
{:noreply, socket |> display_ammo_groups()}
|
||||
end
|
||||
|
||||
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
|
||||
socket |> assign(:ammo_groups, Ammo.list_ammo_groups(current_user))
|
||||
ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container])
|
||||
socket |> assign(:ammo_groups, ammo_groups)
|
||||
end
|
||||
end
|
||||
|
@ -22,6 +22,9 @@
|
||||
<table class="min-w-full table-auto text-center bg-white">
|
||||
<thead class="border-b border-primary-600">
|
||||
<tr>
|
||||
<th class="p-2">
|
||||
<%= gettext("Ammo type") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Count") %>
|
||||
</th>
|
||||
@ -31,6 +34,12 @@
|
||||
<th class="p-2">
|
||||
<%= gettext("Notes") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Staging") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Container") %>
|
||||
</th>
|
||||
|
||||
<th class="p-2"></th>
|
||||
</tr>
|
||||
@ -38,6 +47,13 @@
|
||||
<tbody id="ammo_groups">
|
||||
<%= for ammo_group <- @ammo_groups do %>
|
||||
<tr id={"ammo_group-#{ammo_group.id}"}>
|
||||
<td class="p-2">
|
||||
<%= live_patch(ammo_group.ammo_type.name,
|
||||
to: Routes.ammo_type_show_path(Endpoint, :show, ammo_group.ammo_type),
|
||||
class: "link"
|
||||
) %>
|
||||
</td>
|
||||
|
||||
<td class="p-2">
|
||||
<%= ammo_group.count %>
|
||||
</td>
|
||||
@ -52,23 +68,41 @@
|
||||
<%= ammo_group.notes %>
|
||||
</td>
|
||||
|
||||
<td class="p-2">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="toggle_staged"
|
||||
phx-value-ammo_group_id={ammo_group.id}
|
||||
>
|
||||
<%= if ammo_group.staged, do: gettext("Unstage from range"), else: gettext("Stage for range") %>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
<td class="p-2">
|
||||
<%= if ammo_group.container, do: ammo_group.container.name %>
|
||||
</td>
|
||||
|
||||
<td class="p-2 w-full h-full space-x-2 flex justify-center items-center">
|
||||
<%= live_redirect(dgettext("actions", "View"),
|
||||
to: Routes.ammo_group_show_path(@socket, :show, ammo_group)
|
||||
) %>
|
||||
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
|
||||
<%= live_redirect to: Routes.ammo_group_show_path(@socket, :show, ammo_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-eye"></i>
|
||||
<% end %>
|
||||
|
||||
<%= live_patch to: Routes.ammo_group_index_path(@socket, :edit, ammo_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
<% end %>
|
||||
<%= live_patch to: Routes.ammo_group_index_path(@socket, :edit, ammo_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
<% end %>
|
||||
|
||||
<%= link to: "#",
|
||||
class: "text-primary-500 link",
|
||||
phx_click: "delete",
|
||||
phx_value_id: ammo_group.id,
|
||||
data: [confirm: dgettext("prompts", "Are you sure you want to delete this ammo?")] do %>
|
||||
<i class="fa-fw fa-lg fas fa-trash"></i>
|
||||
<% end %>
|
||||
<%= link to: "#",
|
||||
class: "text-primary-500 link",
|
||||
phx_click: "delete",
|
||||
phx_value_id: ammo_group.id,
|
||||
data: [confirm: dgettext("prompts", "Are you sure you want to delete this ammo?")] do %>
|
||||
<i class="fa-fw fa-lg fas fa-trash"></i>
|
||||
<% end %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@ -79,14 +113,28 @@
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:new, :edit] do %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(@socket, :index)}>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(@socket, :index)}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
||||
|
||||
<%= if @live_action in [:add_shot_group] do %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
@ -6,6 +6,7 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
|
||||
use CanneryWeb, :live_view
|
||||
import CanneryWeb.Components.ContainerCard
|
||||
alias Cannery.{Ammo, Repo}
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
@ -13,11 +14,26 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(
|
||||
%{"id" => id},
|
||||
_,
|
||||
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
|
||||
) do
|
||||
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
|
||||
socket |> assign(page_title: page_title(live_action)) |> apply_action(live_action, params)
|
||||
end
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{current_user: current_user}} = socket,
|
||||
:add_shot_group,
|
||||
%{"id" => id}
|
||||
) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Add Shot group"))
|
||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
||||
end
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{live_action: live_action, current_user: current_user}} = socket,
|
||||
action,
|
||||
%{"id" => id}
|
||||
)
|
||||
when action == :edit or action == :show do
|
||||
ammo_group = Ammo.get_ammo_group!(id, current_user) |> Repo.preload([:container, :ammo_type])
|
||||
{:noreply, socket |> assign(page_title: page_title(live_action), ammo_group: ammo_group)}
|
||||
end
|
||||
@ -36,6 +52,18 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event(
|
||||
"toggle_staged",
|
||||
_,
|
||||
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
|
||||
) do
|
||||
{:ok, ammo_group} =
|
||||
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
|
||||
|
||||
{:noreply, socket |> assign(ammo_group: ammo_group)}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: gettext("Show Ammo group")
|
||||
defp page_title(:edit), do: gettext("Edit Ammo group")
|
||||
end
|
||||
|
@ -24,6 +24,11 @@
|
||||
</div>
|
||||
|
||||
<div class="flex space-x-4 justify-center items-center text-primary-500">
|
||||
<%= live_patch(dgettext("actions", "Ammo Details"),
|
||||
to: Routes.ammo_type_show_path(@socket, :show, @ammo_group.ammo_type),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
|
||||
<%= live_patch to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
@ -35,6 +40,10 @@
|
||||
data: [confirm: dgettext("prompts", "Are you sure you want to delete this ammo?")] do %>
|
||||
<i class="fa-fw fa-lg fas fa-trash"></i>
|
||||
<% end %>
|
||||
|
||||
<button type="button" class="btn btn-primary" phx-click="toggle_staged">
|
||||
<%= if @ammo_group.staged, do: gettext("Unstage from range"), else: gettext("Stage for range") %>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr class="mb-4 w-full">
|
||||
@ -53,14 +62,28 @@
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:edit] do %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(@socket, :show, @ammo_group)}>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(@socket, :show, @ammo_group)}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
||||
|
||||
<%= if @live_action in [:add_shot_group] do %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
64
lib/cannery_web/live/range_live/form_component.ex
Normal file
64
lib/cannery_web/live/range_live/form_component.ex
Normal file
@ -0,0 +1,64 @@
|
||||
defmodule CanneryWeb.RangeLive.FormComponent do
|
||||
@moduledoc """
|
||||
Livecomponent that can update or create a ShotGroup
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo, Ammo.AmmoGroup}
|
||||
alias Phoenix.LiveView.Socket
|
||||
|
||||
@impl true
|
||||
@spec update(
|
||||
%{
|
||||
required(:shot_group) => ShotGroup.t(),
|
||||
required(:current_user) => User.t(),
|
||||
optional(:ammo_group) => AmmoGroup.t(),
|
||||
optional(any()) => any()
|
||||
},
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(
|
||||
%{
|
||||
shot_group: %ShotGroup{ammo_group_id: ammo_group_id} = shot_group,
|
||||
current_user: current_user
|
||||
} = assigns,
|
||||
socket
|
||||
) do
|
||||
changeset = shot_group |> ActivityLog.change_shot_group()
|
||||
ammo_group = Ammo.get_ammo_group!(ammo_group_id, current_user)
|
||||
{:ok, socket |> assign(assigns) |> assign(ammo_group: ammo_group, changeset: changeset)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event(
|
||||
"validate",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{assigns: %{shot_group: shot_group}} = socket
|
||||
) do
|
||||
changeset =
|
||||
shot_group
|
||||
|> ActivityLog.change_shot_group(shot_group_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
end
|
||||
|
||||
def handle_event(
|
||||
"save",
|
||||
%{"shot_group" => shot_group_params},
|
||||
%{assigns: %{shot_group: shot_group, current_user: current_user, return_to: return_to}} =
|
||||
socket
|
||||
) do
|
||||
socket =
|
||||
case ActivityLog.update_shot_group(shot_group, shot_group_params, current_user) do
|
||||
{:ok, _shot_group} ->
|
||||
prompt = dgettext("prompts", "Shot records updated successfully")
|
||||
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
socket |> assign(:changeset, changeset)
|
||||
end
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
45
lib/cannery_web/live/range_live/form_component.html.heex
Normal file
45
lib/cannery_web/live/range_live/form_component.html.heex
Normal file
@ -0,0 +1,45 @@
|
||||
<div>
|
||||
<h2 class="text-center title text-xl text-primary-500">
|
||||
<%= @title %>
|
||||
</h2>
|
||||
|
||||
<.form
|
||||
let={f}
|
||||
for={@changeset}
|
||||
id="shot-group-form"
|
||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
<%= unless @changeset.valid? do %>
|
||||
<div class="invalid-feedback col-span-3 text-center">
|
||||
<%= changeset_errors(@changeset) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label(f, :count, gettext("Shots fired"), class: "title text-lg text-primary-500") %>
|
||||
<%= number_input(f, :count,
|
||||
min: 1,
|
||||
max: @shot_group.count + @ammo_group.count,
|
||||
class: "input input-primary col-span-2"
|
||||
) %>
|
||||
<%= error_tag(f, :count, "col-span-3") %>
|
||||
|
||||
<%= label(f, :notes, gettext("Notes"), class: "title text-lg text-primary-500") %>
|
||||
<%= textarea(f, :notes,
|
||||
class: "input input-primary col-span-2",
|
||||
phx_hook: "MaintainAttrs"
|
||||
) %>
|
||||
<%= error_tag(f, :notes, "col-span-3") %>
|
||||
|
||||
<%= label(f, :date, gettext("Date (UTC)"), class: "title text-lg text-primary-500") %>
|
||||
<%= date_input(f, :date, class: "input input-primary col-span-2") %>
|
||||
<%= error_tag(f, :notes, "col-span-3") %>
|
||||
|
||||
<%= submit(dgettext("actions", "Save"),
|
||||
class: "mx-auto btn btn-primary col-span-3",
|
||||
phx_disable_with: dgettext("prompts", "Saving...")
|
||||
) %>
|
||||
</.form>
|
||||
</div>
|
82
lib/cannery_web/live/range_live/index.ex
Normal file
82
lib/cannery_web/live/range_live/index.ex
Normal file
@ -0,0 +1,82 @@
|
||||
defmodule CanneryWeb.RangeLive.Index do
|
||||
@moduledoc """
|
||||
Main page for range day mode, where `AmmoGroup`s can be used up.
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
import CanneryWeb.Components.AmmoGroupCard
|
||||
alias Cannery.{ActivityLog, ActivityLog.ShotGroup, Ammo, Repo}
|
||||
alias CanneryWeb.Endpoint
|
||||
alias Phoenix.LiveView.Socket
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
{:ok, socket |> assign_defaults(session) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
|
||||
{:noreply, apply_action(socket, live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{current_user: current_user}} = socket,
|
||||
:add_shot_group,
|
||||
%{"id" => id}
|
||||
) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Record shots"))
|
||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Edit Shot Records"))
|
||||
|> assign(:shot_group, ActivityLog.get_shot_group!(id, current_user))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("New Shot Records"))
|
||||
|> assign(:shot_group, %ShotGroup{})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Shot Records"))
|
||||
|> assign(:shot_group, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do
|
||||
{:ok, _} =
|
||||
ActivityLog.get_shot_group!(id, current_user)
|
||||
|> ActivityLog.delete_shot_group(current_user)
|
||||
|
||||
prompt = dgettext("prompts", "Shot records deleted succesfully")
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
def handle_event(
|
||||
"toggle_staged",
|
||||
%{"ammo_group_id" => ammo_group_id},
|
||||
%{assigns: %{current_user: current_user}} = socket
|
||||
) do
|
||||
ammo_group = Ammo.get_ammo_group!(ammo_group_id, current_user)
|
||||
|
||||
{:ok, _ammo_group} =
|
||||
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
|
||||
|
||||
prompt = dgettext("prompts", "Ammo group unstaged succesfully")
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
@spec display_shot_groups(Socket.t()) :: Socket.t()
|
||||
defp display_shot_groups(%{assigns: %{current_user: current_user}} = socket) do
|
||||
shot_groups =
|
||||
ActivityLog.list_shot_groups(current_user) |> Repo.preload(ammo_group: :ammo_type)
|
||||
|
||||
ammo_groups = Ammo.list_staged_ammo_groups(current_user)
|
||||
socket |> assign(shot_groups: shot_groups, ammo_groups: ammo_groups)
|
||||
end
|
||||
end
|
135
lib/cannery_web/live/range_live/index.html.heex
Normal file
135
lib/cannery_web/live/range_live/index.html.heex
Normal file
@ -0,0 +1,135 @@
|
||||
<div class="mx-8 flex flex-col space-y-8 justify-center items-center">
|
||||
<h1 class="title text-2xl title-primary-500">
|
||||
<%= gettext("Range day") %>
|
||||
</h1>
|
||||
|
||||
<%= if @ammo_groups |> Enum.empty?() do %>
|
||||
<h1 class="title text-xl text-primary-500">
|
||||
<%= gettext("No ammo staged") %> 😔
|
||||
</h1>
|
||||
|
||||
<%= live_patch(dgettext("actions", "Why not get some ready to shoot?"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :index),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% else %>
|
||||
<%= live_patch(dgettext("actions", "Stage ammo"),
|
||||
to: Routes.ammo_group_index_path(Endpoint, :index),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
|
||||
<%= for ammo_group <- @ammo_groups do %>
|
||||
<.ammo_group_card ammo_group={ammo_group}>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="toggle_staged"
|
||||
phx-value-ammo_group_id={ammo_group.id}
|
||||
data-confirm={"#{dgettext("prompts", "Are you sure you want to unstage this ammo?")}"}
|
||||
>
|
||||
<%= if ammo_group.staged, do: gettext("Unstage from range"), else: gettext("Stage for range") %>
|
||||
</button>
|
||||
|
||||
<%= live_patch(dgettext("actions", "Record shots"),
|
||||
to: Routes.range_index_path(Endpoint, :add_shot_group, ammo_group),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</.ammo_group_card>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<hr class="hr">
|
||||
|
||||
<%= if @shot_groups |> Enum.empty?() do %>
|
||||
<h1 class="title text-xl text-primary-500">
|
||||
<%= gettext("No shots recorded") %> 😔
|
||||
</h1>
|
||||
<% else %>
|
||||
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
|
||||
<table class="min-w-full table-auto text-center bg-white">
|
||||
<thead class="border-b border-primary-600">
|
||||
<tr>
|
||||
<th class="p-2">
|
||||
<%= gettext("Ammo") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Rounds shot") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Notes") %>
|
||||
</th>
|
||||
<th class="p-2">
|
||||
<%= gettext("Date") %>
|
||||
</th>
|
||||
|
||||
<th class="p-2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="shot_groups">
|
||||
<%= for shot_group <- @shot_groups do %>
|
||||
<tr id={"shot_group-#{shot_group.id}"}>
|
||||
<td class="p-2">
|
||||
<%= live_patch(shot_group.ammo_group.ammo_type.name,
|
||||
to: Routes.ammo_group_show_path(Endpoint, :show, shot_group.ammo_group),
|
||||
class: "link"
|
||||
) %>
|
||||
</td>
|
||||
<td class="p-2">
|
||||
<%= shot_group.count %>
|
||||
</td>
|
||||
<td class="p-2">
|
||||
<%= shot_group.notes %>
|
||||
</td>
|
||||
<td class="p-2">
|
||||
<%= shot_group.date |> display_date() %>
|
||||
</td>
|
||||
|
||||
<td class="p-2 w-full h-full space-x-2 flex justify-center items-center">
|
||||
<%= live_patch to: Routes.range_index_path(Endpoint, :edit, shot_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
<% end %>
|
||||
|
||||
<%= link to: "#",
|
||||
class: "text-primary-500 link",
|
||||
phx_click: "delete",
|
||||
phx_value_id: shot_group.id,
|
||||
data: [confirm: dgettext("prompts", "Are you sure you want to delete this shot record?")] do %>
|
||||
<i class="fa-fw fa-lg fas fa-trash"></i>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:edit] do %>
|
||||
<.modal return_to={Routes.range_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.RangeLive.FormComponent}
|
||||
id={@shot_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
shot_group={@shot_group}
|
||||
return_to={Routes.range_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
||||
|
||||
<%= if @live_action in [:add_shot_group] do %>
|
||||
<.modal return_to={Routes.range_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.range_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
@ -72,9 +72,15 @@ defmodule CanneryWeb.Router do
|
||||
live "/ammo_groups", AmmoGroupLive.Index, :index
|
||||
live "/ammo_groups/new", AmmoGroupLive.Index, :new
|
||||
live "/ammo_groups/:id/edit", AmmoGroupLive.Index, :edit
|
||||
live "/ammo_groups/:id/add_shot_group", AmmoGroupLive.Index, :add_shot_group
|
||||
|
||||
live "/ammo_groups/:id", AmmoGroupLive.Show, :show
|
||||
live "/ammo_groups/:id/show/edit", AmmoGroupLive.Show, :edit
|
||||
live "/ammo_groups/:id/show/add_shot_group", AmmoGroupLive.Show, :add_shot_group
|
||||
|
||||
live "/range", RangeLive.Index, :index
|
||||
live "/range/:id/edit", RangeLive.Index, :edit
|
||||
live "/range/:id/add_shot_group", RangeLive.Index, :add_shot_group
|
||||
end
|
||||
|
||||
scope "/", CanneryWeb do
|
||||
|
Reference in New Issue
Block a user