chore: remove unused stuff
This commit is contained in:
parent
f34936b176
commit
af1e2eb06f
4 changed files with 0 additions and 201 deletions
|
|
@ -1,76 +0,0 @@
|
|||
defmodule PutzplanWeb.CompletedTaskLive.FormComponent do
|
||||
use PutzplanWeb, :live_component
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<.header>
|
||||
{@title}
|
||||
<:subtitle>Use this form to manage completed_task records in your database.</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.simple_form
|
||||
for={@form}
|
||||
id="completed_task-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
<.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>
|
||||
</.simple_form>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def update(assigns, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign_form()}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate", %{"completed_task" => completed_task_params}, socket) do
|
||||
{:noreply,
|
||||
assign(socket, form: AshPhoenix.Form.validate(socket.assigns.form, completed_task_params))}
|
||||
end
|
||||
|
||||
def handle_event("save", %{"completed_task" => completed_task_params}, socket) do
|
||||
case AshPhoenix.Form.submit(socket.assigns.form, params: completed_task_params) do
|
||||
{:ok, completed_task} ->
|
||||
notify_parent({:saved, completed_task})
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> put_flash(:info, "Completed task created successfully")
|
||||
|> push_patch(to: socket.assigns.patch)
|
||||
|
||||
{:noreply, socket}
|
||||
|
||||
{:error, form} ->
|
||||
{:noreply, assign(socket, form: form)}
|
||||
end
|
||||
end
|
||||
|
||||
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||
|
||||
defp assign_form(%{assigns: %{completed_task: completed_task}} = socket) do
|
||||
form =
|
||||
AshPhoenix.Form.for_create(completed_task, :create,
|
||||
as: "completed_task",
|
||||
actor: socket.assigns.current_user
|
||||
)
|
||||
|
||||
assign(socket, form: to_form(form))
|
||||
end
|
||||
end
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
defmodule PutzplanWeb.CompletedTaskLive.Index do
|
||||
use PutzplanWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.header>
|
||||
Listing Completed tasks
|
||||
<:actions>
|
||||
<.link patch={~p"/completed_tasks/new"}>
|
||||
<.button>New Completed task</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.table
|
||||
id="completed_tasks"
|
||||
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>
|
||||
|
||||
<: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>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> stream(
|
||||
:completed_tasks,
|
||||
Ash.read!(Putzplan.Tasks.CompletedTask, actor: socket.assigns[:current_user])
|
||||
)
|
||||
|> assign_new(:current_user, fn -> nil end)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Completed task")
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing Completed tasks")
|
||||
|> assign(:completed_task, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({PutzplanWeb.CompletedTaskLive.FormComponent, {:saved, completed_task}}, socket) do
|
||||
{:noreply, stream_insert(socket, :completed_tasks, completed_task)}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
defmodule PutzplanWeb.CompletedTaskLive.Show do
|
||||
use PutzplanWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.header>
|
||||
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>
|
||||
</.list>
|
||||
|
||||
<.back navigate={~p"/completed_tasks"}>Back to completed_tasks</.back>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
actor = socket.assigns.current_user
|
||||
completed_task = Ash.get!(Putzplan.Tasks.CompletedTask, id, actor: actor)
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(
|
||||
:completed_task,
|
||||
completed_task
|
||||
)}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Completed task"
|
||||
defp page_title(:edit), do: "Edit Completed task"
|
||||
end
|
||||
|
|
@ -45,10 +45,6 @@ defmodule PutzplanWeb.Router do
|
|||
|
||||
live "/tasks/:id", TaskLive.Show, :show
|
||||
live "/tasks/:id/show/edit", TaskLive.Show, :edit
|
||||
|
||||
live "/completed_tasks", CompletedTaskLive.Index, :index
|
||||
live "/completed_tasks/new", CompletedTaskLive.Index, :new
|
||||
live "/completed_tasks/:id", CompletedTaskLive.Show, :show
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue