style: formatter seems to work now
This commit is contained in:
parent
70aeb019a5
commit
f34936b176
11 changed files with 117 additions and 116 deletions
|
|
@ -10,6 +10,6 @@
|
||||||
:phoenix
|
:phoenix
|
||||||
],
|
],
|
||||||
subdirectories: ["priv/*/migrations"],
|
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"]
|
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,11 @@ defmodule Putzplan.Accounts.User do
|
||||||
client_secret "insecure_secret"
|
client_secret "insecure_secret"
|
||||||
nonce true
|
nonce true
|
||||||
redirect_uri "http://127.0.0.1:4000/auth"
|
redirect_uri "http://127.0.0.1:4000/auth"
|
||||||
authorization_params [scope: "profile email"]
|
authorization_params scope: "profile email"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
identities do
|
|
||||||
identity :id, [:id]
|
|
||||||
end
|
|
||||||
|
|
||||||
sqlite do
|
sqlite do
|
||||||
table "users"
|
table "users"
|
||||||
repo Putzplan.Repo
|
repo Putzplan.Repo
|
||||||
|
|
@ -85,4 +81,8 @@ defmodule Putzplan.Accounts.User do
|
||||||
uuid_primary_key :id, writable?: true, default: nil
|
uuid_primary_key :id, writable?: true, default: nil
|
||||||
attribute :name, :string, allow_nil?: false
|
attribute :name, :string, allow_nil?: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
identities do
|
||||||
|
identity :id, [:id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
defmodule Putzplan.Tasks.CompletedTask do
|
defmodule Putzplan.Tasks.CompletedTask do
|
||||||
use Ash.Resource, otp_app: :putzplan, domain: Putzplan.Tasks, data_layer: AshSqlite.DataLayer
|
use Ash.Resource, otp_app: :putzplan, domain: Putzplan.Tasks, data_layer: AshSqlite.DataLayer
|
||||||
|
|
||||||
|
sqlite do
|
||||||
|
table "completed_tasks"
|
||||||
|
repo Putzplan.Repo
|
||||||
|
end
|
||||||
|
|
||||||
actions do
|
actions do
|
||||||
defaults [:destroy]
|
defaults [:destroy]
|
||||||
|
|
||||||
|
|
@ -41,9 +46,4 @@ defmodule Putzplan.Tasks.CompletedTask do
|
||||||
source_attribute :task_id
|
source_attribute :task_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sqlite do
|
|
||||||
table "completed_tasks"
|
|
||||||
repo Putzplan.Repo
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,36 @@ defmodule Putzplan.Tasks.Task do
|
||||||
domain: Putzplan.Tasks,
|
domain: Putzplan.Tasks,
|
||||||
data_layer: AshSqlite.DataLayer
|
data_layer: AshSqlite.DataLayer
|
||||||
|
|
||||||
|
sqlite do
|
||||||
|
table "tasks"
|
||||||
|
repo Putzplan.Repo
|
||||||
|
end
|
||||||
|
|
||||||
actions do
|
actions do
|
||||||
defaults [:read, :destroy, create: :*, update: :*]
|
defaults [:read, :destroy, create: :*, update: :*]
|
||||||
end
|
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
|
calculations do
|
||||||
calculate :last_completed,
|
calculate :last_completed,
|
||||||
:date,
|
:date,
|
||||||
|
|
@ -32,30 +58,4 @@ defmodule Putzplan.Tasks.Task do
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,6 @@ defmodule PutzplanWeb.AuthOverrides do
|
||||||
# end
|
# end
|
||||||
|
|
||||||
override AshAuthentication.Phoenix.Components.SignIn do
|
override AshAuthentication.Phoenix.Components.SignIn do
|
||||||
set :show_banner, false
|
set :show_banner, false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ defmodule PutzplanWeb.CompletedTaskLive.FormComponent do
|
||||||
~H"""
|
~H"""
|
||||||
<div>
|
<div>
|
||||||
<.header>
|
<.header>
|
||||||
<%= @title %>
|
{@title}
|
||||||
<:subtitle>Use this form to manage completed_task records in your database.</:subtitle>
|
<:subtitle>Use this form to manage completed_task records in your database.</:subtitle>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|
@ -17,9 +17,12 @@ defmodule PutzplanWeb.CompletedTaskLive.FormComponent do
|
||||||
phx-change="validate"
|
phx-change="validate"
|
||||||
phx-submit="save"
|
phx-submit="save"
|
||||||
>
|
>
|
||||||
|
<.input field={@form[:user]} type="text" label="User" /><.input
|
||||||
<.input field={@form[:user]} type="text" label="User" /><.input field={@form[:task]} type="text" label="Task" />
|
field={@form[:task]}
|
||||||
|
type="text"
|
||||||
|
label="Task"
|
||||||
|
/>
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
<.button phx-disable-with="Saving...">Save Completed task</.button>
|
<.button phx-disable-with="Saving...">Save Completed task</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ defmodule PutzplanWeb.CompletedTaskLive.Index do
|
||||||
Listing Completed tasks
|
Listing Completed tasks
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link patch={~p"/completed_tasks/new"}>
|
<.link patch={~p"/completed_tasks/new"}>
|
||||||
<.button>New Completed task</.button>
|
<.button>New Completed task</.button>
|
||||||
</.link>
|
</.link>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
@ -18,31 +18,31 @@ defmodule PutzplanWeb.CompletedTaskLive.Index do
|
||||||
rows={@streams.completed_tasks}
|
rows={@streams.completed_tasks}
|
||||||
row_click={fn {_id, completed_task} -> JS.navigate(~p"/completed_tasks/#{completed_task}") end}
|
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}}>
|
<:action :let={{_id, completed_task}}>
|
||||||
<div class="sr-only">
|
<div class="sr-only">
|
||||||
<.link navigate={~p"/completed_tasks/#{completed_task}"}>Show</.link>
|
<.link navigate={~p"/completed_tasks/#{completed_task}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</:action>
|
</:action>
|
||||||
|
|
||||||
</.table>
|
</.table>
|
||||||
|
|
||||||
|
<.modal
|
||||||
<.modal :if={@live_action == :new} id="completed_task-modal" show on_cancel={JS.patch(~p"/completed_tasks")}>
|
:if={@live_action == :new}
|
||||||
<.live_component
|
id="completed_task-modal"
|
||||||
module={PutzplanWeb.CompletedTaskLive.FormComponent}
|
show
|
||||||
current_user={@current_user}
|
on_cancel={JS.patch(~p"/completed_tasks")}
|
||||||
id={:new}
|
>
|
||||||
title={@page_title}
|
<.live_component
|
||||||
action={@live_action}
|
module={PutzplanWeb.CompletedTaskLive.FormComponent}
|
||||||
completed_task={@completed_task}
|
current_user={@current_user}
|
||||||
patch={~p"/completed_tasks"}
|
id={:new}
|
||||||
/>
|
title={@page_title}
|
||||||
</.modal>
|
action={@live_action}
|
||||||
|
completed_task={@completed_task}
|
||||||
|
patch={~p"/completed_tasks"}
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,15 @@ defmodule PutzplanWeb.CompletedTaskLive.Show do
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
Completed task <%= @completed_task.id %>
|
Completed task {@completed_task.id}
|
||||||
<:subtitle>This is a completed_task record from your database.</:subtitle>
|
<:subtitle>This is a completed_task record from your database.</:subtitle>
|
||||||
|
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<.list>
|
<.list>
|
||||||
|
<:item title="Id">{@completed_task.id}</:item>
|
||||||
<:item title="Id"><%= @completed_task.id %></:item>
|
|
||||||
|
|
||||||
</.list>
|
</.list>
|
||||||
|
|
||||||
<.back navigate={~p"/completed_tasks"}>Back to completed_tasks</.back>
|
<.back navigate={~p"/completed_tasks"}>Back to completed_tasks</.back>
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ defmodule PutzplanWeb.TaskLive.FormComponent do
|
||||||
~H"""
|
~H"""
|
||||||
<div>
|
<div>
|
||||||
<.header>
|
<.header>
|
||||||
<%= @title %>
|
{@title}
|
||||||
<:subtitle>Use this form to manage task records in your database.</:subtitle>
|
<:subtitle>Use this form to manage task records in your database.</:subtitle>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|
@ -17,10 +17,12 @@ defmodule PutzplanWeb.TaskLive.FormComponent do
|
||||||
phx-change="validate"
|
phx-change="validate"
|
||||||
phx-submit="save"
|
phx-submit="save"
|
||||||
>
|
>
|
||||||
|
<.input field={@form[:description]} type="text" label="Description" /><.input
|
||||||
<.input field={@form[:description]} type="text" label="Description" /><.input field={@form[:repetition_days]} type="number" label="Repetition days" />
|
field={@form[:repetition_days]}
|
||||||
|
type="number"
|
||||||
|
label="Repetition days"
|
||||||
|
/>
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
<.button phx-disable-with="Saving...">Save Task</.button>
|
<.button phx-disable-with="Saving...">Save Task</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ defmodule PutzplanWeb.TaskLive.Index do
|
||||||
Listing Tasks
|
Listing Tasks
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link patch={~p"/tasks/new"}>
|
<.link patch={~p"/tasks/new"}>
|
||||||
<.button>New Task</.button>
|
<.button>New Task</.button>
|
||||||
</.link>
|
</.link>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
@ -18,21 +18,21 @@ defmodule PutzplanWeb.TaskLive.Index do
|
||||||
rows={@streams.tasks}
|
rows={@streams.tasks}
|
||||||
row_click={fn {_id, task} -> JS.navigate(~p"/tasks/#{task}") end}
|
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}}>
|
<:action :let={{_id, task}}>
|
||||||
<div class="sr-only">
|
<div class="sr-only">
|
||||||
<.link navigate={~p"/tasks/#{task}"}>Show</.link>
|
<.link navigate={~p"/tasks/#{task}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.link patch={~p"/tasks/#{task}/edit"}>Edit</.link>
|
|
||||||
<.link phx-click={JS.push("complete", value: %{id: task.id})}>Complete</.link>
|
|
||||||
|
|
||||||
</:action>
|
</: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}}>
|
<:action :let={{id, task}}>
|
||||||
<.link
|
<.link
|
||||||
phx-click={JS.push("delete", value: %{id: task.id}) |> hide("##{id}")}
|
phx-click={JS.push("delete", value: %{id: task.id}) |> hide("##{id}")}
|
||||||
|
|
@ -41,19 +41,19 @@ defmodule PutzplanWeb.TaskLive.Index do
|
||||||
Delete
|
Delete
|
||||||
</.link>
|
</.link>
|
||||||
</:action>
|
</:action>
|
||||||
|
|
||||||
</.table>
|
</.table>
|
||||||
<.modal :if={@live_action in [:new, :edit]} id="task-modal" show on_cancel={JS.patch(~p"/tasks")}>
|
|
||||||
<.live_component
|
<.modal :if={@live_action in [:new, :edit]} id="task-modal" show on_cancel={JS.patch(~p"/tasks")}>
|
||||||
module={PutzplanWeb.TaskLive.FormComponent}
|
<.live_component
|
||||||
id={(@task && @task.id) || :new}
|
module={PutzplanWeb.TaskLive.FormComponent}
|
||||||
title={@page_title}
|
id={(@task && @task.id) || :new}
|
||||||
current_user={@current_user}
|
title={@page_title}
|
||||||
action={@live_action}
|
current_user={@current_user}
|
||||||
task={@task}
|
action={@live_action}
|
||||||
patch={~p"/"}
|
task={@task}
|
||||||
/>
|
patch={~p"/"}
|
||||||
</.modal>
|
/>
|
||||||
|
</.modal>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -76,7 +76,10 @@ defmodule PutzplanWeb.TaskLive.Index do
|
||||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||||
socket
|
socket
|
||||||
|> assign(:page_title, "Edit Task")
|
|> 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
|
end
|
||||||
|
|
||||||
defp apply_action(socket, :new, _params) do
|
defp apply_action(socket, :new, _params) do
|
||||||
|
|
@ -109,7 +112,7 @@ defmodule PutzplanWeb.TaskLive.Index do
|
||||||
Putzplan.Tasks.CompletedTask
|
Putzplan.Tasks.CompletedTask
|
||||||
|> Ash.Changeset.for_create(:create, %{task: id, user: socket.assigns.current_user.id})
|
|> Ash.Changeset.for_create(:create, %{task: id, user: socket.assigns.current_user.id})
|
||||||
|> Ash.create!(actor: socket.assigns.current_user)
|
|> Ash.create!(actor: socket.assigns.current_user)
|
||||||
|
|
||||||
{:noreply, stream_insert(socket, :tasks, Ash.get!(Putzplan.Tasks.Task, id, load: [:due]))}
|
{:noreply, stream_insert(socket, :tasks, Ash.get!(Putzplan.Tasks.Task, id, load: [:due]))}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,22 @@ defmodule PutzplanWeb.TaskLive.Show do
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
Task <%= @task.description %>
|
Task {@task.description}
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}>
|
<.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}>
|
||||||
<.button>Edit task</.button>
|
<.button>Edit task</.button>
|
||||||
</.link>
|
</.link>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<.table
|
<.table id="completed_tasks" rows={@streams.completed_tasks}>
|
||||||
id="completed_tasks"
|
<:col :let={{_id, completed_task}} label="Completed by">{completed_task.users.name}</:col>
|
||||||
rows={@streams.completed_tasks}
|
<:col :let={{_id, completed_task}} label="Date">{completed_task.completion}</:col>
|
||||||
>
|
<:action :let={{id, completed_task}}>
|
||||||
<:col :let={{_id, completed_task}} label="Completed by"><%= completed_task.users.name %></:col>
|
<.link phx-click={JS.push("delete", value: %{id: completed_task.id}) |> hide("##{id}")}>
|
||||||
<:col :let={{_id, completed_task}} label="Date"><%= completed_task.completion %></:col>
|
Delete
|
||||||
<:action :let={{id, completed_task}}>
|
</.link>
|
||||||
<.link phx-click={JS.push("delete", value: %{id: completed_task.id}) |> hide("##{id}")}>
|
</:action>
|
||||||
Delete
|
|
||||||
</.link>
|
|
||||||
</:action>
|
|
||||||
</.table>
|
</.table>
|
||||||
|
|
||||||
<.back navigate={~p"/"}>Back to tasks</.back>
|
<.back navigate={~p"/"}>Back to tasks</.back>
|
||||||
|
|
@ -58,7 +54,9 @@ defmodule PutzplanWeb.TaskLive.Show do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("delete", %{"id" => id}, socket) do
|
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)
|
Ash.destroy!(completed_task, actor: socket.assigns.current_user)
|
||||||
|
|
||||||
{:noreply, stream_delete(socket, :completed_tasks, completed_task)}
|
{:noreply, stream_delete(socket, :completed_tasks, completed_task)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue