diff --git a/lib/planner/tasks.ex b/lib/planner/tasks.ex index 5501510..23919e8 100644 --- a/lib/planner/tasks.ex +++ b/lib/planner/tasks.ex @@ -10,6 +10,18 @@ defmodule Planner.Tasks do def list_all_tasks, do: Repo.all(Task) + def list_unfiled_tasks do + filed_ids = from(pd in PlanDetail, select: pd.task_id) + + from( + t in Task, + where: is_nil(t.finished_at) and t.id not in subquery(filed_ids), + order_by: [desc: t.updated_at] + ) + |> Repo.all() + |> Repo.preload(:plans) + end + def list_unfinished_tasks do from( t in Task, diff --git a/lib/planner/tasks/task.ex b/lib/planner/tasks/task.ex index 7b73d4b..ffb3f23 100644 --- a/lib/planner/tasks/task.ex +++ b/lib/planner/tasks/task.ex @@ -6,7 +6,6 @@ defmodule Planner.Tasks.Task do @foreign_key_type :binary_id schema "tasks" do field(:value, :string) - field(:filed_at, :naive_datetime) field(:finished_at, :naive_datetime) field(:due_at, :naive_datetime) @@ -17,7 +16,7 @@ defmodule Planner.Tasks.Task do def changeset(task, attrs) do task - |> cast(attrs, [:value, :filed_at, :finished_at, :due_at]) + |> cast(attrs, [:value, :finished_at, :due_at]) |> validate_required([:value]) |> validate_length(:value, min: 3) end diff --git a/lib/planner_web/live/tasks_components.ex b/lib/planner_web/live/tasks_components.ex index a706932..08556ab 100644 --- a/lib/planner_web/live/tasks_components.ex +++ b/lib/planner_web/live/tasks_components.ex @@ -134,13 +134,13 @@ defmodule TaskDetailsComponent do to: @route_index_tasks.(@socket), class: "delete is-pulled-right" ) %> - <%= if(not is_nil(@task.due_at) or is_nil(@task.filed_at)) do %> + <%= if(not is_nil(@task.due_at) or length(@task.plans) == 0) do %>
- <%= live_patch("all unfinished tasks", to: Routes.tasks_path(@socket, :index), class: "panel-block") %> + <%= live_patch("unfiled", to: Routes.tasks_path(@socket, :index), class: "panel-block") %> <%= for plan <- @plans do %> <%= live_patch( plan.name, @@ -109,7 +109,7 @@ defmodule PlannerWeb.TasksLive do