remove :table path

This commit is contained in:
shibao 2023-03-19 13:37:28 -04:00
parent 213dcca973
commit 40e4f6fe0a
17 changed files with 28 additions and 46 deletions

View File

@ -1,5 +1,6 @@
# v0.8.6 # v0.8.6
- Fix duplicate entries showing up - Fix duplicate entries showing up
- Show ammo groups under a type in a table by default
# v0.8.5 # v0.8.5
- Add link in readme to github mirror - Add link in readme to github mirror

View File

@ -30,17 +30,12 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
] ]
@impl true @impl true
def mount(_params, _session, %{assigns: %{live_action: live_action}} = socket), def mount(_params, _session, socket),
do: {:ok, socket |> assign(show_used: false, view_table: live_action == :table)} do: {:ok, socket |> assign(show_used: false, view_table: true)}
@impl true @impl true
def handle_params(%{"id" => id}, _params, %{assigns: %{live_action: live_action}} = socket) do def handle_params(%{"id" => id}, _params, socket) do
socket = {:noreply, socket |> display_ammo_type(id)}
socket
|> assign(view_table: live_action == :table)
|> display_ammo_type(id)
{:noreply, socket}
end end
@impl true @impl true
@ -61,23 +56,14 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
{:noreply, socket |> assign(:show_used, !show_used) |> display_ammo_type()} {:noreply, socket |> assign(:show_used, !show_used) |> display_ammo_type()}
end end
def handle_event( def handle_event("toggle_table", _params, %{assigns: %{view_table: view_table}} = socket) do
"toggle_table", {:noreply, socket |> assign(:view_table, !view_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)}
end end
defp display_ammo_type( defp display_ammo_type(
%{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} = %{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} =
socket, socket,
%AmmoType{} = ammo_type %AmmoType{name: ammo_type_name} = ammo_type
) do ) do
fields_to_display = fields_to_display =
@fields_list @fields_list
@ -112,9 +98,15 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
[nil, nil, nil, nil, nil] [nil, nil, nil, nil, nil]
end 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 socket
|> assign( |> assign(
page_title: page_title(live_action, ammo_type), page_title: page_title,
ammo_type: ammo_type, ammo_type: ammo_type,
ammo_groups: ammo_groups, ammo_groups: ammo_groups,
cprs: ammo_groups |> Ammo.get_cprs(current_user), cprs: ammo_groups |> Ammo.get_cprs(current_user),
@ -142,10 +134,4 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
@spec display_currency(float()) :: String.t() @spec display_currency(float()) :: String.t()
defp display_currency(float), do: :erlang.float_to_binary(float, decimals: 2) 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 end

View File

@ -104,7 +104,7 @@ defmodule CanneryWeb.ContainerLive.Show do
page_title = page_title =
case live_action do case live_action do
action when action in [:show, :table] -> container_name :show -> container_name
:edit -> gettext("Edit %{name}", name: container_name) :edit -> gettext("Edit %{name}", name: container_name)
:edit_tags -> gettext("Edit %{name} tags", name: container_name) :edit_tags -> gettext("Edit %{name} tags", name: container_name)
end end

View File

@ -77,7 +77,6 @@ defmodule CanneryWeb.Router do
live "/type/:id", AmmoTypeLive.Show, :show live "/type/:id", AmmoTypeLive.Show, :show
live "/type/:id/edit", AmmoTypeLive.Show, :edit live "/type/:id/edit", AmmoTypeLive.Show, :edit
live "/type/:id/table", AmmoTypeLive.Show, :table
live "/containers", ContainerLive.Index, :index live "/containers", ContainerLive.Index, :index
live "/containers/new", ContainerLive.Index, :new live "/containers/new", ContainerLive.Index, :new

View File

@ -991,7 +991,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "%{name} bearbeiten" msgstr "%{name} bearbeiten"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} erfolgreich erstellt" msgstr "%{name} erfolgreich erstellt"
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -985,7 +985,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""

View File

@ -985,7 +985,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""

View File

@ -19,7 +19,7 @@ msgid "%{name} created successfully"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -993,7 +993,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "Editar %{ammo_type_name}" msgstr "Editar %{ammo_type_name}"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} creado exitosamente" msgstr "%{name} creado exitosamente"
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -994,7 +994,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "Éditer %{name}" msgstr "Éditer %{name}"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} créé· avec succès" msgstr "%{name} créé· avec succès"
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -987,7 +987,7 @@ msgid "Average CPR"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:28 #: 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 #, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}" msgid "Edit %{ammo_type_name}"
msgstr "" msgstr ""

View File

@ -30,7 +30,7 @@ msgid "%{name} created successfully"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -19,7 +19,7 @@ msgid "%{name} created successfully"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:72 #: 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 #: lib/cannery_web/live/tag_live/index.ex:65
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{name} deleted succesfully" msgid "%{name} deleted succesfully"

View File

@ -310,8 +310,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/) |> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|> render_click() |> render_click()
assert_patch(show_live, Routes.ammo_type_show_path(conn, :table, ammo_type))
assert html =~ "some ammo group" assert html =~ "some ammo group"
assert html =~ container_name assert html =~ container_name
end end
@ -346,8 +344,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/) |> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|> render_click() |> render_click()
assert_patch(show_live, Routes.ammo_type_show_path(conn, :table, ammo_type))
assert html =~ dgettext("actions", "Show used") assert html =~ dgettext("actions", "Show used")
refute html =~ "some ammo group" refute html =~ "some ammo group"