continuing improvements
This commit is contained in:
parent
89d9bc0cce
commit
e00ecbf4c1
8 changed files with 121 additions and 166 deletions
|
@ -37,6 +37,9 @@ import "../node_modules/bootstrap-icons/icons/people.svg"; // users management
|
||||||
// calendar/event icons
|
// calendar/event icons
|
||||||
import "../node_modules/bootstrap-icons/icons/calendar3-event.svg"; // brand
|
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/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
|
// webpack automatically bundles all modules in your
|
||||||
// entry points. Those entry points can be configured
|
// entry points. Those entry points can be configured
|
||||||
|
|
|
@ -20,59 +20,92 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="row justify-content-center">
|
<div class="row">
|
||||||
<div class="col-12 col-sm-11 col-md-10 col-lg-8 col-xl-7 ">
|
|
||||||
|
|
||||||
<%= 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">
|
<div class="card mt-4">
|
||||||
|
<h5 class="card-header">
|
||||||
|
<span class="visually-hidden">Subject:</span>
|
||||||
|
<%= shift.subject %>
|
||||||
|
</h5>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h4 class="card-title"><%= shift.subject %></h4>
|
|
||||||
<h5 class="card-subtitle mb-2 text-muted">
|
<table class="table table-borderless table-nonfluid table-sm">
|
||||||
<%= shift.start_time |> Calendar.strftime("%I:%M %p") %>
|
<tbody>
|
||||||
—
|
<tr>
|
||||||
<%=
|
<th scope="row" class="text-end">
|
||||||
shift.start_time
|
<%= icon_div @socket, "bi-hourglass", [class: "icon baseline text-muted"] %>
|
||||||
|> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60))
|
<span class="visually-hidden">Hours</span>
|
||||||
|> Calendar.strftime("%I:%M %p")
|
</th>
|
||||||
%>
|
<td>
|
||||||
<span class="fs-6">[<%= shift.timezone %>]</span>
|
<%= shift.start_time |> Calendar.strftime("%I:%M%P") %>
|
||||||
</h5>
|
—
|
||||||
<p class="card-text">
|
<%=
|
||||||
<table class="table table-borderless table-nonfluid">
|
shift.start_time
|
||||||
<tbody>
|
|> Time.add((60 * 60 * shift.length_hours) + ((shift.length_minutes || 0) * 60))
|
||||||
<tr>
|
|> Calendar.strftime("%I:%M%P")
|
||||||
<th scope="row" class="text-end">Description</th>
|
%>
|
||||||
<td>
|
</td>
|
||||||
<%= if shift.description do %>
|
</tr>
|
||||||
<%= shift.description %>
|
|
||||||
<% else %>
|
|
||||||
<span class="text-muted fst-italic">empty</span>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
<tr>
|
||||||
</tr>
|
<th scope="row" class="text-end">
|
||||||
<tr>
|
<%= icon_div @socket, "bi-geo", [class: "icon baseline text-muted"] %>
|
||||||
<th scope="row" class="text-end">Location</th>
|
<span class="visually-hidden">Location</span>
|
||||||
<td>
|
</th>
|
||||||
<%= if shift.location do %>
|
<td>
|
||||||
<%= shift.location %>
|
<%= if shift.location do %>
|
||||||
<% else %>
|
<%= shift.location %>
|
||||||
<span class="text-muted fst-italic">empty</span>
|
<% else %>
|
||||||
<% end %>
|
<span class="text-muted fst-italic">none</span>
|
||||||
</td>
|
<% end %>
|
||||||
</tr>
|
</td>
|
||||||
</tbody>
|
</tr>
|
||||||
</table>
|
<tr>
|
||||||
</p>
|
<th scope="row" class="text-end">
|
||||||
<a href="#" class="card-link">Card link</a>
|
<%= icon_div @socket, "bi-justify-left", [class: "icon baseline text-muted"] %>
|
||||||
<a href="#" class="card-link">Another link</a>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% end %>
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +135,6 @@
|
||||||
<td><%= shift.length_hours %>h <%= shift.length_minutes || 0 %>m</td>
|
<td><%= shift.length_hours %>h <%= shift.length_minutes || 0 %>m</td>
|
||||||
|
|
||||||
<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><%= 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>
|
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"] %></span>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -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
|
|
|
@ -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>
|
|
|
@ -112,18 +112,18 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle text-end text-nowrap">
|
<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 %>
|
<%= if Roles.can?(@current_user, user, :edit) do %>
|
||||||
<%= icon_div @socket, "bi-pencil", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
|
<%= 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 %>
|
||||||
Edit
|
<%= icon_div @socket, "bi-pencil", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
|
||||||
|
Edit
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if Roles.can?(@current_user, user, :delete) do %>
|
<%= 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 %>">
|
<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;"] %>
|
<%= icon_div @socket, "bi-trash", [class: "icon baseline", style: "margin-right:0.125rem;"] %>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -16,7 +16,7 @@ defmodule Shift73kWeb.Roles do
|
||||||
def can?(%User{role: :admin}, %ShiftTemplate{}, _any), do: true
|
def can?(%User{role: :admin}, %ShiftTemplate{}, _any), do: true
|
||||||
def can?(%User{}, %ShiftTemplate{}, :index), do: true
|
def can?(%User{}, %ShiftTemplate{}, :index), do: true
|
||||||
def can?(%User{}, %ShiftTemplate{}, :new), 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}, :edit), do: true
|
||||||
def can?(%User{id: id}, %ShiftTemplate{user_id: id}, :delete), 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{}, :index), do: true
|
||||||
def can?(%User{role: :manager}, %User{}, :new), 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{}, :edit), do: true
|
||||||
def can?(%User{role: :manager}, %User{}, :show), do: true
|
# def can?(%User{role: :manager}, %User{}, :show), do: true
|
||||||
|
|
||||||
# Final response
|
# Final response
|
||||||
def can?(_, _, _), do: false
|
def can?(_, _, _), do: false
|
||||||
|
|
|
@ -94,9 +94,6 @@ defmodule Shift73kWeb.Router do
|
||||||
live "/my_shifts", ShiftTemplateLive.Index, :index
|
live "/my_shifts", ShiftTemplateLive.Index, :index
|
||||||
live "/my_shifts/new", ShiftTemplateLive.Index, :new
|
live "/my_shifts/new", ShiftTemplateLive.Index, :new
|
||||||
live "/my_shifts/:id/edit", ShiftTemplateLive.Index, :edit
|
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
|
end
|
||||||
|
|
||||||
# scope "/", Shift73kWeb do
|
# scope "/", Shift73kWeb do
|
||||||
|
|
|
@ -5,9 +5,33 @@ defmodule Shift73kWeb.ShiftTemplateLiveTest do
|
||||||
|
|
||||||
alias Shift73k.ShiftTemplates
|
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"}
|
@create_attrs %{
|
||||||
@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"}
|
description: "some description",
|
||||||
@invalid_attrs %{description: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil}
|
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
|
defp fixture(:shift_template) do
|
||||||
{:ok, shift_template} = ShiftTemplates.create_shift_template(@create_attrs)
|
{: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
|
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))
|
{: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"
|
"Edit Shift template"
|
||||||
|
|
||||||
assert_patch(index_live, Routes.shift_template_index_path(conn, :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
|
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))
|
{: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}")
|
refute has_element?(index_live, "#shift_template-#{shift_template.id}")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue