Skip to content

Commit

Permalink
[modify] Fixed check deps for toggle nested tasks were wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
huantrinh1802 committed Sep 27, 2024
1 parent 37bfa70 commit d0aaf37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lua/m_taskwarrior_d/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ function M.toggle_task()
local current_line, line_number = M.utils.get_line()
local _, uuid = M.utils.extract_uuid(current_line)
if uuid ~= nil then
local task = M.task.get_task_by(uuid, "task")
if task and task["depends"] ~= nil then
print("This task has dependencies: " .. table.concat(task["depends"], ", "))
local is_blocked = M.task.check_if_task_is_blocked(uuid)
if is_blocked then
print("This task is blocked")
return nil
end
end
Expand Down
13 changes: 11 additions & 2 deletions lua/m_taskwarrior_d/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ end
function M.modify_task_status(task_id, new_status)
local command
if M.status_map[new_status] == "active" then
command = string.format("task %s start", task_id)
command = string.format("task %s modify status:pending; task %s start", task_id, task_id)
else
local status = M.status_map[new_status]
command = string.format("task %s modify status:%s", task_id, status)
end
local status, result = M.execute_taskwarrior_command(command)
M.execute_taskwarrior_command(command)
end

function M.add_task_deps(current_task_id, deps)
Expand Down Expand Up @@ -115,4 +115,13 @@ function M.get_tasks_by(uuids)
return true, tasks
end

function M.check_if_task_is_blocked(uuid)
local command = string.format("task %s -BLOCKED", uuid)
local _, result = M.execute_taskwarrior_command(command, true)
if #result > 0 then
return false
end
return true
end

return M
6 changes: 4 additions & 2 deletions lua/m_taskwarrior_d/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ function M.update_related_tasks_statuses(uuid)
for _, task in ipairs(tasks) do
local _, dependencies = task_mod.get_tasks_by(task["depends"])
local new_status = calculate_final_status(dependencies)
local line_number = find_pattern_line(task.uuid)
new_status, _ = findPair(M.status_map, nil, new_status)
M.toggle_task_status(nil, line_number, new_status)
task_mod.modify_task_status(task.uuid, new_status)
local line_number = find_pattern_line(task.uuid)
if line_number ~= nil then
M.toggle_task_status(nil, line_number, new_status)
end
end
end

Expand Down

0 comments on commit d0aaf37

Please sign in to comment.