add cloning to containers index
This commit is contained in:
@ -35,15 +35,18 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
|
||||
container_params
|
||||
) do
|
||||
changeset_action =
|
||||
case action do
|
||||
:new -> :insert
|
||||
:edit -> :update
|
||||
cond do
|
||||
action in [:new, :clone] -> :insert
|
||||
action == :edit -> :update
|
||||
end
|
||||
|
||||
changeset =
|
||||
case action do
|
||||
:new -> container |> Container.create_changeset(user, container_params)
|
||||
:edit -> container |> Container.update_changeset(container_params)
|
||||
cond do
|
||||
action in [:new, :clone] ->
|
||||
container |> Container.create_changeset(user, container_params)
|
||||
|
||||
action == :edit ->
|
||||
container |> Container.update_changeset(container_params)
|
||||
end
|
||||
|
||||
changeset =
|
||||
@ -76,9 +79,10 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
|
||||
|
||||
defp save_container(
|
||||
%{assigns: %{current_user: current_user, return_to: return_to}} = socket,
|
||||
:new,
|
||||
action,
|
||||
container_params
|
||||
) do
|
||||
)
|
||||
when action in [:new, :clone] do
|
||||
socket =
|
||||
case Containers.create_container(container_params, current_user) do
|
||||
{:ok, %{name: container_name}} ->
|
||||
|
@ -31,6 +31,13 @@ defmodule CanneryWeb.ContainerLive.Index do
|
||||
socket |> assign(:page_title, gettext("New Container")) |> assign(:container, %Container{})
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :clone, %{"id" => id}) do
|
||||
container = Containers.get_container!(id, current_user)
|
||||
|
||||
socket
|
||||
|> assign(page_title: gettext("New Container"), container: %{container | id: nil})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(
|
||||
@ -199,6 +206,14 @@ defmodule CanneryWeb.ContainerLive.Index do
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
patch={Routes.container_index_path(Endpoint, :clone, @container)}
|
||||
class="text-primary-600 link"
|
||||
data-qa={"clone-#{@container.id}"}
|
||||
>
|
||||
<i class="fa-fw fa-lg fas fa-copy"></i>
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
href="#"
|
||||
class="text-primary-600 link"
|
||||
|
@ -56,6 +56,14 @@
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
patch={Routes.container_index_path(Endpoint, :clone, container)}
|
||||
class="text-primary-600 link"
|
||||
data-qa={"clone-#{container.id}"}
|
||||
>
|
||||
<i class="fa-fw fa-lg fas fa-copy"></i>
|
||||
</.link>
|
||||
|
||||
<.link
|
||||
href="#"
|
||||
class="text-primary-600 link"
|
||||
@ -74,7 +82,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:new, :edit] do %>
|
||||
<%= if @live_action in [:new, :edit, :clone] do %>
|
||||
<.modal return_to={return_to(@view_table)}>
|
||||
<.live_component
|
||||
module={CanneryWeb.ContainerLive.FormComponent}
|
||||
|
Reference in New Issue
Block a user