url-hack tasks (#64)

This commit is contained in:
Matthew Ryan Dillon 2020-11-21 20:00:36 -07:00 committed by GitHub
parent 55763c0698
commit 8c09142f8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 12 deletions

View file

@ -32,13 +32,13 @@ defmodule Planner.Tasks do
|> Repo.preload(:plans) |> Repo.preload(:plans)
end end
def list_unfinished_tasks_by_plan_id(plan_id) do def list_unfinished_tasks_by_plan_id(plan_id, task_id \\ nil) do
q = q =
Ecto.Query.from( Ecto.Query.from(
t in Task, t in Task,
join: pd in PlanDetail, join: pd in PlanDetail,
on: t.id == pd.task_id, on: t.id == pd.task_id,
where: pd.plan_id == ^plan_id and is_nil(t.finished_at), where: (pd.plan_id == ^plan_id and is_nil(t.finished_at)) or t.id == ^task_id,
order_by: [desc: t.updated_at] order_by: [desc: t.updated_at]
) )

View file

@ -74,13 +74,18 @@ defmodule TaskComponent do
<li> <li>
<div> <div>
<div class="is-pulled-left"> <div class="is-pulled-left">
<button <%= case @task.finished_at do %>
type="button" <% nil -> %>
role="checkbox" <button
class="doit" type="button"
phx-click="finish-task" role="checkbox"
phx-value-task-id="<%= @task.id %>"> class="doit"
</button> phx-click="finish-task"
phx-value-task-id="<%= @task.id %>">
</button>
<% _ -> %>
!
<% end %>
</div> </div>
<div class="ml-5-5"> <div class="ml-5-5">
<%= if(@is_active) do %> <%= if(@is_active) do %>
@ -134,12 +139,16 @@ defmodule TaskDetailsComponent do
to: @route_index_tasks.(@socket), to: @route_index_tasks.(@socket),
class: "delete is-pulled-right" 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) or not is_nil(@task.finished_at) or length(@task.plans) == 0) do %>
<div class="tags"> <div class="tags">
<%= if(not is_nil(@task.due_at)) do %> <%= if(not is_nil(@task.due_at)) do %>
<span class="tag is-warning"> <span class="tag is-warning">
due: <%= @task.due_at %> due: <%= @task.due_at %>
</span><% end %> </span><% end %>
<%= if(not is_nil(@task.finished_at)) do %>
<span class="tag is-success">
completed
</span><% end %>
<%= if(length(@task.plans) == 0) do %> <%= if(length(@task.plans) == 0) do %>
<span class="tag is-danger"> <span class="tag is-danger">
unfiled unfiled

View file

@ -20,7 +20,7 @@ defmodule PlannerWeb.TasksLive do
socket socket
|> assign(:active_task, task_id) |> assign(:active_task, task_id)
|> assign(:active_plan, Tasks.get_plan!(plan_id)) |> assign(:active_plan, Tasks.get_plan!(plan_id))
|> assign(:tasks, Tasks.list_unfinished_tasks_by_plan_id(plan_id)) |> assign(:tasks, Tasks.list_unfinished_tasks_by_plan_id(plan_id, task_id))
|> add_plan_routes(plan_id) |> add_plan_routes(plan_id)
{:noreply, socket} {:noreply, socket}
@ -188,7 +188,8 @@ defmodule PlannerWeb.TasksLive do
def handle_event("finish-task", %{"task-id" => task_id}, socket) do def handle_event("finish-task", %{"task-id" => task_id}, socket) do
{_, task} = Tasks.finish_task_by_id!(task_id) {_, task} = Tasks.finish_task_by_id!(task_id)
{:noreply, refresh_tasks_and_flash_msg(socket, "task \"#{task.value}\" completed")} route = get_index_route(socket)
{:noreply, push_patch(socket, to: route)}
end end
def handle_event("new-task", %{"task" => task_params}, socket) do def handle_event("new-task", %{"task" => task_params}, socket) do