added shift template cloning feature
This commit is contained in:
parent
8aa4b8eee0
commit
ea0f8b86cd
6 changed files with 21 additions and 1 deletions
|
@ -42,6 +42,7 @@ import "../node_modules/bootstrap-icons/icons/map.svg";
|
|||
import "../node_modules/bootstrap-icons/icons/geo.svg";
|
||||
import "../node_modules/bootstrap-icons/icons/justify-left.svg";
|
||||
import "../node_modules/bootstrap-icons/icons/plus-circle-dotted.svg";
|
||||
import "../node_modules/bootstrap-icons/icons/clipboard-plus.svg";
|
||||
|
||||
// webpack automatically bundles all modules in your
|
||||
// entry points. Those entry points can be configured
|
||||
|
|
|
@ -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;"] %>
|
||||
|
|
|
@ -18,6 +18,7 @@ defmodule Shift73kWeb.Roles do
|
|||
def can?(%User{}, %ShiftTemplate{}, :new), do: true
|
||||
# def can?(%User{}, %ShiftTemplate{}, :show), do: true
|
||||
def can?(%User{id: id}, %ShiftTemplate{user_id: id}, :edit), do: true
|
||||
def can?(%User{id: id}, %ShiftTemplate{user_id: id}, :clone), do: true
|
||||
def can?(%User{id: id}, %ShiftTemplate{user_id: id}, :delete), do: true
|
||||
|
||||
# Accounts / User
|
||||
|
|
|
@ -94,6 +94,7 @@ defmodule Shift73kWeb.Router do
|
|||
live "/my_shifts", ShiftTemplateLive.Index, :index
|
||||
live "/my_shifts/new", ShiftTemplateLive.Index, :new
|
||||
live "/my_shifts/:id/edit", ShiftTemplateLive.Index, :edit
|
||||
live "/my_shifts/:id/clone", ShiftTemplateLive.Index, :clone
|
||||
end
|
||||
|
||||
# scope "/", Shift73kWeb do
|
||||
|
|
Loading…
Reference in a new issue