diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f652d9..2ef938b 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 64c8f4d..7d0500d 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 cce6473..982d1c3 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 f4af43a..0c2bebc 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 cbeb288..a78c914 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 6e449f0..1884bd4 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 d7eac7a..f1c7260 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 bd2dd5a..50e7ea7 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 56a4d94..370ef1c 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 153ecaa..78a8990 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 74078df..d38b578 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 8a12206..3b181a9 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 1767772..bef6acd 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 7806b5c..b9ab00d 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 fb8dc6a..81c4660 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 069cce1..bfe606f 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 9bdca5f..4502790 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"