some improved code via credo, sobelow
This commit is contained in:
parent
f270bab7e4
commit
1f99611b56
8 changed files with 40 additions and 36 deletions
lib
|
@ -7,7 +7,7 @@ defmodule Shift73k do
|
|||
if it comes from the database, an external API or others.
|
||||
"""
|
||||
|
||||
@app_vars Application.get_env(:shift73k, :app_global_vars, time_zone: "America/New_York")
|
||||
@app_vars Application.compile_env(:shift73k, :app_global_vars, time_zone: "America/New_York")
|
||||
@app_time_zone @app_vars[:time_zone]
|
||||
|
||||
@weekdays [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Shift73k.Mailer.UserEmail do
|
||||
import Bamboo.Email
|
||||
|
||||
@mailer_vars Application.get_env(:shift73k, :app_global_vars,
|
||||
@mailer_vars Application.compile_env(:shift73k, :app_global_vars,
|
||||
mailer_reply_to: "admin@example.com",
|
||||
mailer_from: {"Shift73k", "shift73k@example.com"}
|
||||
)
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
defmodule Shift73k.Shifts.Templates.ShiftTemplate do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
import Shift73k, only: [app_time_zone: 0]
|
||||
|
||||
alias Shift73k.Shifts
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
|
||||
@app_vars Application.get_env(:shift73k, :app_global_vars, time_zone: "America/New_York")
|
||||
@time_zone @app_vars[:time_zone]
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
schema "shift_templates" do
|
||||
field :subject, :string
|
||||
field :description, :string
|
||||
field :location, :string
|
||||
field :time_zone, :string, default: @time_zone
|
||||
field :time_zone, :string, default: app_time_zone()
|
||||
field :time_start, :time, default: ~T[09:00:00]
|
||||
field :time_end, :time, default: ~T[17:00:00]
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ defmodule Shift73kWeb do
|
|||
|
||||
@impl true
|
||||
def handle_info(%{event: "logout_user", payload: %{user: %User{id: id}}}, socket) do
|
||||
with %User{id: ^id} <- socket.assigns.current_user do
|
||||
{:noreply,
|
||||
socket
|
||||
|> redirect(to: Routes.user_session_path(socket, :force_logout))}
|
||||
else
|
||||
_any -> {:noreply, socket}
|
||||
case socket.assigns.current_user do
|
||||
%User{id: ^id} ->
|
||||
{:noreply, redirect(socket, to: Routes.user_session_path(socket, :force_logout))}
|
||||
|
||||
_ ->
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -181,6 +181,14 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do
|
|||
|> assign_known_shifts()
|
||||
end
|
||||
|
||||
defp new_nav_cursor("now", _cursor_date), do: Date.utc_today()
|
||||
|
||||
defp new_nav_cursor(nav, cursor_date) do
|
||||
cursor_date
|
||||
|> Date.add((nav == "prev" && -30) || 30)
|
||||
|> cursor_date()
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate-shift-template", %{"shift_template" => params}, socket) do
|
||||
params = prep_template_params(params, socket.assigns.current_user)
|
||||
|
@ -214,16 +222,7 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do
|
|||
|
||||
@impl true
|
||||
def handle_event("month-nav", %{"month" => nav}, socket) do
|
||||
new_cursor =
|
||||
cond do
|
||||
nav == "now" ->
|
||||
Date.utc_today()
|
||||
|
||||
true ->
|
||||
socket.assigns.cursor_date
|
||||
|> Date.add((nav == "prev" && -30) || 30)
|
||||
|> cursor_date()
|
||||
end
|
||||
new_cursor = new_nav_cursor(nav, socket.assigns.cursor_date)
|
||||
|
||||
socket
|
||||
|> assign(:cursor_date, new_cursor)
|
||||
|
|
|
@ -86,20 +86,19 @@ defmodule Shift73kWeb.ShiftLive.Index do
|
|||
|
||||
@impl true
|
||||
def handle_event("month-nav", %{"month" => nav}, socket) do
|
||||
new_cursor =
|
||||
cond do
|
||||
nav == "now" ->
|
||||
Date.utc_today()
|
||||
|
||||
true ->
|
||||
socket.assigns.cursor_date
|
||||
|> Date.add((nav == "prev" && -30) || 30)
|
||||
|> cursor_date()
|
||||
end
|
||||
new_cursor = new_nav_cursor(nav, socket.assigns.cursor_date)
|
||||
|
||||
socket
|
||||
|> assign(:cursor_date, new_cursor)
|
||||
|> update_agenda()
|
||||
|> live_noreply()
|
||||
end
|
||||
|
||||
defp new_nav_cursor("now", _cursor_date), do: Date.utc_today()
|
||||
|
||||
defp new_nav_cursor(nav, cursor_date) do
|
||||
cursor_date
|
||||
|> Date.add((nav == "prev" && -30) || 30)
|
||||
|> cursor_date()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue