forked from shibao/cannery
rename ammo groups to packs
This commit is contained in:
@ -4,33 +4,33 @@ defmodule CanneryWeb.RangeLive.FormComponent do
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo, Ammo.AmmoGroup}
|
||||
alias Cannery.{Accounts.User, ActivityLog, ActivityLog.ShotGroup, Ammo, Ammo.Pack}
|
||||
alias Ecto.Changeset
|
||||
alias Phoenix.LiveView.Socket
|
||||
|
||||
@impl true
|
||||
def mount(socket), do: {:ok, socket |> assign(:ammo_group, nil)}
|
||||
def mount(socket), do: {:ok, socket |> assign(:pack, nil)}
|
||||
|
||||
@impl true
|
||||
@spec update(
|
||||
%{
|
||||
required(:shot_group) => ShotGroup.t(),
|
||||
required(:current_user) => User.t(),
|
||||
optional(:ammo_group) => AmmoGroup.t(),
|
||||
optional(:pack) => Pack.t(),
|
||||
optional(any()) => any()
|
||||
},
|
||||
Socket.t()
|
||||
) :: {:ok, Socket.t()}
|
||||
def update(
|
||||
%{
|
||||
shot_group: %ShotGroup{ammo_group_id: ammo_group_id},
|
||||
shot_group: %ShotGroup{pack_id: pack_id},
|
||||
current_user: current_user
|
||||
} = assigns,
|
||||
socket
|
||||
)
|
||||
when is_binary(ammo_group_id) do
|
||||
ammo_group = Ammo.get_ammo_group!(ammo_group_id, current_user)
|
||||
{:ok, socket |> assign(assigns) |> assign(:ammo_group, ammo_group) |> assign_changeset(%{})}
|
||||
when is_binary(pack_id) do
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
{:ok, socket |> assign(assigns) |> assign(:pack, pack) |> assign_changeset(%{})}
|
||||
end
|
||||
|
||||
def update(%{shot_group: %ShotGroup{}} = assigns, socket) do
|
||||
@ -66,7 +66,7 @@ defmodule CanneryWeb.RangeLive.FormComponent do
|
||||
assigns: %{
|
||||
action: live_action,
|
||||
current_user: user,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
}
|
||||
} = socket,
|
||||
@ -81,7 +81,7 @@ defmodule CanneryWeb.RangeLive.FormComponent do
|
||||
|
||||
changeset =
|
||||
case default_action do
|
||||
:insert -> shot_group |> ShotGroup.create_changeset(user, ammo_group, shot_group_params)
|
||||
:insert -> shot_group |> ShotGroup.create_changeset(user, pack, shot_group_params)
|
||||
:update -> shot_group |> ShotGroup.update_changeset(user, shot_group_params)
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
<%= label(f, :count, gettext("Shots fired"), class: "title text-lg text-primary-600") %>
|
||||
<%= number_input(f, :count,
|
||||
min: 1,
|
||||
max: @shot_group.count + @ammo_group.count,
|
||||
max: @shot_group.count + @pack.count,
|
||||
class: "input input-primary col-span-2"
|
||||
) %>
|
||||
<%= error_tag(f, :count, "col-span-3") %>
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule CanneryWeb.RangeLive.Index do
|
||||
@moduledoc """
|
||||
Main page for range day mode, where `AmmoGroup`s can be used up.
|
||||
Main page for range day mode, where `Pack`s can be used up.
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
@ -30,7 +30,7 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
socket
|
||||
|> assign(
|
||||
page_title: gettext("Record Shots"),
|
||||
ammo_group: Ammo.get_ammo_group!(id, current_user)
|
||||
pack: Ammo.get_pack!(id, current_user)
|
||||
)
|
||||
end
|
||||
|
||||
@ -82,13 +82,12 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
|
||||
def handle_event(
|
||||
"toggle_staged",
|
||||
%{"ammo_group_id" => ammo_group_id},
|
||||
%{"pack_id" => pack_id},
|
||||
%{assigns: %{current_user: current_user}} = socket
|
||||
) do
|
||||
ammo_group = Ammo.get_ammo_group!(ammo_group_id, current_user)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
|
||||
{:ok, _ammo_group} =
|
||||
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
|
||||
{:ok, _pack} = pack |> Ammo.update_pack(%{"staged" => !pack.staged}, current_user)
|
||||
|
||||
prompt = dgettext("prompts", "Ammo unstaged succesfully")
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> display_shot_groups()}
|
||||
@ -123,15 +122,15 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
%{assigns: %{class: class, search: search, current_user: current_user}} = socket
|
||||
) do
|
||||
shot_groups = ActivityLog.list_shot_groups(search, class, current_user)
|
||||
ammo_groups = Ammo.list_staged_ammo_groups(current_user)
|
||||
packs = Ammo.list_staged_packs(current_user)
|
||||
chart_data = shot_groups |> get_chart_data_for_shot_group()
|
||||
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)
|
||||
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)
|
||||
|
||||
socket
|
||||
|> assign(
|
||||
ammo_groups: ammo_groups,
|
||||
packs: packs,
|
||||
original_counts: original_counts,
|
||||
cprs: cprs,
|
||||
last_used_dates: last_used_dates,
|
||||
|
@ -3,43 +3,43 @@
|
||||
<%= gettext("Range day") %>
|
||||
</h1>
|
||||
|
||||
<%= if @ammo_groups |> Enum.empty?() do %>
|
||||
<%= if @packs |> Enum.empty?() do %>
|
||||
<h1 class="title text-xl text-primary-600">
|
||||
<%= gettext("No ammo staged") %>
|
||||
<%= display_emoji("😔") %>
|
||||
</h1>
|
||||
|
||||
<.link navigate={Routes.ammo_group_index_path(Endpoint, :index)} class="btn btn-primary">
|
||||
<.link navigate={Routes.pack_index_path(Endpoint, :index)} class="btn btn-primary">
|
||||
<%= dgettext("actions", "Why not get some ready to shoot?") %>
|
||||
</.link>
|
||||
<% else %>
|
||||
<.link navigate={Routes.ammo_group_index_path(Endpoint, :index)} class="btn btn-primary">
|
||||
<.link navigate={Routes.pack_index_path(Endpoint, :index)} class="btn btn-primary">
|
||||
<%= dgettext("actions", "Stage ammo") %>
|
||||
</.link>
|
||||
|
||||
<div class="w-full flex flex-row flex-wrap justify-center items-stretch">
|
||||
<.ammo_group_card
|
||||
:for={%{id: ammo_group_id} = ammo_group <- @ammo_groups}
|
||||
ammo_group={ammo_group}
|
||||
original_count={Map.fetch!(@original_counts, ammo_group_id)}
|
||||
cpr={Map.get(@cprs, ammo_group_id)}
|
||||
last_used_date={Map.get(@last_used_dates, ammo_group_id)}
|
||||
:for={%{id: pack_id} = pack <- @packs}
|
||||
pack={pack}
|
||||
original_count={Map.fetch!(@original_counts, pack_id)}
|
||||
cpr={Map.get(@cprs, pack_id)}
|
||||
last_used_date={Map.get(@last_used_dates, pack_id)}
|
||||
current_user={@current_user}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
phx-click="toggle_staged"
|
||||
phx-value-ammo_group_id={ammo_group.id}
|
||||
phx-value-pack_id={pack.id}
|
||||
data-confirm={"#{dgettext("prompts", "Are you sure you want to unstage this ammo?")}"}
|
||||
>
|
||||
<%= if ammo_group.staged,
|
||||
<%= if pack.staged,
|
||||
do: dgettext("actions", "Unstage from range"),
|
||||
else: dgettext("actions", "Stage for range") %>
|
||||
</button>
|
||||
|
||||
<.link
|
||||
patch={Routes.range_index_path(Endpoint, :add_shot_group, ammo_group)}
|
||||
patch={Routes.range_index_path(Endpoint, :add_shot_group, pack)}
|
||||
class="btn btn-primary"
|
||||
>
|
||||
<%= dgettext("actions", "Record shots") %>
|
||||
@ -186,7 +186,7 @@
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
pack={@pack}
|
||||
return_to={Routes.range_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
|
Reference in New Issue
Block a user