url-hack tasks (#64)
This commit is contained in:
parent
55763c0698
commit
8c09142f8e
3 changed files with 22 additions and 12 deletions
|
@ -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]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,8 @@ defmodule TaskComponent do
|
||||||
<li>
|
<li>
|
||||||
<div>
|
<div>
|
||||||
<div class="is-pulled-left">
|
<div class="is-pulled-left">
|
||||||
|
<%= case @task.finished_at do %>
|
||||||
|
<% nil -> %>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
role="checkbox"
|
role="checkbox"
|
||||||
|
@ -81,6 +83,9 @@ defmodule TaskComponent do
|
||||||
phx-click="finish-task"
|
phx-click="finish-task"
|
||||||
phx-value-task-id="<%= @task.id %>">
|
phx-value-task-id="<%= @task.id %>">
|
||||||
</button>
|
</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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue