added shift template cloning feature
This commit is contained in:
parent
8aa4b8eee0
commit
ea0f8b86cd
6 changed files with 21 additions and 1 deletions
lib/shift73k_web/live/shift_template_live
|
@ -77,6 +77,10 @@ defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
|||
end
|
||||
end
|
||||
|
||||
defp save_shift_template(socket, :clone, shift_template_params) do
|
||||
save_shift_template(socket, :new, shift_template_params)
|
||||
end
|
||||
|
||||
defp save_shift_template(socket, :edit, shift_template_params) do
|
||||
case ShiftTemplates.update_shift_template(
|
||||
socket.assigns.shift_template,
|
||||
|
|
|
@ -34,6 +34,12 @@ defmodule Shift73kWeb.ShiftTemplateLive.Index do
|
|||
end
|
||||
end
|
||||
|
||||
defp apply_action(socket, :clone, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Clone Shift Template")
|
||||
|> assign(:shift_template, ShiftTemplates.get_shift_template!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Shift Template")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= if @live_action in [:new, :edit] do %>
|
||||
<%= if @live_action in [:new, :edit, :clone] do %>
|
||||
<%= live_modal @socket, Shift73kWeb.ShiftTemplateLive.FormComponent,
|
||||
id: @shift_template.id || :new,
|
||||
title: @page_title,
|
||||
|
@ -100,6 +100,13 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= if Roles.can?(@current_user, shift, :clone) do %>
|
||||
<%= live_patch to: Routes.shift_template_index_path(@socket, :clone, shift), class: "btn btn-outline-primary btn-sm text-nowrap" do %>
|
||||
<%= icon_div @socket, "bi-clipboard-plus", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
|
||||
Clone
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= if Roles.can?(@current_user, shift, :delete) do %>
|
||||
<button class="btn btn-outline-danger btn-sm text-nowrap" phx-click="delete-modal" phx-value-id="<%= shift.id %>">
|
||||
<%= icon_div @socket, "bi-trash", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue