shot groups to shot records
This commit is contained in:
@ -27,7 +27,7 @@ defmodule CanneryWeb.PackLive.Index do
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{current_user: current_user}} = socket,
|
||||
:add_shot_group,
|
||||
:add_shot_record,
|
||||
%{"id" => id}
|
||||
) do
|
||||
socket
|
||||
|
@ -121,7 +121,7 @@
|
||||
</button>
|
||||
|
||||
<.link
|
||||
patch={Routes.pack_index_path(Endpoint, :add_shot_group, pack)}
|
||||
patch={Routes.pack_index_path(Endpoint, :add_shot_record, pack)}
|
||||
class="mx-2 my-1 text-sm btn btn-primary"
|
||||
>
|
||||
<%= dgettext("actions", "Record shots") %>
|
||||
@ -213,10 +213,10 @@
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% :add_shot_group -> %>
|
||||
<% :add_shot_record -> %>
|
||||
<.modal return_to={Routes.pack_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
module={CanneryWeb.Components.AddShotRecordComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
|
@ -4,7 +4,7 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_view
|
||||
alias Cannery.{ActivityLog, ActivityLog.ShotGroup}
|
||||
alias Cannery.{ActivityLog, ActivityLog.ShotRecord}
|
||||
alias Cannery.{Ammo, Ammo.Pack}
|
||||
alias Cannery.{ComparableDate, Containers}
|
||||
alias CanneryWeb.Endpoint
|
||||
@ -15,15 +15,15 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
|
||||
@impl true
|
||||
def handle_params(
|
||||
%{"id" => id, "shot_group_id" => shot_group_id},
|
||||
%{"id" => id, "shot_record_id" => shot_record_id},
|
||||
_url,
|
||||
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
|
||||
) do
|
||||
shot_group = ActivityLog.get_shot_group!(shot_group_id, current_user)
|
||||
shot_record = ActivityLog.get_shot_record!(shot_record_id, current_user)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(page_title: page_title(live_action), shot_group: shot_group)
|
||||
|> assign(page_title: page_title(live_action), shot_record: shot_record)
|
||||
|> display_pack(id)
|
||||
|
||||
{:noreply, socket}
|
||||
@ -38,8 +38,8 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp page_title(:add_shot_group), do: gettext("Record Shots")
|
||||
defp page_title(:edit_shot_group), do: gettext("Edit Shot Records")
|
||||
defp page_title(:add_shot_record), do: gettext("Record Shots")
|
||||
defp page_title(:edit_shot_record), do: gettext("Edit Shot Records")
|
||||
defp page_title(:move), do: gettext("Move Ammo")
|
||||
defp page_title(:show), do: gettext("Show Ammo")
|
||||
defp page_title(:edit), do: gettext("Edit Ammo")
|
||||
@ -69,13 +69,13 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
end
|
||||
|
||||
def handle_event(
|
||||
"delete_shot_group",
|
||||
"delete_shot_record",
|
||||
%{"id" => id},
|
||||
%{assigns: %{pack: %{id: pack_id}, current_user: current_user}} = socket
|
||||
) do
|
||||
{:ok, _} =
|
||||
ActivityLog.get_shot_group!(id, current_user)
|
||||
|> ActivityLog.delete_shot_group(current_user)
|
||||
ActivityLog.get_shot_record!(id, current_user)
|
||||
|> ActivityLog.delete_shot_record(current_user)
|
||||
|
||||
prompt = dgettext("prompts", "Shot records deleted succesfully")
|
||||
{:noreply, socket |> put_flash(:info, prompt) |> display_pack(pack_id)}
|
||||
@ -93,12 +93,12 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
%{label: gettext("Actions"), key: :actions, sortable: false}
|
||||
]
|
||||
|
||||
shot_groups = ActivityLog.list_shot_groups_for_pack(pack, current_user)
|
||||
shot_records = ActivityLog.list_shot_records_for_pack(pack, current_user)
|
||||
|
||||
rows =
|
||||
shot_groups
|
||||
|> Enum.map(fn shot_group ->
|
||||
pack |> get_table_row_for_shot_group(shot_group, columns)
|
||||
shot_records
|
||||
|> Enum.map(fn shot_record ->
|
||||
pack |> get_table_row_for_shot_record(shot_record, columns)
|
||||
end)
|
||||
|
||||
socket
|
||||
@ -107,7 +107,7 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
original_count: Ammo.get_original_count(pack, current_user),
|
||||
percentage_remaining: Ammo.get_percentage_remaining(pack, current_user),
|
||||
container: container_id && Containers.get_container!(container_id, current_user),
|
||||
shot_groups: shot_groups,
|
||||
shot_records: shot_records,
|
||||
columns: columns,
|
||||
rows: rows
|
||||
)
|
||||
@ -119,9 +119,9 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
@spec display_currency(float()) :: String.t()
|
||||
defp display_currency(float), do: :erlang.float_to_binary(float, decimals: 2)
|
||||
|
||||
@spec get_table_row_for_shot_group(Pack.t(), ShotGroup.t(), [map()]) :: map()
|
||||
defp get_table_row_for_shot_group(pack, %{id: id, date: date} = shot_group, columns) do
|
||||
assigns = %{pack: pack, shot_group: shot_group}
|
||||
@spec get_table_row_for_shot_record(Pack.t(), ShotRecord.t(), [map()]) :: map()
|
||||
defp get_table_row_for_shot_record(pack, %{id: id, date: date} = shot_record, columns) do
|
||||
assigns = %{pack: pack, shot_record: shot_record}
|
||||
|
||||
columns
|
||||
|> Map.new(fn %{key: key} ->
|
||||
@ -139,11 +139,11 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
~H"""
|
||||
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
|
||||
<.link
|
||||
patch={Routes.pack_show_path(Endpoint, :edit_shot_group, @pack, @shot_group)}
|
||||
patch={Routes.pack_show_path(Endpoint, :edit_shot_record, @pack, @shot_record)}
|
||||
class="text-primary-600 link"
|
||||
aria-label={
|
||||
dgettext("actions", "Edit shot group of %{shot_group_count} shots",
|
||||
shot_group_count: @shot_group.count
|
||||
dgettext("actions", "Edit shot record of %{shot_record_count} shots",
|
||||
shot_record_count: @shot_record.count
|
||||
)
|
||||
}
|
||||
>
|
||||
@ -153,12 +153,12 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
<.link
|
||||
href="#"
|
||||
class="text-primary-600 link"
|
||||
phx-click="delete_shot_group"
|
||||
phx-value-id={@shot_group.id}
|
||||
phx-click="delete_shot_record"
|
||||
phx-value-id={@shot_record.id}
|
||||
data-confirm={dgettext("prompts", "Are you sure you want to delete this shot record?")}
|
||||
aria-label={
|
||||
dgettext("actions", "Delete shot record of %{shot_group_count} shots",
|
||||
shot_group_count: @shot_group.count
|
||||
dgettext("actions", "Delete shot record of %{shot_record_count} shots",
|
||||
shot_record_count: @shot_record.count
|
||||
)
|
||||
}
|
||||
>
|
||||
@ -168,7 +168,7 @@ defmodule CanneryWeb.PackLive.Show do
|
||||
"""
|
||||
|
||||
key ->
|
||||
shot_group |> Map.get(key)
|
||||
shot_record |> Map.get(key)
|
||||
end
|
||||
|
||||
{key, value}
|
||||
|
@ -90,7 +90,7 @@
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
patch={Routes.pack_show_path(Endpoint, :add_shot_group, @pack)}
|
||||
patch={Routes.pack_show_path(Endpoint, :add_shot_record, @pack)}
|
||||
class="mx-4 my-2 btn btn-primary"
|
||||
>
|
||||
<%= dgettext("actions", "Record shots") %>
|
||||
@ -112,7 +112,7 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= unless @shot_groups |> Enum.empty?() do %>
|
||||
<%= unless @shot_records |> Enum.empty?() do %>
|
||||
<hr class="mb-4 w-full" />
|
||||
|
||||
<h1 class="mb-4 px-4 py-2 text-center rounded-lg title text-xl">
|
||||
@ -121,7 +121,7 @@
|
||||
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.TableComponent}
|
||||
id="pack_shot_groups_table"
|
||||
id="pack_shot_records_table"
|
||||
columns={@columns}
|
||||
rows={@rows}
|
||||
/>
|
||||
@ -141,22 +141,22 @@
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% :edit_shot_group -> %>
|
||||
<% :edit_shot_record -> %>
|
||||
<.modal return_to={Routes.pack_show_path(Endpoint, :show, @pack)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.RangeLive.FormComponent}
|
||||
id={@shot_group.id}
|
||||
id={@shot_record.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
shot_group={@shot_group}
|
||||
shot_record={@shot_record}
|
||||
return_to={Routes.pack_show_path(Endpoint, :show, @pack)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% :add_shot_group -> %>
|
||||
<% :add_shot_record -> %>
|
||||
<.modal return_to={Routes.pack_show_path(Endpoint, :show, @pack)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
module={CanneryWeb.Components.AddShotRecordComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
|
Reference in New Issue
Block a user