continuing improvements

This commit is contained in:
Adam Piontek 2021-03-08 07:39:41 -05:00
parent 89d9bc0cce
commit e00ecbf4c1
8 changed files with 121 additions and 166 deletions

View file

@ -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

View file

@ -20,59 +20,92 @@
</div>
<div class="row justify-content-center">
<div class="col-12 col-sm-11 col-md-10 col-lg-8 col-xl-7 ">
<div class="row">
<%= for shift <- @shift_templates do %>
<%= for shift <- @shift_templates do %>
<div class="col-12 col-sm-11 col-md-9 col-lg-7 col-xl-6 ">
<div class="card mt-4">
<h5 class="card-header">
<span class="visually-hidden">Subject:</span>
<%= shift.subject %>
</h5>
<div class="card-body">
<h4 class="card-title"><%= shift.subject %></h4>
<h5 class="card-subtitle mb-2 text-muted">
<%= shift.start_time |> Calendar.strftime("%I:%M %p") %>
&mdash;
<%=
shift.start_time
|> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60))
|> Calendar.strftime("%I:%M %p")
%>
<span class="fs-6">[<%= shift.timezone %>]</span>
</h5>
<p class="card-text">
<table class="table table-borderless table-nonfluid">
<tbody>
<tr>
<th scope="row" class="text-end">Description</th>
<td>
<%= if shift.description do %>
<%= shift.description %>
<% else %>
<span class="text-muted fst-italic">empty</span>
<% end %>
</td>
</tr>
<tr>
<th scope="row" class="text-end">Location</th>
<td>
<%= if shift.location do %>
<%= shift.location %>
<% else %>
<span class="text-muted fst-italic">empty</span>
<% end %>
</td>
</tr>
</tbody>
</table>
</p>
<a href="#" class="card-link">Card link</a>
<a href="#" class="card-link">Another link</a>
<table class="table table-borderless table-nonfluid table-sm">
<tbody>
<tr>
<th scope="row" class="text-end">
<%= icon_div @socket, "bi-hourglass", [class: "icon baseline text-muted"] %>
<span class="visually-hidden">Hours</span>
</th>
<td>
<%= shift.start_time |> Calendar.strftime("%I:%M%P") %>
&mdash;
<%=
shift.start_time
|> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60))
|> Calendar.strftime("%I:%M%P")
%>
</td>
</tr>
<tr>
<th scope="row" class="text-end">
<%= icon_div @socket, "bi-geo", [class: "icon baseline text-muted"] %>
<span class="visually-hidden">Location</span>
</th>
<td>
<%= if shift.location do %>
<%= shift.location %>
<% else %>
<span class="text-muted fst-italic">none</span>
<% end %>
</td>
</tr>
<tr>
<th scope="row" class="text-end">
<%= icon_div @socket, "bi-justify-left", [class: "icon baseline text-muted"] %>
<span class="visually-hidden">Description</span>
</th>
<td>
<%= if shift.description do %>
<%= shift.description %>
<% else %>
<span class="text-muted fst-italic">none</span>
<% end %>
</td>
</tr>
</tbody>
</table>
<div class="text-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 %>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
@ -102,7 +135,6 @@
<td><%= shift.length_hours %>h <%= shift.length_minutes || 0 %>m</td>
<td>
<span><%= live_redirect "Show", to: Routes.shift_template_show_path(@socket, :show, shift) %></span>
<span><%= live_patch "Edit", to: Routes.shift_template_index_path(@socket, :edit, shift) %></span>
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"] %></span>
</td>

View file

@ -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

View file

@ -1,52 +0,0 @@
<h1>Show Shift template</h1>
<%= 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 %>
<ul>
<li>
<strong>Subject:</strong>
<%= @shift_template.subject %>
</li>
<li>
<strong>Description:</strong>
<%= @shift_template.description %>
</li>
<li>
<strong>Location:</strong>
<%= @shift_template.location %>
</li>
<li>
<strong>Timezone:</strong>
<%= @shift_template.timezone %>
</li>
<li>
<strong>Start time:</strong>
<%= @shift_template.start_time %>
</li>
<li>
<strong>Length hours:</strong>
<%= @shift_template.length_hours %>
</li>
<li>
<strong>Length minutes:</strong>
<%= @shift_template.length_minutes %>
</li>
</ul>
<span><%= live_patch "Edit", to: Routes.shift_template_show_path(@socket, :edit, @shift_template), class: "button" %></span>
<span><%= live_redirect "Back", to: Routes.shift_template_index_path(@socket, :index) %></span>

View file

@ -112,18 +112,18 @@
</td>
<td class="align-middle text-end text-nowrap">
<%= 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 %>
<button class="btn btn-outline-danger btn-sm text-nowrap" phx-click="delete-modal" phx-value-id="<%= user.id %>">
<%= icon_div @socket, "bi-trash", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
Delete
</button>
<% end %>
</td>

View file

@ -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

View file

@ -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

View file

@ -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&apos;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