add move to container button for ammo groups
This commit is contained in:
@ -17,6 +17,12 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
{:noreply, apply_action(socket, live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :move, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Move Ammo group"))
|
||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Edit Ammo group"))
|
||||
|
@ -80,7 +80,12 @@
|
||||
</td>
|
||||
|
||||
<td class="p-2">
|
||||
<%= if ammo_group.container, do: ammo_group.container.name %>
|
||||
<%= if ammo_group.container do %>
|
||||
<%= live_patch(ammo_group.container.name,
|
||||
to: Routes.ammo_group_index_path(@socket, :move, ammo_group),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<td class="p-2 w-full h-full space-x-2 flex justify-center items-center">
|
||||
@ -112,30 +117,45 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:new, :edit] do %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
||||
<%= cond do %>
|
||||
<% @live_action in [:new, :edit] -> %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<%= if @live_action in [:add_shot_group] do %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% @live_action == :add_shot_group -> %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<% @live_action == :move -> %>
|
||||
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.MoveAmmoGroupComponent}
|
||||
id={@ammo_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<% true -> %>
|
||||
<% end %>
|
||||
|
@ -14,26 +14,11 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
|
||||
socket |> assign(page_title: page_title(live_action)) |> apply_action(live_action, params)
|
||||
end
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{current_user: current_user}} = socket,
|
||||
:add_shot_group,
|
||||
%{"id" => id}
|
||||
) do
|
||||
socket
|
||||
|> assign(:page_title, gettext("Add Shot group"))
|
||||
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
|
||||
end
|
||||
|
||||
defp apply_action(
|
||||
%{assigns: %{live_action: live_action, current_user: current_user}} = socket,
|
||||
action,
|
||||
%{"id" => id}
|
||||
)
|
||||
when action == :edit or action == :show do
|
||||
def handle_params(
|
||||
%{"id" => 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)}
|
||||
end
|
||||
@ -64,6 +49,8 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
|
||||
{:noreply, socket |> assign(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")
|
||||
end
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
<div class="flex space-x-4 justify-center items-center text-primary-500">
|
||||
<%= live_patch(dgettext("actions", "Ammo Details"),
|
||||
to: Routes.ammo_type_show_path(@socket, :show, @ammo_group.ammo_type),
|
||||
to: Routes.ammo_type_show_path(Endpoint, :show, @ammo_group.ammo_type),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
|
||||
<%= live_patch to: Routes.ammo_group_show_path(@socket, :edit, @ammo_group),
|
||||
<%= live_patch to: Routes.ammo_group_show_path(Endpoint, :edit, @ammo_group),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
<% end %>
|
||||
@ -44,6 +44,11 @@
|
||||
<button type="button" class="btn btn-primary" phx-click="toggle_staged">
|
||||
<%= if @ammo_group.staged, do: gettext("Unstage from range"), else: gettext("Stage for range") %>
|
||||
</button>
|
||||
|
||||
<%= live_patch(dgettext("actions", "Move to different container"),
|
||||
to: Routes.ammo_group_show_path(Endpoint, :move, @ammo_group),
|
||||
class: "btn btn-primary"
|
||||
) %>
|
||||
</div>
|
||||
|
||||
<hr class="mb-4 w-full">
|
||||
@ -61,30 +66,45 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:edit] do %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% end %>
|
||||
<%= case @live_action do %>
|
||||
<% :edit -> %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.AmmoGroupLive.FormComponent}
|
||||
id={@ammo_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<%= if @live_action in [:add_shot_group] do %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
<% :add_shot_group -> %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.AddShotGroupComponent}
|
||||
id={:new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<% :move -> %>
|
||||
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.Components.MoveAmmoGroupComponent}
|
||||
id={@ammo_group.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
ammo_group={@ammo_group}
|
||||
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
|
||||
current_user={@current_user}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<% _show -> %>
|
||||
<% end %>
|
||||
|
Reference in New Issue
Block a user