diff --git a/lib/cannery_web/live/ammo_group_live/show.ex b/lib/cannery_web/live/ammo_group_live/show.ex index a3da36f9..e6f10533 100644 --- a/lib/cannery_web/live/ammo_group_live/show.ex +++ b/lib/cannery_web/live/ammo_group_live/show.ex @@ -5,8 +5,9 @@ defmodule CanneryWeb.AmmoGroupLive.Show do use CanneryWeb, :live_view import CanneryWeb.Components.ContainerCard - alias Cannery.{Ammo, Repo} + alias Cannery.{ActivityLog, Ammo, Ammo.AmmoGroup, Repo} alias CanneryWeb.Endpoint + alias Phoenix.LiveView.Socket @impl true def mount(_params, session, socket) do @@ -15,14 +16,31 @@ defmodule CanneryWeb.AmmoGroupLive.Show do @impl true def handle_params( - %{"id" => id}, + %{"id" => id, "shot_group_id" => shot_group_id}, _url, %{assigns: %{live_action: live_action, current_user: current_user}} = socket ) 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)} + shot_group = ActivityLog.get_shot_group!(shot_group_id, current_user) + + socket = + socket + |> assign(page_title: page_title(live_action), shot_group: shot_group) + |> display_ammo_group(id) + + {:noreply, socket} end + @impl true + def handle_params(%{"id" => id}, _url, %{assigns: %{live_action: live_action}} = socket) do + {:noreply, socket |> assign(page_title: page_title(live_action)) |> display_ammo_group(id)} + 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(:move), do: gettext("Move Ammo group") + defp page_title(:show), do: gettext("Show Ammo group") + defp page_title(:edit), do: gettext("Edit Ammo group") + @impl true def handle_event( "delete", @@ -46,11 +64,29 @@ defmodule CanneryWeb.AmmoGroupLive.Show do {:ok, ammo_group} = ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user) - {:noreply, socket |> assign(ammo_group: ammo_group)} + {:noreply, socket |> display_ammo_group(ammo_group)} end - defp page_title(:add_shot_group), do: gettext("Add Shot group") - defp page_title(:move), do: gettext("Move Ammo group") - defp page_title(:show), do: gettext("Show Ammo group") - defp page_title(:edit), do: gettext("Edit Ammo group") + @impl true + def handle_event( + "delete_shot_group", + %{"id" => id}, + %{assigns: %{ammo_group: ammo_group, 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_ammo_group(ammo_group)} + end + + @spec display_ammo_group(Socket.t(), AmmoGroup.t() | AmmoGroup.id()) :: Socket.t() + defp display_ammo_group(socket, %AmmoGroup{} = ammo_group) do + ammo_group = ammo_group |> Repo.preload([:container, :ammo_type, :shot_groups], force: true) + socket |> assign(:ammo_group, ammo_group) + end + + defp display_ammo_group(%{assigns: %{current_user: current_user}} = socket, id), + do: display_ammo_group(socket, Ammo.get_ammo_group!(id, current_user)) end diff --git a/lib/cannery_web/live/ammo_group_live/show.html.heex b/lib/cannery_web/live/ammo_group_live/show.html.heex index 119e6932..36a4ad87 100644 --- a/lib/cannery_web/live/ammo_group_live/show.html.heex +++ b/lib/cannery_web/live/ammo_group_live/show.html.heex @@ -124,6 +124,8 @@ <%= gettext("Date") %> + + @@ -132,12 +134,35 @@ <%= shot_group.count %> + <%= shot_group.notes %> + <%= shot_group.date |> display_date() %> + + +
+ <%= live_patch to: Routes.ammo_group_show_path(Endpoint, :edit_shot_group, @ammo_group, shot_group), + class: "text-primary-600 link", + data: [qa: "edit-#{shot_group.id}"] do %> + + <% end %> + + <%= link to: "#", + class: "text-primary-600 link", + phx_click: "delete_shot_group", + phx_value_id: shot_group.id, + data: [ + confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"), + qa: "delete-#{shot_group.id}" + ] do %> + + <% end %> +
+ <% end %> @@ -159,6 +184,18 @@ current_user={@current_user} /> + <% :edit_shot_group -> %> + <.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}> + <.live_component + module={CanneryWeb.RangeLive.FormComponent} + id={@shot_group.id} + title={@page_title} + action={@live_action} + shot_group={@shot_group} + return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)} + current_user={@current_user} + /> + <% :add_shot_group -> %> <.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}> <.live_component diff --git a/lib/cannery_web/live/range_live/index.ex b/lib/cannery_web/live/range_live/index.ex index cabded57..e0f6e64c 100644 --- a/lib/cannery_web/live/range_live/index.ex +++ b/lib/cannery_web/live/range_live/index.ex @@ -25,7 +25,7 @@ defmodule CanneryWeb.RangeLive.Index do %{"id" => id} ) do socket - |> assign(:page_title, gettext("Record shots")) + |> assign(:page_title, gettext("Record Shots")) |> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user)) end diff --git a/lib/cannery_web/router.ex b/lib/cannery_web/router.ex index eca06d97..9e704df1 100644 --- a/lib/cannery_web/router.ex +++ b/lib/cannery_web/router.ex @@ -80,6 +80,7 @@ defmodule CanneryWeb.Router do live "/ammo_groups/:id/show/edit", AmmoGroupLive.Show, :edit live "/ammo_groups/:id/show/add_shot_group", AmmoGroupLive.Show, :add_shot_group live "/ammo_groups/:id/show/move", AmmoGroupLive.Show, :move + live "/ammo_groups/:id/show/:shot_group_id/edit", AmmoGroupLive.Show, :edit_shot_group live "/range", RangeLive.Index, :index live "/range/:id/edit", RangeLive.Index, :edit diff --git a/priv/gettext/actions.pot b/priv/gettext/actions.pot index 2621bf04..5f4c0cce 100644 --- a/priv/gettext/actions.pot +++ b/priv/gettext/actions.pot @@ -11,12 +11,12 @@ msgid "" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:42 +#: lib/cannery_web/live/ammo_group_live/index.ex:44 msgid "Add Ammo" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:12 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:24 msgid "Add your first box!" msgstr "" @@ -81,7 +81,7 @@ msgid "Make your first tag!" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:17 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:42 msgid "New Ammo group" msgstr "" @@ -160,7 +160,7 @@ msgid "Why not get some ready to shoot?" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:85 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:111 #: lib/cannery_web/live/ammo_group_live/show.html.heex:86 #: lib/cannery_web/live/range_live/index.html.heex:36 msgid "Record shots" @@ -190,3 +190,9 @@ msgstr "" #: lib/cannery_web/live/invite_live/index.html.heex:33 msgid "Copy to clipboard" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/index.html.heex:18 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:36 +msgid "add a container first" +msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 3dab3e48..e059534d 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -39,7 +39,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:27 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:53 msgid "Ammo type" msgstr "" @@ -103,7 +103,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/move_ammo_group_component.html.heex:22 #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:48 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:42 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:68 msgid "Container" msgstr "" @@ -122,7 +122,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:27 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:30 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:56 msgid "Count" msgstr "" @@ -155,8 +155,8 @@ msgid "Easy to Use:" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:36 -#: lib/cannery_web/live/ammo_group_live/show.ex:55 +#: lib/cannery_web/live/ammo_group_live/index.ex:38 +#: lib/cannery_web/live/ammo_group_live/show.ex:42 msgid "Edit Ammo group" msgstr "" @@ -335,7 +335,7 @@ msgid "No ammo for this type" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/container_live/show.html.heex:77 +#: lib/cannery_web/live/container_live/show.html.heex:78 msgid "No ammo groups in this container" msgstr "" @@ -384,7 +384,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:34 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:33 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:59 msgid "Price paid" msgstr "" @@ -427,7 +427,7 @@ msgid "Settings" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/show.ex:54 +#: lib/cannery_web/live/ammo_group_live/show.ex:41 msgid "Show Ammo group" msgstr "" @@ -528,7 +528,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/topbar.ex:64 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:39 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:65 msgid "Range" msgstr "" @@ -565,15 +565,9 @@ msgstr "" msgid "Unstage from range" msgstr "" -#, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/show.ex:52 -msgid "Add Shot group" -msgstr "" - #, elixir-autogen, elixir-format #: lib/cannery_web/components/add_shot_group_component.html.heex:3 -#: lib/cannery_web/live/ammo_group_live/index.ex:24 -#: lib/cannery_web/live/range_live/index.ex:28 +#: lib/cannery_web/live/ammo_group_live/index.ex:26 msgid "Record shots" msgstr "" @@ -583,7 +577,7 @@ msgid "Ammo Types" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:47 +#: lib/cannery_web/live/ammo_group_live/index.ex:49 msgid "Ammo groups" msgstr "" @@ -594,6 +588,7 @@ msgid "Date (UTC)" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.ex:39 #: lib/cannery_web/live/range_live/index.ex:34 msgid "Edit Shot Records" msgstr "" @@ -625,8 +620,8 @@ msgid "Shot Records" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:30 -#: lib/cannery_web/live/ammo_group_live/show.ex:53 +#: lib/cannery_web/live/ammo_group_live/index.ex:32 +#: lib/cannery_web/live/ammo_group_live/show.ex:40 msgid "Move Ammo group" msgstr "" @@ -647,7 +642,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/ammo_group_card.ex:43 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:64 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:90 #: lib/cannery_web/live/ammo_group_live/show.html.heex:32 #: lib/cannery_web/live/ammo_group_live/show.html.heex:39 #: lib/cannery_web/live/ammo_type_live/show.html.heex:98 @@ -711,12 +706,12 @@ msgid "New password" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:82 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:108 msgid "Stage" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:82 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:108 msgid "Unstage" msgstr "" @@ -765,7 +760,7 @@ msgid "No cost information" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:36 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:62 msgid "% left" msgstr "" @@ -833,3 +828,9 @@ msgstr "" #: lib/cannery_web/controllers/user_reset_password_controller.ex:36 msgid "Reset your password" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.ex:38 +#: lib/cannery_web/live/range_live/index.ex:28 +msgid "Record Shots" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/actions.po b/priv/gettext/en/LC_MESSAGES/actions.po index 3d4cead1..63988065 100644 --- a/priv/gettext/en/LC_MESSAGES/actions.po +++ b/priv/gettext/en/LC_MESSAGES/actions.po @@ -12,12 +12,12 @@ msgstr "" "Plural-Forms: nplurals=2\n" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:42 +#: lib/cannery_web/live/ammo_group_live/index.ex:44 msgid "Add Ammo" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:12 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:24 msgid "Add your first box!" msgstr "" @@ -82,7 +82,7 @@ msgid "Make your first tag!" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:17 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:42 msgid "New Ammo group" msgstr "" @@ -161,7 +161,7 @@ msgid "Why not get some ready to shoot?" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:85 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:111 #: lib/cannery_web/live/ammo_group_live/show.html.heex:86 #: lib/cannery_web/live/range_live/index.html.heex:36 msgid "Record shots" @@ -191,3 +191,9 @@ msgstr "" #: lib/cannery_web/live/invite_live/index.html.heex:33 msgid "Copy to clipboard" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/index.html.heex:18 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:36 +msgid "add a container first" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 98a5412e..e5bdbf28 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -40,7 +40,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:27 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:53 msgid "Ammo type" msgstr "" @@ -104,7 +104,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/move_ammo_group_component.html.heex:22 #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:48 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:42 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:68 msgid "Container" msgstr "" @@ -123,7 +123,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:27 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:30 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:56 msgid "Count" msgstr "" @@ -156,8 +156,8 @@ msgid "Easy to Use:" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:36 -#: lib/cannery_web/live/ammo_group_live/show.ex:55 +#: lib/cannery_web/live/ammo_group_live/index.ex:38 +#: lib/cannery_web/live/ammo_group_live/show.ex:42 msgid "Edit Ammo group" msgstr "" @@ -336,7 +336,7 @@ msgid "No ammo for this type" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/container_live/show.html.heex:77 +#: lib/cannery_web/live/container_live/show.html.heex:78 msgid "No ammo groups in this container" msgstr "" @@ -385,7 +385,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/live/ammo_group_live/form_component.html.heex:34 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:33 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:59 msgid "Price paid" msgstr "" @@ -428,7 +428,7 @@ msgid "Settings" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/show.ex:54 +#: lib/cannery_web/live/ammo_group_live/show.ex:41 msgid "Show Ammo group" msgstr "" @@ -529,7 +529,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/topbar.ex:64 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:39 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:65 msgid "Range" msgstr "" @@ -566,15 +566,9 @@ msgstr "" msgid "Unstage from range" msgstr "" -#, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/show.ex:52 -msgid "Add Shot group" -msgstr "" - #, elixir-autogen, elixir-format #: lib/cannery_web/components/add_shot_group_component.html.heex:3 -#: lib/cannery_web/live/ammo_group_live/index.ex:24 -#: lib/cannery_web/live/range_live/index.ex:28 +#: lib/cannery_web/live/ammo_group_live/index.ex:26 msgid "Record shots" msgstr "" @@ -584,7 +578,7 @@ msgid "Ammo Types" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:47 +#: lib/cannery_web/live/ammo_group_live/index.ex:49 msgid "Ammo groups" msgstr "" @@ -595,6 +589,7 @@ msgid "Date (UTC)" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.ex:39 #: lib/cannery_web/live/range_live/index.ex:34 msgid "Edit Shot Records" msgstr "" @@ -626,8 +621,8 @@ msgid "Shot Records" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:30 -#: lib/cannery_web/live/ammo_group_live/show.ex:53 +#: lib/cannery_web/live/ammo_group_live/index.ex:32 +#: lib/cannery_web/live/ammo_group_live/show.ex:40 msgid "Move Ammo group" msgstr "" @@ -648,7 +643,7 @@ msgstr "" #, elixir-autogen, elixir-format #: lib/cannery_web/components/ammo_group_card.ex:43 -#: lib/cannery_web/live/ammo_group_live/index.html.heex:64 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:90 #: lib/cannery_web/live/ammo_group_live/show.html.heex:32 #: lib/cannery_web/live/ammo_group_live/show.html.heex:39 #: lib/cannery_web/live/ammo_type_live/show.html.heex:98 @@ -712,12 +707,12 @@ msgid "New password" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:82 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:108 msgid "Stage" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:82 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:108 msgid "Unstage" msgstr "" @@ -766,7 +761,7 @@ msgid "No cost information" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:36 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:62 msgid "% left" msgstr "" @@ -834,3 +829,9 @@ msgstr "" #: lib/cannery_web/controllers/user_reset_password_controller.ex:36 msgid "Reset your password" msgstr "" + +#, elixir-autogen, elixir-format, fuzzy +#: lib/cannery_web/live/ammo_group_live/show.ex:38 +#: lib/cannery_web/live/range_live/index.ex:28 +msgid "Record Shots" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/prompts.po b/priv/gettext/en/LC_MESSAGES/prompts.po index d19dcea3..d26555e3 100644 --- a/priv/gettext/en/LC_MESSAGES/prompts.po +++ b/priv/gettext/en/LC_MESSAGES/prompts.po @@ -63,18 +63,18 @@ msgid "A link to confirm your email change has been sent to the new address." msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/form_component.ex:87 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:90 msgid "Ammo group created successfully" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:54 -#: lib/cannery_web/live/ammo_group_live/show.ex:34 +#: lib/cannery_web/live/ammo_group_live/index.ex:56 +#: lib/cannery_web/live/ammo_group_live/show.ex:52 msgid "Ammo group deleted succesfully" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/form_component.ex:69 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:72 msgid "Ammo group updated successfully" msgstr "" @@ -98,7 +98,7 @@ msgid "Are you sure you want to delete the invite for %{name}?" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:120 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:146 #: lib/cannery_web/live/ammo_group_live/show.html.heex:66 #: lib/cannery_web/live/ammo_type_live/index.html.heex:75 msgid "Are you sure you want to delete this ammo?" @@ -211,11 +211,13 @@ msgid "Ammo group unstaged succesfully" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.html.heex:159 #: lib/cannery_web/live/range_live/index.html.heex:108 msgid "Are you sure you want to delete this shot record?" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.ex:80 #: lib/cannery_web/live/range_live/index.ex:56 msgid "Shot records deleted succesfully" msgstr "" @@ -244,3 +246,9 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.ex:58 msgid "%{name} removed successfully" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/index.html.heex:15 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:33 +msgid "You'll need to" +msgstr "" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index 1013ccb1..a159265c 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -62,18 +62,18 @@ msgid "A link to confirm your email change has been sent to the new address." msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/form_component.ex:87 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:90 msgid "Ammo group created successfully" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.ex:54 -#: lib/cannery_web/live/ammo_group_live/show.ex:34 +#: lib/cannery_web/live/ammo_group_live/index.ex:56 +#: lib/cannery_web/live/ammo_group_live/show.ex:52 msgid "Ammo group deleted succesfully" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/form_component.ex:69 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:72 msgid "Ammo group updated successfully" msgstr "" @@ -97,7 +97,7 @@ msgid "Are you sure you want to delete the invite for %{name}?" msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery_web/live/ammo_group_live/index.html.heex:120 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:146 #: lib/cannery_web/live/ammo_group_live/show.html.heex:66 #: lib/cannery_web/live/ammo_type_live/index.html.heex:75 msgid "Are you sure you want to delete this ammo?" @@ -210,11 +210,13 @@ msgid "Ammo group unstaged succesfully" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.html.heex:159 #: lib/cannery_web/live/range_live/index.html.heex:108 msgid "Are you sure you want to delete this shot record?" msgstr "" #, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/show.ex:80 #: lib/cannery_web/live/range_live/index.ex:56 msgid "Shot records deleted succesfully" msgstr "" @@ -243,3 +245,9 @@ msgstr "" #: lib/cannery_web/live/container_live/edit_tags_component.ex:58 msgid "%{name} removed successfully" msgstr "" + +#, elixir-autogen, elixir-format +#: lib/cannery_web/live/ammo_group_live/index.html.heex:15 +#: lib/cannery_web/live/ammo_group_live/index.html.heex:33 +msgid "You'll need to" +msgstr "" diff --git a/test/cannery_web/live/ammo_group_live_test.exs b/test/cannery_web/live/ammo_group_live_test.exs index f0bef086..c8bd6249 100644 --- a/test/cannery_web/live/ammo_group_live_test.exs +++ b/test/cannery_web/live/ammo_group_live_test.exs @@ -10,6 +10,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do @moduletag :ammo_group_live_test @shot_group_create_attrs %{"ammo_left" => 5, "notes" => "some notes"} + @shot_group_update_attrs %{"count" => 5, "notes" => "some updated notes"} @create_attrs %{count: 42, notes: "some notes", price_paid: 120.5} @update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7} # @invalid_attrs %{count: -1, notes: nil, price_paid: nil} @@ -17,7 +18,13 @@ defmodule CanneryWeb.AmmoGroupLiveTest do defp create_ammo_group(%{current_user: current_user}) do ammo_type = ammo_type_fixture(current_user) container = container_fixture(current_user) - %{ammo_group: ammo_group_fixture(ammo_type, container, current_user)} + ammo_group = ammo_group_fixture(ammo_type, container, current_user) + + shot_group = + %{"count" => 5, "date" => ~N[2022-02-13 03:17:00], "notes" => "some notes"} + |> shot_group_fixture(current_user, ammo_group) + + %{ammo_group: ammo_group, shot_group: shot_group} end describe "Index" do @@ -164,5 +171,40 @@ defmodule CanneryWeb.AmmoGroupLiveTest do assert html =~ dgettext("prompts", "Shots recorded successfully") end + + test "updates shot_group in listing", + %{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do + {:ok, index_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :edit, ammo_group)) + + assert index_live |> element("[data-qa=\"edit-#{shot_group.id}\"]") |> render_click() =~ + gettext("Edit Shot Records") + + assert_patch( + index_live, + Routes.ammo_group_show_path(conn, :edit_shot_group, ammo_group, shot_group) + ) + + # assert index_live + # |> form("#shot_group-form", shot_group: @invalid_attrs) + # |> render_change() =~ dgettext("errors", "is invalid") + + {:ok, _, html} = + index_live + |> form("#shot-group-form", shot_group: @shot_group_update_attrs) + |> render_submit() + |> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group)) + + assert html =~ dgettext("actions", "Shot records updated successfully") + assert html =~ "some updated notes" + end + + test "deletes shot_group in listing", + %{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do + {:ok, index_live, _html} = + live(conn, Routes.ammo_group_show_path(conn, :edit_shot_group, ammo_group, shot_group)) + + assert index_live |> element("[data-qa=\"delete-#{shot_group.id}\"]") |> render_click() + refute has_element?(index_live, "#shot_group-#{shot_group.id}") + end end end