switched to 'native' Ecto.Enum for user week_starts_at field
This commit is contained in:
parent
4c673508b5
commit
aabcd9e029
6 changed files with 15 additions and 16 deletions
lib
|
@ -2,8 +2,8 @@ defmodule Shift73k.Accounts.User do
|
|||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
import EctoEnum
|
||||
import Shift73k.Util.Dt, only: [weekdays: 0]
|
||||
|
||||
alias Shift73k.EctoEnums.WeekdayEnum
|
||||
alias Shift73k.Shifts.Templates.ShiftTemplate
|
||||
alias Shift73k.Shifts.Shift
|
||||
|
||||
|
@ -29,7 +29,7 @@ defmodule Shift73k.Accounts.User do
|
|||
field(:confirmed_at, :naive_datetime)
|
||||
|
||||
field(:role, RolesEnum, default: :user)
|
||||
field(:week_start_at, WeekdayEnum, default: 1)
|
||||
field(:week_start_at, Ecto.Enum, values: weekdays(), default: :monday)
|
||||
|
||||
has_many(:shift_templates, ShiftTemplate)
|
||||
belongs_to(:fave_shift_template, ShiftTemplate)
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
defmodule Shift73k.EctoEnums do
|
||||
import EctoEnum
|
||||
|
||||
@weekdays [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday]
|
||||
|> Enum.with_index(1)
|
||||
|
||||
defenum(WeekdayEnum, @weekdays)
|
||||
end
|
|
@ -2,5 +2,9 @@ defmodule Shift73k.Util.Dt do
|
|||
@app_vars Application.get_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]
|
||||
|
||||
def app_time_zone, do: @app_time_zone
|
||||
|
||||
def weekdays, do: @weekdays
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Shift73kWeb.UserLive.Settings.WeekStart do
|
||||
use Shift73kWeb, :live_component
|
||||
import Shift73k.Util.Dt, only: [weekdays: 0]
|
||||
|
||||
alias Shift73k.EctoEnums.WeekdayEnum
|
||||
alias Shift73k.Accounts
|
||||
|
||||
@impl true
|
||||
|
@ -14,13 +14,12 @@ defmodule Shift73kWeb.UserLive.Settings.WeekStart do
|
|||
end
|
||||
|
||||
def week_start_options do
|
||||
{week_start_at, _} = WeekdayEnum.__enum_map__() |> hd()
|
||||
week_start = Date.beginning_of_week(Date.utc_today(), week_start_at)
|
||||
week_start = Date.beginning_of_week(Date.utc_today(), hd(weekdays()))
|
||||
|
||||
week_start
|
||||
|> Date.range(Date.add(week_start, 6))
|
||||
|> Enum.map(&Calendar.strftime(&1, "%A"))
|
||||
|> Enum.zip(Keyword.keys(WeekdayEnum.__enum_map__()))
|
||||
|> Enum.zip(weekdays())
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue