defmodule TasksComponent do use PlannerWeb, :live_component alias Planner.Tasks alias Planner.Tasks.Task def update(%{:changeset => changeset, :id => _id}, socket) do {:ok, assign(socket, :changeset, changeset)} end def update(assigns, socket) do socket = socket |> assign(assigns) |> assign(:changeset, Tasks.change_task(%Task{})) {:ok, socket} end def render(assigns) do ~L"""
<%= f = form_for(@changeset, "#", [phx_submit: "new-task"]) %>
<%= text_input(f, :value, placeholder: "add new task", class: "input", autocomplete: "off" )%>
<%= error_tag(f, :value) %>
<%= if(!is_nil(@active_plan)) do %> <% end %>
""" end end defmodule TaskComponent do use Phoenix.LiveComponent import PlannerWeb.Util def render(assigns) do ~L"""
  • <%= if(@is_active) do %> <%= case @live_action do %> <% :show_task -> %> <%= live_component(@socket, TaskDetailsComponent, id: "task_details:#{@task.id}", task: @task, route_index_tasks: @route_index_tasks, route_edit_task: @route_edit_task )%> <% :edit_task -> %> <%= live_component(@socket, TaskEditComponent, id: "task_edit:#{@task.id}", task: @task, plans: @plans )%> <% end %> <% else %> <%= live_patch(to: @route_show_task.(@socket, @task.id), style: "display: block;" ) do %>
    <%= md_to_html(@task.value) %>
    <% end %> <%= if(not is_nil(@task.due_at)) do %>
    due: <%= @task.due_at %>
    <% end %> <% end %>
  • """ end end defmodule TaskDetailsComponent do use PlannerWeb, :live_component def render(assigns) do ~L"""
    <%= live_patch("", to: @route_index_tasks.(@socket), class: "delete is-pulled-right" ) %> <%= if(not is_nil(@task.due_at) or length(@task.plans) == 0) do %>
    <%= if(not is_nil(@task.due_at)) do %> due: <%= @task.due_at %> <% end %> <%= if(length(@task.plans) == 0) do %> unfiled <% end %>
    <% end %>
    <%= md_to_html(@task.value) %>
    updated: <%= @task.updated_at %> created: <%= @task.inserted_at %>
    <%= live_patch("edit", to: @route_edit_task.(@socket, @task.id), class: "button is-dark is-small" ) %>
    """ end end defmodule TaskEditComponent do use PlannerWeb, :live_component alias Planner.Tasks def update(%{:changeset => changeset, :id => _id}, socket) do {:ok, assign(socket, :changeset, changeset)} end def update(assigns, socket) do socket = socket |> assign(assigns) |> assign(:changeset, Tasks.change_task(assigns.task)) {:ok, socket} end def render(assigns) do ~L"""
    <%= f = form_for(@changeset, "#", [phx_submit: "save-task"]) %> <%= hidden_input(f, :id) %>
    <%= textarea(f, :value, required: true, class: "textarea", placeholder: "task", autocomplete: "off" ) %>
    <%= error_tag(f, :value) %>
    <%= label(f, :due_at, class: "label") do %> due (YYYY-MM-DD HH:MM:SS) <% end %>
    <%= text_input(f, :due_at, class: "input", placeholder: "YYYY-MM-DD HH:MM:SS", autocomplete: "off" ) %>
    <%= error_tag(f, :due_at) %>
    <%= multiple_select(f, :plans, Enum.map(@plans, &({&1.name, &1.id})), selected: Enum.map(@task.plans, &(&1.id)) ) %>
    <%= submit("save", class: "button is-dark is-small") %>
    """ end end