handle unfiled tasks (#51)
This commit is contained in:
parent
d57fdd0d0f
commit
8201dfbf7a
5 changed files with 29 additions and 9 deletions
|
@ -10,6 +10,18 @@ defmodule Planner.Tasks do
|
||||||
|
|
||||||
def list_all_tasks, do: Repo.all(Task)
|
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
|
def list_unfinished_tasks do
|
||||||
from(
|
from(
|
||||||
t in Task,
|
t in Task,
|
||||||
|
|
|
@ -6,7 +6,6 @@ defmodule Planner.Tasks.Task do
|
||||||
@foreign_key_type :binary_id
|
@foreign_key_type :binary_id
|
||||||
schema "tasks" do
|
schema "tasks" do
|
||||||
field(:value, :string)
|
field(:value, :string)
|
||||||
field(:filed_at, :naive_datetime)
|
|
||||||
field(:finished_at, :naive_datetime)
|
field(:finished_at, :naive_datetime)
|
||||||
field(:due_at, :naive_datetime)
|
field(:due_at, :naive_datetime)
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ defmodule Planner.Tasks.Task do
|
||||||
|
|
||||||
def changeset(task, attrs) do
|
def changeset(task, attrs) do
|
||||||
task
|
task
|
||||||
|> cast(attrs, [:value, :filed_at, :finished_at, :due_at])
|
|> cast(attrs, [:value, :finished_at, :due_at])
|
||||||
|> validate_required([:value])
|
|> validate_required([:value])
|
||||||
|> validate_length(:value, min: 3)
|
|> validate_length(:value, min: 3)
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,13 +134,13 @@ 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 is_nil(@task.filed_at)) do %>
|
<%= if(not is_nil(@task.due_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(is_nil(@task.filed_at)) do %>
|
<%= if(length(@task.plans) == 0) do %>
|
||||||
<span class="tag is-danger">
|
<span class="tag is-danger">
|
||||||
unfiled
|
unfiled
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -38,7 +38,7 @@ defmodule PlannerWeb.TasksLive do
|
||||||
socket
|
socket
|
||||||
|> assign(:active_task, task_id)
|
|> assign(:active_task, task_id)
|
||||||
|> assign(:active_plan, nil)
|
|> assign(:active_plan, nil)
|
||||||
|> assign(:tasks, Tasks.list_unfinished_tasks())
|
|> assign(:tasks, Tasks.list_unfiled_tasks())
|
||||||
|> add_task_routes()
|
|> add_task_routes()
|
||||||
|
|
||||||
{:noreply, assign(socket, :active_task, task_id)}
|
{:noreply, assign(socket, :active_task, task_id)}
|
||||||
|
@ -72,7 +72,7 @@ defmodule PlannerWeb.TasksLive do
|
||||||
socket
|
socket
|
||||||
|> assign(:active_task, nil)
|
|> assign(:active_task, nil)
|
||||||
|> assign(:active_plan, nil)
|
|> assign(:active_plan, nil)
|
||||||
|> assign(:tasks, Tasks.list_unfinished_tasks())
|
|> assign(:tasks, Tasks.list_unfiled_tasks())
|
||||||
|> add_task_routes()
|
|> add_task_routes()
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
@ -94,7 +94,7 @@ defmodule PlannerWeb.TasksLive do
|
||||||
<%= error_tag(f, :name) %>
|
<%= error_tag(f, :name) %>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<%= 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 %>
|
<%= for plan <- @plans do %>
|
||||||
<%= live_patch(
|
<%= live_patch(
|
||||||
plan.name,
|
plan.name,
|
||||||
|
@ -109,7 +109,7 @@ defmodule PlannerWeb.TasksLive do
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<%= case @active_plan do %>
|
<%= case @active_plan do %>
|
||||||
<%= nil -> %>
|
<%= nil -> %>
|
||||||
<h4 class="title is-4">all unfinished tasks</h4>
|
<h4 class="title is-4">unfiled</h4>
|
||||||
<% _ -> %>
|
<% _ -> %>
|
||||||
<h4 class="title is-4">
|
<h4 class="title is-4">
|
||||||
<button
|
<button
|
||||||
|
@ -220,7 +220,7 @@ defmodule PlannerWeb.TasksLive do
|
||||||
defp refresh_tasks_and_flash_msg(socket, msg) do
|
defp refresh_tasks_and_flash_msg(socket, msg) do
|
||||||
tasks =
|
tasks =
|
||||||
case socket.assigns.active_plan do
|
case socket.assigns.active_plan do
|
||||||
nil -> Tasks.list_unfinished_tasks()
|
nil -> Tasks.list_unfiled_tasks()
|
||||||
plan -> Tasks.list_unfinished_tasks_by_plan_id(plan.id)
|
plan -> Tasks.list_unfinished_tasks_by_plan_id(plan.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Planner.Repo.Migrations.RemoveFieldFiledAtFromTasks do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:tasks) do
|
||||||
|
remove(:filed_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue