From e00ecbf4c1ec0b89a0bbaad5f7f51d7702d0934b Mon Sep 17 00:00:00 2001 From: Adam Piontek Date: Mon, 8 Mar 2021 07:39:41 -0500 Subject: [PATCH] continuing improvements --- assets/js/app.js | 3 + .../live/shift_template_live/index.html.leex | 122 +++++++++++------- .../live/shift_template_live/show.ex | 21 --- .../live/shift_template_live/show.html.leex | 52 -------- .../live/user_management/index.html.leex | 10 +- lib/shift73k_web/roles.ex | 4 +- lib/shift73k_web/router.ex | 3 - .../live/shift_template_live_test.exs | 72 +++++------ 8 files changed, 121 insertions(+), 166 deletions(-) delete mode 100644 lib/shift73k_web/live/shift_template_live/show.ex delete mode 100644 lib/shift73k_web/live/shift_template_live/show.html.leex diff --git a/assets/js/app.js b/assets/js/app.js index b5943bc8..aeee1e5f 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -37,6 +37,9 @@ import "../node_modules/bootstrap-icons/icons/people.svg"; // users management // calendar/event icons import "../node_modules/bootstrap-icons/icons/calendar3-event.svg"; // brand import "../node_modules/bootstrap-icons/icons/clock-history.svg"; // brand +import "../node_modules/bootstrap-icons/icons/hourglass.svg"; // brand +import "../node_modules/bootstrap-icons/icons/geo.svg"; // brand +import "../node_modules/bootstrap-icons/icons/justify-left.svg"; // brand // 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/index.html.leex b/lib/shift73k_web/live/shift_template_live/index.html.leex index 779a15b0..860b3439 100644 --- a/lib/shift73k_web/live/shift_template_live/index.html.leex +++ b/lib/shift73k_web/live/shift_template_live/index.html.leex @@ -20,59 +20,92 @@ -
-
+
- <%= for shift <- @shift_templates do %> + <%= for shift <- @shift_templates do %> + +
+
+ Subject: + <%= shift.subject %> +
-

<%= shift.subject %>

-
- <%= shift.start_time |> Calendar.strftime("%I:%M %p") %> - — - <%= - shift.start_time - |> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60)) - |> Calendar.strftime("%I:%M %p") - %> - [<%= shift.timezone %>] -
-

- - - - - - - - - - - -
Description - <%= if shift.description do %> - <%= shift.description %> - <% else %> - empty - <% end %> -
Location - <%= if shift.location do %> - <%= shift.location %> - <% else %> - empty - <% end %> -
-

- Card link - Another link + + + + + + + + + + + + + + + + + + + + +
+ <%= icon_div @socket, "bi-hourglass", [class: "icon baseline text-muted"] %> + Hours + + <%= shift.start_time |> Calendar.strftime("%I:%M%P") %> + — + <%= + shift.start_time + |> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60)) + |> Calendar.strftime("%I:%M%P") + %> +
+ <%= icon_div @socket, "bi-geo", [class: "icon baseline text-muted"] %> + Location + + <%= if shift.location do %> + <%= shift.location %> + <% else %> + none + <% end %> +
+ <%= icon_div @socket, "bi-justify-left", [class: "icon baseline text-muted"] %> + Description + + <%= if shift.description do %> + <%= shift.description %> + <% else %> + none + <% end %> +
+ +
+ + <%= if Roles.can?(@current_user, shift, :delete) do %> + <%= link to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"], class: "btn btn-outline-danger" do %> + <%= icon_div @socket, "bi-trash", [class: "icon baseline", style: "margin-right:0.125rem;"] %> + Delete + <% end %> + <% end %> + + <%= if Roles.can?(@current_user, shift, :edit) do %> + <%= live_patch to: Routes.shift_template_index_path(@socket, :edit, shift), class: "btn btn-primary" do %> + <%= icon_div @socket, "bi-pencil", [class: "icon baseline", style: "margin-right:0.125rem;"] %> + Edit + <% end %> + <% end %> +
- <% end %> +
+ <% end %> -
@@ -102,7 +135,6 @@ <%= shift.length_hours %>h <%= shift.length_minutes || 0 %>m - <%= live_redirect "Show", to: Routes.shift_template_show_path(@socket, :show, shift) %> <%= live_patch "Edit", to: Routes.shift_template_index_path(@socket, :edit, shift) %> <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"] %> diff --git a/lib/shift73k_web/live/shift_template_live/show.ex b/lib/shift73k_web/live/shift_template_live/show.ex deleted file mode 100644 index 084a69e9..00000000 --- a/lib/shift73k_web/live/shift_template_live/show.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule Shift73kWeb.ShiftTemplateLive.Show do - use Shift73kWeb, :live_view - - alias Shift73k.ShiftTemplates - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:shift_template, ShiftTemplates.get_shift_template!(id))} - end - - defp page_title(:show), do: "Show Shift template" - defp page_title(:edit), do: "Edit Shift template" -end diff --git a/lib/shift73k_web/live/shift_template_live/show.html.leex b/lib/shift73k_web/live/shift_template_live/show.html.leex deleted file mode 100644 index d663be70..00000000 --- a/lib/shift73k_web/live/shift_template_live/show.html.leex +++ /dev/null @@ -1,52 +0,0 @@ -

