diff --git a/lib/planner/tasks.ex b/lib/planner/tasks.ex index a92dd6a..a587998 100644 --- a/lib/planner/tasks.ex +++ b/lib/planner/tasks.ex @@ -32,13 +32,13 @@ defmodule Planner.Tasks do |> Repo.preload(:plans) 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 = Ecto.Query.from( t in Task, join: pd in PlanDetail, 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] ) diff --git a/lib/planner_web/live/tasks_components.ex b/lib/planner_web/live/tasks_components.ex index 635a014..41bf8e6 100644 --- a/lib/planner_web/live/tasks_components.ex +++ b/lib/planner_web/live/tasks_components.ex @@ -74,13 +74,18 @@ defmodule TaskComponent do
  • - + <%= case @task.finished_at do %> + <% nil -> %> + + <% _ -> %> + ! + <% end %>
    <%= if(@is_active) do %> @@ -134,12 +139,16 @@ defmodule TaskDetailsComponent do 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) or not is_nil(@task.finished_at) or length(@task.plans) == 0) do %>
    <%= if(not is_nil(@task.due_at)) do %> due: <%= @task.due_at %> <% end %> + <%= if(not is_nil(@task.finished_at)) do %> + + completed + <% end %> <%= if(length(@task.plans) == 0) do %> unfiled diff --git a/lib/planner_web/live/tasks_live.ex b/lib/planner_web/live/tasks_live.ex index 2e0dcb7..2e5f727 100644 --- a/lib/planner_web/live/tasks_live.ex +++ b/lib/planner_web/live/tasks_live.ex @@ -20,7 +20,7 @@ defmodule PlannerWeb.TasksLive do socket |> assign(:active_task, task_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) {:noreply, socket} @@ -188,7 +188,8 @@ defmodule PlannerWeb.TasksLive do def handle_event("finish-task", %{"task-id" => task_id}, socket) do {_, 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 def handle_event("new-task", %{"task" => task_params}, socket) do