rename
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
local curl = require("plenary.curl")
|
||||
local helpers = require("eta.helpers")
|
||||
local M = {}
|
||||
|
||||
---@class eta.clickup.Session: eta.Session
|
||||
---@field user string
|
||||
---@field workspace string
|
||||
|
||||
---@class eta.clickup.Ref
|
||||
---@field name string
|
||||
---@field id string
|
||||
|
||||
---@class eta.clickup.Dep
|
||||
---@field task_id string
|
||||
---@field depends_on string
|
||||
|
||||
---@class eta.clickup.Task
|
||||
---@field id string
|
||||
---@field name string
|
||||
---@field tags? table[]
|
||||
---@field locations? table[]
|
||||
---@field list? eta.clickup.Ref
|
||||
---@field parent? string | nil
|
||||
---@field dependencies? eta.clickup.Dep[]
|
||||
---@field [string] string
|
||||
|
||||
---@param self eta.clickup.Session
|
||||
---@return eta.clickup.Task[]
|
||||
M.latest_tasks = function(self)
|
||||
local ret = helpers.request("get", self, "/team/" .. self.workspace .. "/task",{subtasks="true", include_markdown_description="true", ['assignees[]']= self.user})
|
||||
if ret then
|
||||
return ret.tasks
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
---@param self eta.clickup.Session
|
||||
---@param id string
|
||||
---@return eta.clickup.Task
|
||||
M.task = function(self, id)
|
||||
local ret = helpers.request("get", self, "/task/" .. id,{include_markdown_description="true"}) or {}
|
||||
return ret
|
||||
end
|
||||
|
||||
---@param self eta.clickup.Session
|
||||
---@param id string
|
||||
M.task_relations = function(self, id)
|
||||
local ret = helpers.request("get", self, "/task/" .. id .. "/dependency", {}) or {}
|
||||
return ret
|
||||
end
|
||||
|
||||
M.insert_ref = function()
|
||||
local pos = vim.api.nvim_win_get_cursor(0)
|
||||
local row = pos[1] - 1
|
||||
local col = pos[2]
|
||||
local tasks = M.latest_tasks(require("plugin.eta").clickup_session)
|
||||
|
||||
---@type SelectionItem[]
|
||||
local items = {}
|
||||
|
||||
for tix, t in ipairs(tasks) do
|
||||
if string.sub(t.name, -7, -1) ~= "Absence" then
|
||||
local preview_frontmatter = ""
|
||||
|
||||
---@type SelectionItem
|
||||
local prepared = {
|
||||
idx = tix,
|
||||
id = t.id,
|
||||
text = t.name .. t.id .. t.markdown_description,
|
||||
name = t.name,
|
||||
tags = require("plugin.eta").retrieve_subkeys(t.tags, { "name" }),
|
||||
status = t.status.status,
|
||||
parent = t.parent,
|
||||
list = t.list.name,
|
||||
description = t.markdown_description,
|
||||
preview = {
|
||||
ft = "markdown",
|
||||
},
|
||||
action = M._on_select_task
|
||||
}
|
||||
|
||||
for _, k in ipairs({ "id", "name", "status", "tags", "parent" }) do
|
||||
preview_frontmatter = preview_frontmatter .. "\n" .. k .. ": " .. vim.json.encode(prepared[k])
|
||||
end
|
||||
|
||||
prepared.preview.text = "---" .. preview_frontmatter .. "\n---\n" .. t.markdown_description
|
||||
table.insert(items, #items + 1, prepared)
|
||||
end
|
||||
end
|
||||
|
||||
require("snacks.picker").pick({
|
||||
title = "Select Task",
|
||||
format = require("plugin.eta")._item_format,
|
||||
preview = "preview",
|
||||
confirm = function(picker, item)
|
||||
picker:close()
|
||||
vim.api.nvim_buf_set_text(0, row, col, row, col,
|
||||
{ "[#" .. item.id .. "](https://app.clickup.com/t/" .. item.id .. ")" })
|
||||
end,
|
||||
items = items
|
||||
})
|
||||
end
|
||||
return M
|
||||
Reference in New Issue
Block a user