Show Shift template

- -<%= if @live_action in [:edit] do %> - <%= live_modal @socket, Shift73kWeb.ShiftTemplateLive.FormComponent, - id: @shift_template.id, - title: @page_title, - action: @live_action, - shift_template: @shift_template, - return_to: Routes.shift_template_show_path(@socket, :show, @shift_template) %> -<% end %> - - - -<%= live_patch "Edit", to: Routes.shift_template_show_path(@socket, :edit, @shift_template), class: "button" %> -<%= live_redirect "Back", to: Routes.shift_template_index_path(@socket, :index) %> diff --git a/lib/shift73k_web/live/user_management/index.html.leex b/lib/shift73k_web/live/user_management/index.html.leex index d36fb7ab..8cdb428e 100644 --- a/lib/shift73k_web/live/user_management/index.html.leex +++ b/lib/shift73k_web/live/user_management/index.html.leex @@ -112,18 +112,18 @@ - <%= live_patch to: Routes.user_management_index_path(@socket, :edit, user.id, Enum.into(@query, [])), class: "btn btn-outline-primary btn-sm text-nowrap" do %> - <%= icon_div @socket, "bi-pencil", [class: "icon baseline", style: "margin-right:0.125rem;"] %> - Edit + <%= if Roles.can?(@current_user, user, :edit) do %> + <%= live_patch to: Routes.user_management_index_path(@socket, :edit, user.id, Enum.into(@query, [])), class: "btn btn-outline-primary btn-sm text-nowrap" do %> + <%= icon_div @socket, "bi-pencil", [class: "icon baseline", style: "margin-right:0.125rem;"] %> + Edit + <% end %> <% end %> <%= if Roles.can?(@current_user, user, :delete) do %> - - <% end %> diff --git a/lib/shift73k_web/roles.ex b/lib/shift73k_web/roles.ex index ed8985b3..07751894 100644 --- a/lib/shift73k_web/roles.ex +++ b/lib/shift73k_web/roles.ex @@ -16,7 +16,7 @@ defmodule Shift73kWeb.Roles do def can?(%User{role: :admin}, %ShiftTemplate{}, _any), do: true def can?(%User{}, %ShiftTemplate{}, :index), do: true def can?(%User{}, %ShiftTemplate{}, :new), do: true - def can?(%User{}, %ShiftTemplate{}, :show), 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}, :delete), do: true @@ -25,7 +25,7 @@ defmodule Shift73kWeb.Roles do def can?(%User{role: :manager}, %User{}, :index), do: true def can?(%User{role: :manager}, %User{}, :new), do: true def can?(%User{role: :manager}, %User{}, :edit), do: true - def can?(%User{role: :manager}, %User{}, :show), do: true + # def can?(%User{role: :manager}, %User{}, :show), do: true # Final response def can?(_, _, _), do: false diff --git a/lib/shift73k_web/router.ex b/lib/shift73k_web/router.ex index 1f929c89..aa244e45 100644 --- a/lib/shift73k_web/router.ex +++ b/lib/shift73k_web/router.ex @@ -94,9 +94,6 @@ 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", ShiftTemplateLive.Show, :show - live "/my_shifts/:id/show/edit", ShiftTemplateLive.Show, :edit end # scope "/", Shift73kWeb do diff --git a/test/shift73k_web/live/shift_template_live_test.exs b/test/shift73k_web/live/shift_template_live_test.exs index 93c959ea..75cd2e34 100644 --- a/test/shift73k_web/live/shift_template_live_test.exs +++ b/test/shift73k_web/live/shift_template_live_test.exs @@ -5,9 +5,33 @@ defmodule Shift73kWeb.ShiftTemplateLiveTest do alias Shift73k.ShiftTemplates - @create_attrs %{description: "some description", length_hours: 12, length_minutes: 42, location: "some location", start_time: ~T[14:00:00], subject: "some subject", timezone: "some timezone"} - @update_attrs %{description: "some updated description", length_hours: 12, length_minutes: 43, location: "some updated location", start_time: ~T[15:01:01], subject: "some updated subject", timezone: "some updated timezone"} - @invalid_attrs %{description: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil} + @create_attrs %{ + description: "some description", + length_hours: 12, + length_minutes: 42, + location: "some location", + start_time: ~T[14:00:00], + subject: "some subject", + timezone: "some timezone" + } + @update_attrs %{ + description: "some updated description", + length_hours: 12, + length_minutes: 43, + location: "some updated location", + start_time: ~T[15:01:01], + subject: "some updated subject", + timezone: "some updated timezone" + } + @invalid_attrs %{ + description: nil, + length_hours: nil, + length_minutes: nil, + location: nil, + start_time: nil, + subject: nil, + timezone: nil + } defp fixture(:shift_template) do {:ok, shift_template} = ShiftTemplates.create_shift_template(@create_attrs) @@ -54,7 +78,9 @@ defmodule Shift73kWeb.ShiftTemplateLiveTest do test "updates shift_template in listing", %{conn: conn, shift_template: shift_template} do {:ok, index_live, _html} = live(conn, Routes.shift_template_index_path(conn, :index)) - assert index_live |> element("#shift_template-#{shift_template.id} a", "Edit") |> render_click() =~ + assert index_live + |> element("#shift_template-#{shift_template.id} a", "Edit") + |> render_click() =~ "Edit Shift template" assert_patch(index_live, Routes.shift_template_index_path(conn, :edit, shift_template)) @@ -76,41 +102,11 @@ defmodule Shift73kWeb.ShiftTemplateLiveTest do test "deletes shift_template in listing", %{conn: conn, shift_template: shift_template} do {:ok, index_live, _html} = live(conn, Routes.shift_template_index_path(conn, :index)) - assert index_live |> element("#shift_template-#{shift_template.id} a", "Delete") |> render_click() + assert index_live + |> element("#shift_template-#{shift_template.id} a", "Delete") + |> render_click() + refute has_element?(index_live, "#shift_template-#{shift_template.id}") end end - - describe "Show" do - setup [:create_shift_template] - - test "displays shift_template", %{conn: conn, shift_template: shift_template} do - {:ok, _show_live, html} = live(conn, Routes.shift_template_show_path(conn, :show, shift_template)) - - assert html =~ "Show Shift template" - assert html =~ shift_template.description - end - - test "updates shift_template within modal", %{conn: conn, shift_template: shift_template} do - {:ok, show_live, _html} = live(conn, Routes.shift_template_show_path(conn, :show, shift_template)) - - assert show_live |> element("a", "Edit") |> render_click() =~ - "Edit Shift template" - - assert_patch(show_live, Routes.shift_template_show_path(conn, :edit, shift_template)) - - assert show_live - |> form("#shift_template-form", shift_template: @invalid_attrs) - |> render_change() =~ "can't be blank" - - {:ok, _, html} = - show_live - |> form("#shift_template-form", shift_template: @update_attrs) - |> render_submit() - |> follow_redirect(conn, Routes.shift_template_show_path(conn, :show, shift_template)) - - assert html =~ "Shift template updated successfully" - assert html =~ "some updated description" - end - end end