forked from shibao/cannery
		
	add cloning to ammo type index
This commit is contained in:
		@@ -35,15 +35,15 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
 | 
			
		||||
         ammo_type_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 -> ammo_type |> AmmoType.create_changeset(user, ammo_type_params)
 | 
			
		||||
        :edit -> ammo_type |> AmmoType.update_changeset(ammo_type_params)
 | 
			
		||||
      cond do
 | 
			
		||||
        action in [:new, :clone] -> ammo_type |> AmmoType.create_changeset(user, ammo_type_params)
 | 
			
		||||
        action == :edit -> ammo_type |> AmmoType.update_changeset(ammo_type_params)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    changeset =
 | 
			
		||||
@@ -76,9 +76,10 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
 | 
			
		||||
 | 
			
		||||
  defp save_ammo_type(
 | 
			
		||||
         %{assigns: %{current_user: current_user, return_to: return_to}} = socket,
 | 
			
		||||
         :new,
 | 
			
		||||
         action,
 | 
			
		||||
         ammo_type_params
 | 
			
		||||
       ) do
 | 
			
		||||
       )
 | 
			
		||||
       when action in [:new, :clone] do
 | 
			
		||||
    socket =
 | 
			
		||||
      case Ammo.create_ammo_type(ammo_type_params, current_user) do
 | 
			
		||||
        {:ok, %{name: ammo_type_name}} ->
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,12 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
 | 
			
		||||
    |> assign(:ammo_type, Ammo.get_ammo_type!(id, current_user))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp apply_action(%{assigns: %{current_user: current_user}} = socket, :clone, %{"id" => id}) do
 | 
			
		||||
    socket
 | 
			
		||||
    |> assign(:page_title, gettext("New Ammo type"))
 | 
			
		||||
    |> assign(:ammo_type, %{Ammo.get_ammo_type!(id, current_user) | id: nil})
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp apply_action(socket, :new, _params) do
 | 
			
		||||
    socket
 | 
			
		||||
    |> assign(:page_title, gettext("New Ammo type"))
 | 
			
		||||
@@ -154,6 +160,14 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
 | 
			
		||||
        <i class="fa-fw fa-lg fas fa-edit"></i>
 | 
			
		||||
      </.link>
 | 
			
		||||
 | 
			
		||||
      <.link
 | 
			
		||||
        patch={Routes.ammo_type_index_path(Endpoint, :clone, @ammo_type)}
 | 
			
		||||
        class="text-primary-600 link"
 | 
			
		||||
        data-qa={"clone-#{@ammo_type.id}"}
 | 
			
		||||
      >
 | 
			
		||||
        <i class="fa-fw fa-lg fas fa-copy"></i>
 | 
			
		||||
      </.link>
 | 
			
		||||
 | 
			
		||||
      <.link
 | 
			
		||||
        href="#"
 | 
			
		||||
        class="text-primary-600 link"
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@
 | 
			
		||||
  <% end %>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<%= if @live_action in [:new, :edit] do %>
 | 
			
		||||
<%= if @live_action in [:new, :edit, :clone] do %>
 | 
			
		||||
  <.modal return_to={Routes.ammo_type_index_path(Endpoint, :index)}>
 | 
			
		||||
    <.live_component
 | 
			
		||||
      module={CanneryWeb.AmmoTypeLive.FormComponent}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user