From 40e4f6fe0a336568455e6eabbc3e4d658c2108c2 Mon Sep 17 00:00:00 2001 From: shibao Date: Sun, 19 Mar 2023 13:37:28 -0400 Subject: [PATCH] remove :table path --- CHANGELOG.md | 1 + lib/cannery_web/live/ammo_type_live/show.ex | 42 +++++++------------ lib/cannery_web/live/container_live/show.ex | 2 +- lib/cannery_web/router.ex | 1 - priv/gettext/de/LC_MESSAGES/default.po | 2 +- priv/gettext/de/LC_MESSAGES/prompts.po | 2 +- priv/gettext/default.pot | 2 +- priv/gettext/en/LC_MESSAGES/default.po | 2 +- priv/gettext/en/LC_MESSAGES/prompts.po | 2 +- priv/gettext/es/LC_MESSAGES/default.po | 2 +- priv/gettext/es/LC_MESSAGES/prompts.po | 2 +- priv/gettext/fr/LC_MESSAGES/default.po | 2 +- priv/gettext/fr/LC_MESSAGES/prompts.po | 2 +- priv/gettext/ga/LC_MESSAGES/default.po | 2 +- priv/gettext/ga/LC_MESSAGES/prompts.po | 2 +- priv/gettext/prompts.pot | 2 +- test/cannery_web/live/ammo_type_live_test.exs | 4 -- 17 files changed, 28 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f652d9b..2ef938b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # v0.8.6 - Fix duplicate entries showing up +- Show ammo groups under a type in a table by default # v0.8.5 - Add link in readme to github mirror diff --git a/lib/cannery_web/live/ammo_type_live/show.ex b/lib/cannery_web/live/ammo_type_live/show.ex index 64c8f4db..7d0500db 100644 --- a/lib/cannery_web/live/ammo_type_live/show.ex +++ b/lib/cannery_web/live/ammo_type_live/show.ex @@ -30,17 +30,12 @@ defmodule CanneryWeb.AmmoTypeLive.Show do ] @impl true - def mount(_params, _session, %{assigns: %{live_action: live_action}} = socket), - do: {:ok, socket |> assign(show_used: false, view_table: live_action == :table)} + def mount(_params, _session, socket), + do: {:ok, socket |> assign(show_used: false, view_table: true)} @impl true - def handle_params(%{"id" => id}, _params, %{assigns: %{live_action: live_action}} = socket) do - socket = - socket - |> assign(view_table: live_action == :table) - |> display_ammo_type(id) - - {:noreply, socket} + def handle_params(%{"id" => id}, _params, socket) do + {:noreply, socket |> display_ammo_type(id)} end @impl true @@ -61,23 +56,14 @@ defmodule CanneryWeb.AmmoTypeLive.Show do {:noreply, socket |> assign(:show_used, !show_used) |> display_ammo_type()} end - def handle_event( - "toggle_table", - _params, - %{assigns: %{view_table: view_table, ammo_type: ammo_type}} = socket - ) do - new_path = - if view_table, - do: Routes.ammo_type_show_path(Endpoint, :show, ammo_type), - else: Routes.ammo_type_show_path(Endpoint, :table, ammo_type) - - {:noreply, socket |> push_patch(to: new_path)} + def handle_event("toggle_table", _params, %{assigns: %{view_table: view_table}} = socket) do + {:noreply, socket |> assign(:view_table, !view_table)} end defp display_ammo_type( %{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} = socket, - %AmmoType{} = ammo_type + %AmmoType{name: ammo_type_name} = ammo_type ) do fields_to_display = @fields_list @@ -112,9 +98,15 @@ defmodule CanneryWeb.AmmoTypeLive.Show do [nil, nil, nil, nil, nil] end + page_title = + case live_action do + :show -> ammo_type_name + :edit -> gettext("Edit %{ammo_type_name}", ammo_type_name: ammo_type_name) + end + socket |> assign( - page_title: page_title(live_action, ammo_type), + page_title: page_title, ammo_type: ammo_type, ammo_groups: ammo_groups, cprs: ammo_groups |> Ammo.get_cprs(current_user), @@ -142,10 +134,4 @@ defmodule CanneryWeb.AmmoTypeLive.Show do @spec display_currency(float()) :: String.t() defp display_currency(float), do: :erlang.float_to_binary(float, decimals: 2) - - defp page_title(action, %{name: ammo_type_name}) when action in [:show, :table], - do: ammo_type_name - - defp page_title(:edit, %{name: ammo_type_name}), - do: gettext("Edit %{ammo_type_name}", ammo_type_name: ammo_type_name) end diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index cce64731..982d1c30 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -104,7 +104,7 @@ defmodule CanneryWeb.ContainerLive.Show do page_title = case live_action do - action when action in [:show, :table] -> container_name + :show -> container_name :edit -> gettext("Edit %{name}", name: container_name) :edit_tags -> gettext("Edit %{name} tags", name: container_name) end diff --git a/lib/cannery_web/router.ex b/lib/cannery_web/router.ex index f4af43a2..0c2bebca 100644 --- a/lib/cannery_web/router.ex +++ b/lib/cannery_web/router.ex @@ -77,7 +77,6 @@ defmodule CanneryWeb.Router do live "/type/:id", AmmoTypeLive.Show, :show live "/type/:id/edit", AmmoTypeLive.Show, :edit - live "/type/:id/table", AmmoTypeLive.Show, :table live "/containers", ContainerLive.Index, :index live "/containers/new", ContainerLive.Index, :new diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index cbeb288c..a78c914f 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -991,7 +991,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format, fuzzy msgid "Edit %{ammo_type_name}" msgstr "%{name} bearbeiten" diff --git a/priv/gettext/de/LC_MESSAGES/prompts.po b/priv/gettext/de/LC_MESSAGES/prompts.po index 6e449f07..1884bd4a 100644 --- a/priv/gettext/de/LC_MESSAGES/prompts.po +++ b/priv/gettext/de/LC_MESSAGES/prompts.po @@ -32,7 +32,7 @@ msgid "%{name} created successfully" msgstr "%{name} erfolgreich erstellt" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index d7eac7ab..f1c72605 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -985,7 +985,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format msgid "Edit %{ammo_type_name}" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index bd2dd5ae..50e7ea78 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -985,7 +985,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format, fuzzy msgid "Edit %{ammo_type_name}" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/prompts.po b/priv/gettext/en/LC_MESSAGES/prompts.po index 56a4d94b..370ef1ca 100644 --- a/priv/gettext/en/LC_MESSAGES/prompts.po +++ b/priv/gettext/en/LC_MESSAGES/prompts.po @@ -19,7 +19,7 @@ msgid "%{name} created successfully" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/priv/gettext/es/LC_MESSAGES/default.po b/priv/gettext/es/LC_MESSAGES/default.po index 153ecaa7..78a89902 100644 --- a/priv/gettext/es/LC_MESSAGES/default.po +++ b/priv/gettext/es/LC_MESSAGES/default.po @@ -993,7 +993,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format msgid "Edit %{ammo_type_name}" msgstr "Editar %{ammo_type_name}" diff --git a/priv/gettext/es/LC_MESSAGES/prompts.po b/priv/gettext/es/LC_MESSAGES/prompts.po index 74078df4..d38b5783 100644 --- a/priv/gettext/es/LC_MESSAGES/prompts.po +++ b/priv/gettext/es/LC_MESSAGES/prompts.po @@ -32,7 +32,7 @@ msgid "%{name} created successfully" msgstr "%{name} creado exitosamente" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 8a122064..3b181a9a 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -994,7 +994,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format, fuzzy msgid "Edit %{ammo_type_name}" msgstr "Éditer %{name}" diff --git a/priv/gettext/fr/LC_MESSAGES/prompts.po b/priv/gettext/fr/LC_MESSAGES/prompts.po index 17677720..bef6acd3 100644 --- a/priv/gettext/fr/LC_MESSAGES/prompts.po +++ b/priv/gettext/fr/LC_MESSAGES/prompts.po @@ -32,7 +32,7 @@ msgid "%{name} created successfully" msgstr "%{name} créé· avec succès" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/priv/gettext/ga/LC_MESSAGES/default.po b/priv/gettext/ga/LC_MESSAGES/default.po index 7806b5ca..b9ab00db 100644 --- a/priv/gettext/ga/LC_MESSAGES/default.po +++ b/priv/gettext/ga/LC_MESSAGES/default.po @@ -987,7 +987,7 @@ msgid "Average CPR" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:28 -#: lib/cannery_web/live/ammo_type_live/show.ex:150 +#: lib/cannery_web/live/ammo_type_live/show.ex:104 #, elixir-autogen, elixir-format, fuzzy msgid "Edit %{ammo_type_name}" msgstr "" diff --git a/priv/gettext/ga/LC_MESSAGES/prompts.po b/priv/gettext/ga/LC_MESSAGES/prompts.po index fb8dc6ac..81c46602 100644 --- a/priv/gettext/ga/LC_MESSAGES/prompts.po +++ b/priv/gettext/ga/LC_MESSAGES/prompts.po @@ -30,7 +30,7 @@ msgid "%{name} created successfully" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index 069cce1c..bfe606f4 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -19,7 +19,7 @@ msgid "%{name} created successfully" msgstr "" #: lib/cannery_web/live/ammo_type_live/index.ex:72 -#: lib/cannery_web/live/ammo_type_live/show.ex:54 +#: lib/cannery_web/live/ammo_type_live/show.ex:49 #: lib/cannery_web/live/tag_live/index.ex:65 #, elixir-autogen, elixir-format msgid "%{name} deleted succesfully" diff --git a/test/cannery_web/live/ammo_type_live_test.exs b/test/cannery_web/live/ammo_type_live_test.exs index 9bdca5ff..45027908 100644 --- a/test/cannery_web/live/ammo_type_live_test.exs +++ b/test/cannery_web/live/ammo_type_live_test.exs @@ -310,8 +310,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do |> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/) |> render_click() - assert_patch(show_live, Routes.ammo_type_show_path(conn, :table, ammo_type)) - assert html =~ "some ammo group" assert html =~ container_name end @@ -346,8 +344,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do |> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/) |> render_click() - assert_patch(show_live, Routes.ammo_type_show_path(conn, :table, ammo_type)) - assert html =~ dgettext("actions", "Show used") refute html =~ "some ammo group"