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)
|
||||
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]
|
||||
)
|
||||
|
||||
|
|
|
@ -74,6 +74,8 @@ defmodule TaskComponent do
|
|||
<li>
|
||||
<div>
|
||||
<div class="is-pulled-left">
|
||||
<%= case @task.finished_at do %>
|
||||
<% nil -> %>
|
||||
<button
|
||||
type="button"
|
||||
role="checkbox"
|
||||
|
@ -81,6 +83,9 @@ defmodule TaskComponent do
|
|||
phx-click="finish-task"
|
||||
phx-value-task-id="<%= @task.id %>">
|
||||
</button>
|
||||
<% _ -> %>
|
||||
!
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="ml-5-5">
|
||||
<%= 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 %>
|
||||
<div class="tags">
|
||||
<%= if(not is_nil(@task.due_at)) do %>
|
||||
<span class="tag is-warning">
|
||||
due: <%= @task.due_at %>
|
||||
</span><% end %>
|
||||
<%= if(not is_nil(@task.finished_at)) do %>
|
||||
<span class="tag is-success">
|
||||
completed
|
||||
</span><% end %>
|
||||
<%= if(length(@task.plans) == 0) do %>
|
||||
<span class="tag is-danger">
|
||||
unfiled
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue