style: formatter seems to work now

This commit is contained in:
Moritz Böhme 2025-04-07 15:03:53 +02:00
parent 70aeb019a5
commit f34936b176
11 changed files with 117 additions and 116 deletions

View file

@ -10,6 +10,6 @@
:phoenix
],
subdirectories: ["priv/*/migrations"],
# plugins: [Spark.Formatter, Phoenix.LiveView.HTMLFormatter], # FIXME:seems broken
plugins: [Spark.Formatter, Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]

View file

@ -28,15 +28,11 @@ defmodule Putzplan.Accounts.User do
client_secret "insecure_secret"
nonce true
redirect_uri "http://127.0.0.1:4000/auth"
authorization_params [scope: "profile email"]
authorization_params scope: "profile email"
end
end
end
identities do
identity :id, [:id]
end
sqlite do
table "users"
repo Putzplan.Repo
@ -85,4 +81,8 @@ defmodule Putzplan.Accounts.User do
uuid_primary_key :id, writable?: true, default: nil
attribute :name, :string, allow_nil?: false
end
identities do
identity :id, [:id]
end
end

View file

@ -1,6 +1,11 @@
defmodule Putzplan.Tasks.CompletedTask do
use Ash.Resource, otp_app: :putzplan, domain: Putzplan.Tasks, data_layer: AshSqlite.DataLayer
sqlite do
table "completed_tasks"
repo Putzplan.Repo
end
actions do
defaults [:destroy]
@ -41,9 +46,4 @@ defmodule Putzplan.Tasks.CompletedTask do
source_attribute :task_id
end
end
sqlite do
table "completed_tasks"
repo Putzplan.Repo
end
end

View file

@ -4,10 +4,36 @@ defmodule Putzplan.Tasks.Task do
domain: Putzplan.Tasks,
data_layer: AshSqlite.DataLayer
sqlite do
table "tasks"
repo Putzplan.Repo
end
actions do
defaults [:read, :destroy, create: :*, update: :*]
end
# Attributes are the simple pieces of data that exist on your resource
attributes do
# Add an autogenerated UUID primary key called `:id`.
uuid_primary_key :id
attribute :description, :string do
allow_nil? false
public? true
end
attribute :repetition_days, :integer do
allow_nil? false
public? true
constraints min: 1
end
end
relationships do
has_many :completed_tasks, Putzplan.Tasks.CompletedTask
end
calculations do
calculate :last_completed,
:date,
@ -32,30 +58,4 @@ defmodule Putzplan.Tasks.Task do
)
)
end
sqlite do
table "tasks"
repo Putzplan.Repo
end
relationships do
has_many :completed_tasks, Putzplan.Tasks.CompletedTask
end
# Attributes are the simple pieces of data that exist on your resource
attributes do
# Add an autogenerated UUID primary key called `:id`.
uuid_primary_key :id
attribute :description, :string do
allow_nil? false
public? true
end
attribute :repetition_days, :integer do
allow_nil? false
public? true
constraints min: 1
end
end
end

View file

@ -15,6 +15,6 @@ defmodule PutzplanWeb.AuthOverrides do
# end
override AshAuthentication.Phoenix.Components.SignIn do
set :show_banner, false
set :show_banner, false
end
end

View file

@ -6,7 +6,7 @@ defmodule PutzplanWeb.CompletedTaskLive.FormComponent do
~H"""
<div>
<.header>
<%= @title %>
{@title}
<:subtitle>Use this form to manage completed_task records in your database.</:subtitle>
</.header>
@ -17,9 +17,12 @@ defmodule PutzplanWeb.CompletedTaskLive.FormComponent do
phx-change="validate"
phx-submit="save"
>
<.input field={@form[:user]} type="text" label="User" /><.input field={@form[:task]} type="text" label="Task" />
<.input field={@form[:user]} type="text" label="User" /><.input
field={@form[:task]}
type="text"
label="Task"
/>
<:actions>
<.button phx-disable-with="Saving...">Save Completed task</.button>
</:actions>

View file

@ -8,7 +8,7 @@ defmodule PutzplanWeb.CompletedTaskLive.Index do
Listing Completed tasks
<:actions>
<.link patch={~p"/completed_tasks/new"}>
<.button>New Completed task</.button>
<.button>New Completed task</.button>
</.link>
</:actions>
</.header>
@ -18,31 +18,31 @@ defmodule PutzplanWeb.CompletedTaskLive.Index do
rows={@streams.completed_tasks}
row_click={fn {_id, completed_task} -> JS.navigate(~p"/completed_tasks/#{completed_task}") end}
>
<:col :let={{_id, completed_task}} label="Id"><%= completed_task.id %></:col>
<:col :let={{_id, completed_task}} label="Id">{completed_task.id}</:col>
<:action :let={{_id, completed_task}}>
<div class="sr-only">
<.link navigate={~p"/completed_tasks/#{completed_task}"}>Show</.link>
</div>
</:action>
</.table>
<.modal :if={@live_action == :new} id="completed_task-modal" show on_cancel={JS.patch(~p"/completed_tasks")}>
<.live_component
module={PutzplanWeb.CompletedTaskLive.FormComponent}
current_user={@current_user}
id={:new}
title={@page_title}
action={@live_action}
completed_task={@completed_task}
patch={~p"/completed_tasks"}
/>
</.modal>
<.modal
:if={@live_action == :new}
id="completed_task-modal"
show
on_cancel={JS.patch(~p"/completed_tasks")}
>
<.live_component
module={PutzplanWeb.CompletedTaskLive.FormComponent}
current_user={@current_user}
id={:new}
title={@page_title}
action={@live_action}
completed_task={@completed_task}
patch={~p"/completed_tasks"}
/>
</.modal>
"""
end

View file

@ -5,20 +5,15 @@ defmodule PutzplanWeb.CompletedTaskLive.Show do
def render(assigns) do
~H"""
<.header>
Completed task <%= @completed_task.id %>
<:subtitle>This is a completed_task record from your database.</:subtitle>
Completed task {@completed_task.id}
<:subtitle>This is a completed_task record from your database.</:subtitle>
</.header>
<.list>
<:item title="Id"><%= @completed_task.id %></:item>
<:item title="Id">{@completed_task.id}</:item>
</.list>
<.back navigate={~p"/completed_tasks"}>Back to completed_tasks</.back>
"""
end

View file

@ -6,7 +6,7 @@ defmodule PutzplanWeb.TaskLive.FormComponent do
~H"""
<div>
<.header>
<%= @title %>
{@title}
<:subtitle>Use this form to manage task records in your database.</:subtitle>
</.header>
@ -17,10 +17,12 @@ defmodule PutzplanWeb.TaskLive.FormComponent do
phx-change="validate"
phx-submit="save"
>
<.input field={@form[:description]} type="text" label="Description" /><.input field={@form[:repetition_days]} type="number" label="Repetition days" />
<.input field={@form[:description]} type="text" label="Description" /><.input
field={@form[:repetition_days]}
type="number"
label="Repetition days"
/>
<:actions>
<.button phx-disable-with="Saving...">Save Task</.button>
</:actions>

View file

@ -8,7 +8,7 @@ defmodule PutzplanWeb.TaskLive.Index do
Listing Tasks
<:actions>
<.link patch={~p"/tasks/new"}>
<.button>New Task</.button>
<.button>New Task</.button>
</.link>
</:actions>
</.header>
@ -18,21 +18,21 @@ defmodule PutzplanWeb.TaskLive.Index do
rows={@streams.tasks}
row_click={fn {_id, task} -> JS.navigate(~p"/tasks/#{task}") end}
>
<:col :let={{_id, task}} label="Description">{task.description}</:col>
<:col :let={{_id, task}} label="Description"><%= task.description %></:col>
<:col :let={{_id, task}} label="Due"><%= task.due %></:col>
<:col :let={{_id, task}} label="Due">{task.due}</:col>
<:action :let={{_id, task}}>
<div class="sr-only">
<.link navigate={~p"/tasks/#{task}"}>Show</.link>
</div>
<.link patch={~p"/tasks/#{task}/edit"}>Edit</.link>
<.link phx-click={JS.push("complete", value: %{id: task.id})}>Complete</.link>
</:action>
<:action :let={{_id, task}}>
<.link patch={~p"/tasks/#{task}/edit"}>Edit</.link>
</:action>
<:action :let={{_id, task}}>
<.link phx-click={JS.push("complete", value: %{id: task.id})}>Complete</.link>
</:action>
<:action :let={{id, task}}>
<.link
phx-click={JS.push("delete", value: %{id: task.id}) |> hide("##{id}")}
@ -41,19 +41,19 @@ defmodule PutzplanWeb.TaskLive.Index do
Delete
</.link>
</:action>
</.table>
<.modal :if={@live_action in [:new, :edit]} id="task-modal" show on_cancel={JS.patch(~p"/tasks")}>
<.live_component
module={PutzplanWeb.TaskLive.FormComponent}
id={(@task && @task.id) || :new}
title={@page_title}
current_user={@current_user}
action={@live_action}
task={@task}
patch={~p"/"}
/>
</.modal>
<.modal :if={@live_action in [:new, :edit]} id="task-modal" show on_cancel={JS.patch(~p"/tasks")}>
<.live_component
module={PutzplanWeb.TaskLive.FormComponent}
id={(@task && @task.id) || :new}
title={@page_title}
current_user={@current_user}
action={@live_action}
task={@task}
patch={~p"/"}
/>
</.modal>
"""
end
@ -76,7 +76,10 @@ defmodule PutzplanWeb.TaskLive.Index do
defp apply_action(socket, :edit, %{"id" => id}) do
socket
|> assign(:page_title, "Edit Task")
|> assign(:task, Ash.get!(Putzplan.Tasks.Task, id, actor: socket.assigns.current_user))
|> assign(
:task,
Ash.get!(Putzplan.Tasks.Task, id, load: [:due], actor: socket.assigns.current_user)
)
end
defp apply_action(socket, :new, _params) do
@ -109,7 +112,7 @@ defmodule PutzplanWeb.TaskLive.Index do
Putzplan.Tasks.CompletedTask
|> Ash.Changeset.for_create(:create, %{task: id, user: socket.assigns.current_user.id})
|> Ash.create!(actor: socket.assigns.current_user)
{:noreply, stream_insert(socket, :tasks, Ash.get!(Putzplan.Tasks.Task, id, load: [:due]))}
end
end

View file

@ -6,26 +6,22 @@ defmodule PutzplanWeb.TaskLive.Show do
def render(assigns) do
~H"""
<.header>
Task <%= @task.description %>
<:actions>
<.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit task</.button>
</.link>
</:actions>
Task {@task.description}
<:actions>
<.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit task</.button>
</.link>
</:actions>
</.header>
<.table
id="completed_tasks"
rows={@streams.completed_tasks}
>
<:col :let={{_id, completed_task}} label="Completed by"><%= completed_task.users.name %></:col>
<:col :let={{_id, completed_task}} label="Date"><%= completed_task.completion %></:col>
<:action :let={{id, completed_task}}>
<.link phx-click={JS.push("delete", value: %{id: completed_task.id}) |> hide("##{id}")}>
Delete
</.link>
</:action>
<.table id="completed_tasks" rows={@streams.completed_tasks}>
<:col :let={{_id, completed_task}} label="Completed by">{completed_task.users.name}</:col>
<:col :let={{_id, completed_task}} label="Date">{completed_task.completion}</:col>
<:action :let={{id, completed_task}}>
<.link phx-click={JS.push("delete", value: %{id: completed_task.id}) |> hide("##{id}")}>
Delete
</.link>
</:action>
</.table>
<.back navigate={~p"/"}>Back to tasks</.back>
@ -58,7 +54,9 @@ defmodule PutzplanWeb.TaskLive.Show do
@impl true
def handle_event("delete", %{"id" => id}, socket) do
completed_task = Ash.get!(Putzplan.Tasks.CompletedTask, id, actor: socket.assigns.current_user)
completed_task =
Ash.get!(Putzplan.Tasks.CompletedTask, id, actor: socket.assigns.current_user)
Ash.destroy!(completed_task, actor: socket.assigns.current_user)
{:noreply, stream_delete(socket, :completed_tasks, completed_task)}