From ea0f8b86cdf01af6143cfb9819a4a87df61dabe5 Mon Sep 17 00:00:00 2001 From: Adam Piontek Date: Thu, 11 Mar 2021 14:05:22 -0500 Subject: [PATCH] added shift template cloning feature --- assets/js/app.js | 1 + .../live/shift_template_live/form_component.ex | 4 ++++ lib/shift73k_web/live/shift_template_live/index.ex | 6 ++++++ .../live/shift_template_live/index.html.leex | 9 ++++++++- lib/shift73k_web/roles.ex | 1 + lib/shift73k_web/router.ex | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/assets/js/app.js b/assets/js/app.js index 72edd2eb..47873136 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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 diff --git a/lib/shift73k_web/live/shift_template_live/form_component.ex b/lib/shift73k_web/live/shift_template_live/form_component.ex index b156d53c..c7969881 100644 --- a/lib/shift73k_web/live/shift_template_live/form_component.ex +++ b/lib/shift73k_web/live/shift_template_live/form_component.ex @@ -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, diff --git a/lib/shift73k_web/live/shift_template_live/index.ex b/lib/shift73k_web/live/shift_template_live/index.ex index f8818cf0..25d92ff3 100644 --- a/lib/shift73k_web/live/shift_template_live/index.ex +++ b/lib/shift73k_web/live/shift_template_live/index.ex @@ -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") diff --git a/lib/shift73k_web/live/shift_template_live/index.html.leex b/lib/shift73k_web/live/shift_template_live/index.html.leex index d6ce5dd0..d47efbbc 100644 --- a/lib/shift73k_web/live/shift_template_live/index.html.leex +++ b/lib/shift73k_web/live/shift_template_live/index.html.leex @@ -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 %>