tidying shifts files
This commit is contained in:
parent
8a1b7a4852
commit
ab11131df6
7 changed files with 2 additions and 211 deletions
|
@ -1,55 +0,0 @@
|
||||||
defmodule Shift73kWeb.ShiftLive.FormComponent do
|
|
||||||
use Shift73kWeb, :live_component
|
|
||||||
|
|
||||||
alias Shift73k.Shifts
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def update(%{shift: shift} = assigns, socket) do
|
|
||||||
changeset = Shifts.change_shift(shift)
|
|
||||||
|
|
||||||
{:ok,
|
|
||||||
socket
|
|
||||||
|> assign(assigns)
|
|
||||||
|> assign(:changeset, changeset)}
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def handle_event("validate", %{"shift" => shift_params}, socket) do
|
|
||||||
changeset =
|
|
||||||
socket.assigns.shift
|
|
||||||
|> Shifts.change_shift(shift_params)
|
|
||||||
|> Map.put(:action, :validate)
|
|
||||||
|
|
||||||
{:noreply, assign(socket, :changeset, changeset)}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_event("save", %{"shift" => shift_params}, socket) do
|
|
||||||
save_shift(socket, socket.assigns.action, shift_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp save_shift(socket, :edit, shift_params) do
|
|
||||||
case Shifts.update_shift(socket.assigns.shift, shift_params) do
|
|
||||||
{:ok, _shift} ->
|
|
||||||
{:noreply,
|
|
||||||
socket
|
|
||||||
|> put_flash(:info, "Shift updated successfully")
|
|
||||||
|> push_redirect(to: socket.assigns.return_to)}
|
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
|
||||||
{:noreply, assign(socket, :changeset, changeset)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp save_shift(socket, :new, shift_params) do
|
|
||||||
case Shifts.create_shift(shift_params) do
|
|
||||||
{:ok, _shift} ->
|
|
||||||
{:noreply,
|
|
||||||
socket
|
|
||||||
|> put_flash(:info, "Shift created successfully")
|
|
||||||
|> push_redirect(to: socket.assigns.return_to)}
|
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
|
||||||
{:noreply, assign(socket, changeset: changeset)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,42 +0,0 @@
|
||||||
<h2><%= @title %></h2>
|
|
||||||
|
|
||||||
<%= f = form_for @changeset, "#",
|
|
||||||
id: "shift-form",
|
|
||||||
phx_target: @myself,
|
|
||||||
phx_change: "validate",
|
|
||||||
phx_submit: "save" %>
|
|
||||||
|
|
||||||
<%= label f, :subject %>
|
|
||||||
<%= text_input f, :subject %>
|
|
||||||
<%= error_tag f, :subject %>
|
|
||||||
|
|
||||||
<%= label f, :location %>
|
|
||||||
<%= text_input f, :location %>
|
|
||||||
<%= error_tag f, :location %>
|
|
||||||
|
|
||||||
<%= label f, :description %>
|
|
||||||
<%= textarea f, :description %>
|
|
||||||
<%= error_tag f, :description %>
|
|
||||||
|
|
||||||
<%= label f, :time_zone %>
|
|
||||||
<%= text_input f, :time_zone %>
|
|
||||||
<%= error_tag f, :time_zone %>
|
|
||||||
|
|
||||||
<%= label f, :date %>
|
|
||||||
<%= date_select f, :date %>
|
|
||||||
<%= error_tag f, :date %>
|
|
||||||
|
|
||||||
<%= label f, :time_zone %>
|
|
||||||
<%= text_input f, :time_zone %>
|
|
||||||
<%= error_tag f, :time_zone %>
|
|
||||||
|
|
||||||
<%= label f, :time_start %>
|
|
||||||
<%= time_select f, :time_start %>
|
|
||||||
<%= error_tag f, :time_start %>
|
|
||||||
|
|
||||||
<%= label f, :time_end %>
|
|
||||||
<%= time_select f, :time_end %>
|
|
||||||
<%= error_tag f, :time_end %>
|
|
||||||
|
|
||||||
<%= submit "Save", phx_disable_with: "Saving..." %>
|
|
||||||
</form>
|
|
|
@ -11,8 +11,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
|
||||||
socket
|
socket
|
||||||
|> assign_defaults(session)
|
|> assign_defaults(session)
|
||||||
|> live_okreply()
|
|> live_okreply()
|
||||||
|
|
||||||
# {:ok, assign(socket, :shifts, list_shifts())}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
@ -23,8 +21,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
|
||||||
|
|
||||||
if Roles.can?(current_user, shift, live_action) do
|
if Roles.can?(current_user, shift, live_action) do
|
||||||
socket
|
socket
|
||||||
# |> assign_shift_templates()
|
|
||||||
# |> assign_modal_close_handlers()
|
|
||||||
|> init_today(Timex.today())
|
|> init_today(Timex.today())
|
||||||
|> assign_date_range()
|
|> assign_date_range()
|
||||||
|> assign_known_shifts()
|
|> assign_known_shifts()
|
||||||
|
@ -37,20 +33,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
|> live_noreply()
|
|> live_noreply()
|
||||||
end
|
end
|
||||||
|
|
||||||
# {:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
|
||||||
socket
|
|
||||||
|> assign(:page_title, "Edit Shift")
|
|
||||||
|> assign(:shift, Shifts.get_shift!(id))
|
|
||||||
end
|
|
||||||
|
|
||||||
defp apply_action(socket, :new, _params) do
|
|
||||||
socket
|
|
||||||
|> assign(:page_title, "New Shift")
|
|
||||||
|> assign(:shift, %Shift{})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(socket, :index, _params) do
|
defp apply_action(socket, :index, _params) do
|
||||||
|
|
|
@ -1,18 +1,8 @@
|
||||||
<%= if @live_action in [:new, :edit] do %>
|
|
||||||
<%= live_modal @socket, Shift73kWeb.ShiftLive.FormComponent,
|
|
||||||
id: @shift.id || :new,
|
|
||||||
title: @page_title,
|
|
||||||
action: @live_action,
|
|
||||||
shift: @shift,
|
|
||||||
return_to: Routes.shift_index_path(@socket, :index) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="row justify-content-start justify-content-sm-center">
|
<div class="row justify-content-start justify-content-sm-center">
|
||||||
<div class="col-md-10 col-xl-10">
|
<div class="col-md-10 col-xl-10">
|
||||||
|
|
||||||
<h2 class="mb-3 mb-sm-0">
|
<h2 class="mb-3 mb-sm-0">
|
||||||
<%= icon_div @socket, "bi-calendar2-date", [class: "icon baseline"] %>
|
<%= icon_div @socket, "bi-card-list", [class: "icon baseline"] %>
|
||||||
My Shifts
|
My Shifts
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
@ -40,7 +30,6 @@
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
<%= for day <- Enum.to_list(@date_range) do %>
|
<%= for day <- Enum.to_list(@date_range) do %>
|
||||||
<% Date.day_of_week(day, @current_user.week_start_at) |> IO.inspect(label: "day in date_range") %>
|
|
||||||
<%= if Date.day_of_week(day, @current_user.week_start_at) == 1 do %>
|
<%= if Date.day_of_week(day, @current_user.week_start_at) == 1 do %>
|
||||||
<div class="border-top mt-4 mb-4"></div>
|
<div class="border-top mt-4 mb-4"></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -69,8 +58,6 @@
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: smaller;"><%= shift.description %></div>
|
<div style="font-size: smaller;"><%= shift.description %></div>
|
||||||
<div style="font-size: smaller;">
|
<div style="font-size: smaller;">
|
||||||
<span><%= live_redirect "Show", to: Routes.shift_show_path(@socket, :show, shift) %></span>
|
|
||||||
<span><%= live_patch "Edit", to: Routes.shift_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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -80,14 +67,11 @@
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<dd><em>No shift scheduled</em></dd>
|
<dd><em>Nothing scheduled</em></dd>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
|
||||||
<span><%= live_patch "New Shift", to: Routes.shift_index_path(@socket, :new) %></span>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
defmodule Shift73kWeb.ShiftLive.Show do
|
|
||||||
use Shift73kWeb, :live_view
|
|
||||||
|
|
||||||
alias Shift73k.Shifts
|
|
||||||
|
|
||||||
@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, Shifts.get_shift!(id))}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp page_title(:show), do: "Show Shift"
|
|
||||||
defp page_title(:edit), do: "Edit Shift"
|
|
||||||
end
|
|
|
@ -1,52 +0,0 @@
|
||||||
<h1>Show Shift</h1>
|
|
||||||
|
|
||||||
<%= if @live_action in [:edit] do %>
|
|
||||||
<%= live_modal @socket, Shift73kWeb.ShiftLive.FormComponent,
|
|
||||||
id: @shift.id,
|
|
||||||
title: @page_title,
|
|
||||||
action: @live_action,
|
|
||||||
shift: @shift,
|
|
||||||
return_to: Routes.shift_show_path(@socket, :show, @shift) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Subject:</strong>
|
|
||||||
<%= @shift.subject %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Location:</strong>
|
|
||||||
<%= @shift.location %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Description:</strong>
|
|
||||||
<%= @shift.description %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Date:</strong>
|
|
||||||
<%= @shift.date %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Time zone:</strong>
|
|
||||||
<%= @shift.time_zone %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Time start:</strong>
|
|
||||||
<%= @shift.time_start %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<strong>Time end:</strong>
|
|
||||||
<%= @shift.time_end %>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<span><%= live_patch "Edit", to: Routes.shift_show_path(@socket, :edit, @shift), class: "button" %></span>
|
|
||||||
<span><%= live_redirect "Back", to: Routes.shift_index_path(@socket, :index) %></span>
|
|
|
@ -98,11 +98,6 @@ defmodule Shift73kWeb.Router do
|
||||||
live "/assign", ShiftAssignLive.Index, :index
|
live "/assign", ShiftAssignLive.Index, :index
|
||||||
|
|
||||||
live "/shifts", ShiftLive.Index, :index
|
live "/shifts", ShiftLive.Index, :index
|
||||||
live "/shifts/new", ShiftLive.Index, :new
|
|
||||||
live "/shifts/:id/edit", ShiftLive.Index, :edit
|
|
||||||
|
|
||||||
live "/shifts/:id", ShiftLive.Show, :show
|
|
||||||
live "/shifts/:id/show/edit", ShiftLive.Show, :edit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# scope "/", Shift73kWeb do
|
# scope "/", Shift73kWeb do
|
||||||
|
|
Loading…
Reference in a new issue