WIP
This commit is contained in:
parent
9044abed47
commit
4d327d751b
6 changed files with 18 additions and 8 deletions
|
@ -8,7 +8,7 @@ defmodule ChoreTracker.Accounts.User do
|
|||
field :hashed_password, :string, redact: true
|
||||
field :current_password, :string, virtual: true, redact: true
|
||||
field :confirmed_at, :utc_datetime
|
||||
# field :display_name, :string
|
||||
field :display_name, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ defmodule ChoreTracker.Accounts.User do
|
|||
"""
|
||||
def registration_changeset(user, attrs, opts \\ []) do
|
||||
user
|
||||
|> cast(attrs, [:email, :password])
|
||||
|> cast(attrs, [:email, :password, :display_name])
|
||||
|> validate_email(opts)
|
||||
|> validate_password(opts)
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ defmodule ChoreTracker.Chores do
|
|||
|
||||
"""
|
||||
def list_chores do
|
||||
Repo.all(Chore) |> Repo.preload(:logs)
|
||||
from(chore in Chore, preload: [:logs]) |> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -12,7 +12,7 @@ defmodule ChoreTracker.Chores.Chore do
|
|||
|
||||
timestamps(type: :utc_datetime)
|
||||
|
||||
has_many :logs, ChoreTracker.Chores.ChoreLog
|
||||
has_many :logs, ChoreTracker.Chores.ChoreLog, preload_order: [desc: :inserted_at]
|
||||
end
|
||||
|
||||
@doc false
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
<div class="col-span-12">
|
||||
<p class="text-sm font-medium text-zinc-500 mb-2">Logs</p>
|
||||
<.table id="chore_logs" rows={@chore.logs}>
|
||||
<:col :let={chore_log} label="User"><%= chore_log.user.email %></:col>
|
||||
<:col :let={chore_log} label="User"><%= chore_log.user.display_name %></:col>
|
||||
<:col :let={chore_log} label="Execution date"><%= chore_log.inserted_at %></:col>
|
||||
</.table>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,9 @@ defmodule ChoreTrackerWeb.OverviewLive do
|
|||
>
|
||||
<:col :let={chore}><span class="text-2xl"><%= chore.emoji %></span></:col>
|
||||
<:col :let={chore} label="Chore"><%= chore.name %></:col>
|
||||
<:col :let={chore} label="Last executed"><%= chore.logs |> length %></:col>
|
||||
<:col :let={chore} label="Last executed">
|
||||
<%= display_latest_log(chore) %>
|
||||
</:col>
|
||||
<:action :let={chore}>
|
||||
<.link
|
||||
phx-click={JS.push("log_execution", value: %{id: chore.id})}
|
||||
|
@ -47,7 +49,13 @@ defmodule ChoreTrackerWeb.OverviewLive do
|
|||
|
||||
def load_chores(socket) do
|
||||
chores = Chores.list_chores()
|
||||
dbg(chores)
|
||||
assign(socket, chores: chores)
|
||||
end
|
||||
|
||||
def display_latest_log(%Chores.Chore{} = chore) do
|
||||
case chore.logs |> List.first() do
|
||||
nil -> "Never"
|
||||
log -> log.inserted_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,8 @@ admin_password = ChoreTracker.Helpers.random_string(16)
|
|||
{:ok, admin} =
|
||||
ChoreTracker.Accounts.register_user(%{
|
||||
email: "admin@jednota.party",
|
||||
password: admin_password
|
||||
password: admin_password,
|
||||
display_name: "Admin"
|
||||
})
|
||||
|
||||
ChoreTracker.Chores.create_chore(%{
|
||||
|
|
Loading…
Reference in a new issue