Compare commits
No commits in common. "8fb3554c436dbcffbb723fe6f92513864ec27716" and "6e381c0d5fc752d24170e813bf72b9f44e3df80d" have entirely different histories.
8fb3554c43
...
6e381c0d5f
4 changed files with 7 additions and 75 deletions
|
|
@ -430,48 +430,6 @@ function M.toggle_complete()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param id_str string
|
|
||||||
---@return nil
|
|
||||||
function M.done(id_str)
|
|
||||||
local id = tonumber(id_str)
|
|
||||||
if not id then
|
|
||||||
log.error('Invalid task ID: ' .. tostring(id_str))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local s = get_store()
|
|
||||||
s:load()
|
|
||||||
local task = s:get(id)
|
|
||||||
if not task then
|
|
||||||
log.error('No task with ID ' .. id .. '.')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local was_done = task.status == 'done'
|
|
||||||
if was_done then
|
|
||||||
s:update(id, { status = 'pending', ['end'] = vim.NIL })
|
|
||||||
else
|
|
||||||
if task.recur and task.due then
|
|
||||||
local recur = require('pending.recur')
|
|
||||||
local mode = task.recur_mode or 'scheduled'
|
|
||||||
local next_date = recur.next_due(task.due, task.recur, mode)
|
|
||||||
s:add({
|
|
||||||
description = task.description,
|
|
||||||
category = task.category,
|
|
||||||
priority = task.priority,
|
|
||||||
due = next_date,
|
|
||||||
recur = task.recur,
|
|
||||||
recur_mode = task.recur_mode,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
s:update(id, { status = 'done' })
|
|
||||||
end
|
|
||||||
_save_and_notify()
|
|
||||||
local bufnr = buffer.bufnr()
|
|
||||||
if bufnr and vim.api.nvim_buf_is_valid(bufnr) then
|
|
||||||
buffer.render(bufnr)
|
|
||||||
end
|
|
||||||
log.info('Task #' .. id .. ' marked ' .. (was_done and 'pending' or 'done'))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.toggle_priority()
|
function M.toggle_priority()
|
||||||
local bufnr = buffer.bufnr()
|
local bufnr = buffer.bufnr()
|
||||||
|
|
@ -592,7 +550,7 @@ local function run_sync(backend_name, action)
|
||||||
if not action or action == '' then
|
if not action or action == '' then
|
||||||
local actions = {}
|
local actions = {}
|
||||||
for k, v in pairs(backend) do
|
for k, v in pairs(backend) do
|
||||||
if type(v) == 'function' and k:sub(1, 1) ~= '_' and k ~= 'health' then
|
if type(v) == 'function' and k:sub(1, 1) ~= '_' then
|
||||||
table.insert(actions, k)
|
table.insert(actions, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -600,7 +558,7 @@ local function run_sync(backend_name, action)
|
||||||
log.info(backend_name .. ' actions: ' .. table.concat(actions, ', '))
|
log.info(backend_name .. ' actions: ' .. table.concat(actions, ', '))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if action == 'health' or type(backend[action]) ~= 'function' then
|
if type(backend[action]) ~= 'function' then
|
||||||
log.error(backend_name .. " backend has no '" .. action .. "' action")
|
log.error(backend_name .. " backend has no '" .. action .. "' action")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -873,8 +831,8 @@ end
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.auth()
|
function M.auth()
|
||||||
local oauth = require('pending.sync.oauth')
|
local oauth = require('pending.sync.oauth')
|
||||||
vim.ui.select({ 'Google Tasks', 'Google Calendar', 'Google Tasks and Google Calendar' }, {
|
vim.ui.select({ 'gtasks', 'gcal', 'both' }, {
|
||||||
prompt = 'Authenticate with:',
|
prompt = 'Authenticate:',
|
||||||
}, function(choice)
|
}, function(choice)
|
||||||
if not choice then
|
if not choice then
|
||||||
return
|
return
|
||||||
|
|
@ -898,8 +856,6 @@ function M.command(args)
|
||||||
local cmd, rest = args:match('^(%S+)%s*(.*)')
|
local cmd, rest = args:match('^(%S+)%s*(.*)')
|
||||||
if cmd == 'add' then
|
if cmd == 'add' then
|
||||||
M.add(rest)
|
M.add(rest)
|
||||||
elseif cmd == 'done' then
|
|
||||||
M.done(rest:match('^(%S+)'))
|
|
||||||
elseif cmd == 'edit' then
|
elseif cmd == 'edit' then
|
||||||
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
|
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
|
||||||
M.edit(id_str, edit_rest)
|
M.edit(id_str, edit_rest)
|
||||||
|
|
|
||||||
|
|
@ -234,12 +234,6 @@ end
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.health()
|
function M.health()
|
||||||
oauth.health(M.name)
|
oauth.health(M.name)
|
||||||
local tokens = oauth.google_client:load_tokens()
|
|
||||||
if tokens and tokens.refresh_token then
|
|
||||||
vim.health.ok('gcal tokens found')
|
|
||||||
else
|
|
||||||
vim.health.info('no gcal tokens — run :Pending auth')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,7 @@ end
|
||||||
function OAuthClient:auth(on_complete)
|
function OAuthClient:auth(on_complete)
|
||||||
local creds = self:resolve_credentials()
|
local creds = self:resolve_credentials()
|
||||||
if creds.client_id == BUNDLED_CLIENT_ID then
|
if creds.client_id == BUNDLED_CLIENT_ID then
|
||||||
log.error(self.name .. ': no credentials configured — run :Pending auth')
|
log.error(self.name .. ': no credentials configured — run :Pending ' .. self.name .. ' setup')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local port = self.port
|
local port = self.port
|
||||||
|
|
@ -470,14 +470,12 @@ function OAuthClient:_exchange_code(creds, code, code_verifier, port, on_complet
|
||||||
}, { text = true })
|
}, { text = true })
|
||||||
|
|
||||||
if result.code ~= 0 then
|
if result.code ~= 0 then
|
||||||
self:_wipe()
|
|
||||||
log.error('Token exchange failed.')
|
log.error('Token exchange failed.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, decoded = pcall(vim.json.decode, result.stdout or '')
|
local ok, decoded = pcall(vim.json.decode, result.stdout or '')
|
||||||
if not ok or not decoded.access_token then
|
if not ok or not decoded.access_token then
|
||||||
self:_wipe()
|
|
||||||
log.error('Invalid token response.')
|
log.error('Invalid token response.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -490,12 +488,6 @@ function OAuthClient:_exchange_code(creds, code, code_verifier, port, on_complet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return nil
|
|
||||||
function OAuthClient:_wipe()
|
|
||||||
os.remove(self:token_path())
|
|
||||||
os.remove(vim.fn.stdpath('data') .. '/pending/google_credentials.json')
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param opts { name: string, scope: string, port: integer, config_key: string }
|
---@param opts { name: string, scope: string, port: integer, config_key: string }
|
||||||
---@return pending.OAuthClient
|
---@return pending.OAuthClient
|
||||||
function M.new(opts)
|
function M.new(opts)
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ end, {
|
||||||
nargs = '*',
|
nargs = '*',
|
||||||
complete = function(arg_lead, cmd_line)
|
complete = function(arg_lead, cmd_line)
|
||||||
local pending = require('pending')
|
local pending = require('pending')
|
||||||
local subcmds = { 'add', 'archive', 'auth', 'done', 'due', 'edit', 'filter', 'undo' }
|
local subcmds = { 'add', 'archive', 'auth', 'due', 'edit', 'filter', 'undo' }
|
||||||
for _, b in ipairs(pending.sync_backends()) do
|
for _, b in ipairs(pending.sync_backends()) do
|
||||||
table.insert(subcmds, b)
|
table.insert(subcmds, b)
|
||||||
end
|
end
|
||||||
|
|
@ -200,16 +200,6 @@ end, {
|
||||||
end
|
end
|
||||||
return filtered
|
return filtered
|
||||||
end
|
end
|
||||||
if cmd_line:match('^Pending%s+done%s') then
|
|
||||||
local store = require('pending.store')
|
|
||||||
local s = store.new(store.resolve_path())
|
|
||||||
s:load()
|
|
||||||
local ids = {}
|
|
||||||
for _, task in ipairs(s:active_tasks()) do
|
|
||||||
table.insert(ids, tostring(task.id))
|
|
||||||
end
|
|
||||||
return filter_candidates(arg_lead, ids)
|
|
||||||
end
|
|
||||||
if cmd_line:match('^Pending%s+edit') then
|
if cmd_line:match('^Pending%s+edit') then
|
||||||
return complete_edit(arg_lead, cmd_line)
|
return complete_edit(arg_lead, cmd_line)
|
||||||
end
|
end
|
||||||
|
|
@ -226,7 +216,7 @@ end, {
|
||||||
end
|
end
|
||||||
local actions = {}
|
local actions = {}
|
||||||
for k, v in pairs(mod) do
|
for k, v in pairs(mod) do
|
||||||
if type(v) == 'function' and k:sub(1, 1) ~= '_' and k ~= 'health' then
|
if type(v) == 'function' and k:sub(1, 1) ~= '_' then
|
||||||
table.insert(actions, k)
|
table.insert(actions, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue