Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api to modify task state based on uuid #504

Closed
1 task done
max397574 opened this issue Jul 8, 2022 · 0 comments
Closed
1 task done

Api to modify task state based on uuid #504

max397574 opened this issue Jul 8, 2022 · 0 comments
Labels
feature Issues related to feature proposals. Please attach a module.

Comments

@max397574
Copy link
Contributor

Issues

  • I have checked existing issues and there are no existing ones with the same request.

Feature description

read the title
for gtd tasks
would be useful for integrations like e.g. https://github.com/max397574/neorg-kanban

Help

Yes

Implementation help

something I tried out

local states = {
    ["undone"] = { "%- %[ %] ", "NeorgTodoItem1Undone" },
    ["done"] = { "%- %[x%] ", "NeorgTodoItem1Done" },
    ["pending"] = { "%- %[%-%] ", "NeorgTodoItem1Pending" },
    ["cancelled"] = { "%- %[%_%] ", "NeorgTodoItem1Cancelled" },
    ["uncertain"] = { "%- %[%?%] ", "NeorgTodoItem1Uncertain" },
    ["urgent"] = { "%- %[%!%] ", "NeorgTodoItem1Urgent" },
    ["recurring"] = { "%- %[%+%] ", "NeorgTodoItem1Recurring" },
    ["on_hold"] = { "%- %[=%] ", "NeorgTodoItem1OnHold" },
}
local ts_utils = require("nvim-treesitter.ts_utils")
---@diagnostic disable: undefined-global
pcall(vim.cmd, "NeorgStart silent=true")

local tasks_raw = neorg.modules.get_module("core.gtd.queries").get("tasks")
tasks_raw = neorg.modules.get_module("core.gtd.queries").add_metadata(
    tasks_raw,
    "task"
)
-- local tasks_raw = neorg.modules.get_module("core.gtd.queries").get("projects")
-- tasks_raw = neorg.modules.get_module("core.gtd.queries").add_metadata(tasks_raw, "project")
-- vim.pretty_print(tasks_raw)
local uuid = tasks_raw[1].uuid
local state_new = "done"
for _, task in ipairs(tasks_raw) do
    if task.uuid == uuid then
        vim.pretty_print(task)
        vim.fn.bufload(task.internal.bufnr)
        local old_state = states[task.state][1]
        if state_new == old_state then
            break
        end
        -- ts_utils.goto_node(task.internal.node, false, true)
        local new_state = states[state_new][1]
        local s_row, s_col, e_row, e_col = ts_utils.get_node_range(
            task.internal.node
        )
        local line = vim.api.nvim_buf_get_lines(
            task.internal.bufnr,
            s_row,
            e_row,
            false
        )[1]
        line = line:gsub(old_state, new_state)
        vim.api.nvim_buf_set_lines(
            task.internal.bufnr,
            s_row,
            s_row + 1,
            false,
            { line }
        )
        vim.api.nvim_buf_call(task.internal.bufnr, function()
            vim.cmd("write!")
        end)
        vim.cmd([[bunload ]] .. task.internal.bufnr)
    end
end
@max397574 max397574 added the feature Issues related to feature proposals. Please attach a module. label Jul 8, 2022
@danymat danymat changed the title create api to modify task state based on uuid Api to modify task state based on uuid Jul 18, 2022
@danymat danymat closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues related to feature proposals. Please attach a module.
Projects
None yet
Development

No branches or pull requests

2 participants