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_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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 %>
|
||||
<div class="tags">
|
||||
<%= if(not is_nil(@task.due_at)) do %>
|
||||
<span class="tag is-warning">
|
||||
due: <%= @task.due_at %>
|
||||
</span><% end %>
|
||||
<%= if(is_nil(@task.filed_at)) do %>
|
||||
<%= if(length(@task.plans) == 0) do %>
|
||||
<span class="tag is-danger">
|
||||
unfiled
|
||||
</span>
|
||||
|
|
|
@ -38,7 +38,7 @@ defmodule PlannerWeb.TasksLive do
|
|||
socket
|
||||
|> assign(:active_task, task_id)
|
||||
|> assign(:active_plan, nil)
|
||||
|> assign(:tasks, Tasks.list_unfinished_tasks())
|
||||
|> assign(:tasks, Tasks.list_unfiled_tasks())
|
||||
|> add_task_routes()
|
||||
|
||||
{:noreply, assign(socket, :active_task, task_id)}
|
||||
|
@ -72,7 +72,7 @@ defmodule PlannerWeb.TasksLive do
|
|||
socket
|
||||
|> assign(:active_task, nil)
|
||||
|> assign(:active_plan, nil)
|
||||
|> assign(:tasks, Tasks.list_unfinished_tasks())
|
||||
|> assign(:tasks, Tasks.list_unfiled_tasks())
|
||||
|> add_task_routes()
|
||||
|
||||
{:noreply, socket}
|
||||
|
@ -94,7 +94,7 @@ defmodule PlannerWeb.TasksLive do
|
|||
<%= error_tag(f, :name) %>
|
||||
</div>
|
||||
</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 %>
|
||||
<%= live_patch(
|
||||
plan.name,
|
||||
|
@ -109,7 +109,7 @@ defmodule PlannerWeb.TasksLive do
|
|||
<div class="column">
|
||||
<%= case @active_plan do %>
|
||||
<%= nil -> %>
|
||||
<h4 class="title is-4">all unfinished tasks</h4>
|
||||
<h4 class="title is-4">unfiled</h4>
|
||||
<% _ -> %>
|
||||
<h4 class="title is-4">
|
||||
<button
|
||||
|
@ -220,7 +220,7 @@ defmodule PlannerWeb.TasksLive do
|
|||
defp refresh_tasks_and_flash_msg(socket, msg) do
|
||||
tasks =
|
||||
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)
|
||||
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