reorganized shift templates files
This commit is contained in:
parent
243ebd8aa2
commit
e0f8515566
13 changed files with 80 additions and 49 deletions
lib
shift73k
shift73k_web
|
@ -7,7 +7,6 @@ defmodule Shift73k.Accounts do
|
|||
alias Shift73k.Repo
|
||||
alias Shift73k.Accounts.{User, UserToken, UserNotifier}
|
||||
alias Shift73kWeb.UserAuth
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
|
||||
## Database getters
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ defmodule Shift73k.Accounts.User do
|
|||
import Ecto.Changeset
|
||||
import EctoEnum
|
||||
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
||||
@roles [
|
||||
user: "Basic user level",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
defmodule Shift73k.ShiftTemplates do
|
||||
defmodule Shift73k.Shifts.Templates do
|
||||
@moduledoc """
|
||||
The ShiftTemplates context.
|
||||
The Shifts.Templates context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Shift73k.Repo
|
||||
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
||||
@doc """
|
||||
Returns the list of shift_templates.
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Shift73k.ShiftTemplates.ShiftTemplate do
|
||||
defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Shift73kWeb.ShiftTemplateLive.DeleteComponent do
|
||||
use Shift73kWeb, :live_component
|
||||
|
||||
alias Shift73k.ShiftTemplates
|
||||
alias Shift73k.Shifts.Templates
|
||||
|
||||
@impl true
|
||||
def update(assigns, socket) do
|
||||
|
@ -18,8 +18,8 @@ defmodule Shift73kWeb.ShiftTemplateLive.DeleteComponent do
|
|||
@impl true
|
||||
def handle_event("confirm", %{"id" => id, "subject" => subject}, socket) do
|
||||
id
|
||||
|> ShiftTemplates.get_shift_template()
|
||||
|> ShiftTemplates.delete_shift_template()
|
||||
|> Templates.get_shift_template()
|
||||
|> Templates.delete_shift_template()
|
||||
|> case do
|
||||
{:ok, _} ->
|
||||
flash = {:info, "Shift template deleted successfully: \"#{subject}\""}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
||||
use Shift73kWeb, :live_component
|
||||
|
||||
alias Shift73k.ShiftTemplates
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Templates
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
||||
@impl true
|
||||
def update(%{shift_template: shift_template} = assigns, socket) do
|
||||
changeset = ShiftTemplates.change_shift_template(shift_template)
|
||||
changeset = Templates.change_shift_template(shift_template)
|
||||
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|
@ -37,7 +37,7 @@ defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
|||
|
||||
changeset =
|
||||
socket.assigns.shift_template
|
||||
|> ShiftTemplates.change_shift_template(shift_template_params)
|
||||
|> Templates.change_shift_template(shift_template_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
socket
|
||||
|
@ -63,7 +63,7 @@ defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
|||
end
|
||||
|
||||
defp save_shift_template(socket, :new, shift_template_params) do
|
||||
case ShiftTemplates.create_shift_template(shift_template_params) do
|
||||
case Templates.create_shift_template(shift_template_params) do
|
||||
{:ok, _shift_template} ->
|
||||
flash = {:info, "Shift template created successfully"}
|
||||
send(self(), {:put_flash_message, flash})
|
||||
|
@ -82,7 +82,7 @@ defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
|
|||
end
|
||||
|
||||
defp save_shift_template(socket, :edit, shift_template_params) do
|
||||
case ShiftTemplates.update_shift_template(
|
||||
case Templates.update_shift_template(
|
||||
socket.assigns.shift_template,
|
||||
shift_template_params
|
||||
) do
|
||||
|
|
|
@ -2,8 +2,8 @@ defmodule Shift73kWeb.ShiftTemplateLive.Index do
|
|||
use Shift73kWeb, :live_view
|
||||
|
||||
alias Shift73k.Accounts
|
||||
alias Shift73k.ShiftTemplates
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Templates
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
alias Shift73kWeb.Roles
|
||||
|
||||
@impl true
|
||||
|
@ -38,13 +38,13 @@ defmodule Shift73kWeb.ShiftTemplateLive.Index do
|
|||
defp apply_action(socket, :clone, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Clone Shift Template")
|
||||
|> assign(:shift_template, ShiftTemplates.get_shift_template!(id))
|
||||
|> assign(:shift_template, Templates.get_shift_template!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Shift Template")
|
||||
|> assign(:shift_template, ShiftTemplates.get_shift_template!(id))
|
||||
|> assign(:shift_template, Templates.get_shift_template!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
|
@ -61,20 +61,20 @@ defmodule Shift73kWeb.ShiftTemplateLive.Index do
|
|||
|
||||
defp assign_shift_templates(socket) do
|
||||
%User{id: uid} = socket.assigns.current_user
|
||||
user_shifts = ShiftTemplates.list_shift_templates_by_user_id(uid)
|
||||
user_shifts = Templates.list_shift_templates_by_user_id(uid)
|
||||
assign(socket, :shift_templates, user_shifts)
|
||||
end
|
||||
|
||||
defp shift_template_from_params(params)
|
||||
|
||||
defp shift_template_from_params(%{"id" => id}),
|
||||
do: ShiftTemplates.get_shift_template!(id)
|
||||
do: Templates.get_shift_template!(id)
|
||||
|
||||
defp shift_template_from_params(_params), do: %ShiftTemplate{}
|
||||
|
||||
@impl true
|
||||
def handle_event("delete-modal", %{"id" => id}, socket) do
|
||||
{:noreply, assign(socket, :delete_shift_template, ShiftTemplates.get_shift_template!(id))}
|
||||
{:noreply, assign(socket, :delete_shift_template, Templates.get_shift_template!(id))}
|
||||
end
|
||||
|
||||
def handle_event("set-user-fave-shift-template", %{"id" => shift_template_id}, socket) do
|
||||
|
@ -99,8 +99,8 @@ defmodule Shift73kWeb.ShiftTemplateLive.Index do
|
|||
|
||||
# @impl true
|
||||
# def handle_event("delete", %{"id" => id}, socket) do
|
||||
# shift_template = ShiftTemplates.get_shift_template!(id)
|
||||
# {:ok, _} = ShiftTemplates.delete_shift_template(shift_template)
|
||||
# shift_template = Templates.get_shift_template!(id)
|
||||
# {:ok, _} = Templates.delete_shift_template(shift_template)
|
||||
|
||||
# {:noreply, assign_shift_templates(socket)}
|
||||
# end
|
||||
|
|
|
@ -4,7 +4,7 @@ defmodule Shift73kWeb.Roles do
|
|||
"""
|
||||
|
||||
alias Shift73k.Accounts.User
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
||||
@type entity :: struct()
|
||||
@type action :: :new | :index | :edit | :show | :delete | :edit_role
|
||||
|
@ -12,7 +12,7 @@ defmodule Shift73kWeb.Roles do
|
|||
|
||||
def can?(user, entity, action)
|
||||
|
||||
# ShiftTemplates / ShiftTemplate
|
||||
# Shifts.Templates / ShiftTemplate
|
||||
def can?(%User{role: :admin}, %ShiftTemplate{}, _any), do: true
|
||||
def can?(%User{}, %ShiftTemplate{}, :index), do: true
|
||||
def can?(%User{}, %ShiftTemplate{}, :new), do: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue