feat(views): add recurrence to LineMeta
Problem: LineMeta does not carry recurrence info, so the buffer layer cannot display recurrence indicators. Solution: add recur field to LineMeta and populate it in both category_view() and priority_view().
This commit is contained in:
parent
b08d01fe78
commit
1e2d72914c
2 changed files with 51 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ local config = require('pending.config')
|
||||||
---@field overdue? boolean
|
---@field overdue? boolean
|
||||||
---@field show_category? boolean
|
---@field show_category? boolean
|
||||||
---@field priority? integer
|
---@field priority? integer
|
||||||
|
---@field recur? string
|
||||||
|
|
||||||
---@class pending.views
|
---@class pending.views
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
@ -149,6 +150,7 @@ function M.category_view(tasks)
|
||||||
status = task.status,
|
status = task.status,
|
||||||
category = cat,
|
category = cat,
|
||||||
overdue = task.status == 'pending' and task.due ~= nil and task.due < today or nil,
|
overdue = task.status == 'pending' and task.due ~= nil and task.due < today or nil,
|
||||||
|
recur = task.recur,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -200,6 +202,7 @@ function M.priority_view(tasks)
|
||||||
category = task.category,
|
category = task.category,
|
||||||
overdue = task.status == 'pending' and task.due ~= nil and task.due < today or nil,
|
overdue = task.status == 'pending' and task.due ~= nil and task.due < today or nil,
|
||||||
show_category = true,
|
show_category = true,
|
||||||
|
recur = task.recur,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,30 @@ describe('views', function()
|
||||||
assert.is_falsy(task_meta.overdue)
|
assert.is_falsy(task_meta.overdue)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('includes recur in LineMeta for recurring tasks', function()
|
||||||
|
store.add({ description = 'Recurring', category = 'Inbox', recur = 'weekly' })
|
||||||
|
local _, meta = views.category_view(store.active_tasks())
|
||||||
|
local task_meta
|
||||||
|
for _, m in ipairs(meta) do
|
||||||
|
if m.type == 'task' then
|
||||||
|
task_meta = m
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal('weekly', task_meta.recur)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('has nil recur in LineMeta for non-recurring tasks', function()
|
||||||
|
store.add({ description = 'Normal', category = 'Inbox' })
|
||||||
|
local _, meta = views.category_view(store.active_tasks())
|
||||||
|
local task_meta
|
||||||
|
for _, m in ipairs(meta) do
|
||||||
|
if m.type == 'task' then
|
||||||
|
task_meta = m
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_nil(task_meta.recur)
|
||||||
|
end)
|
||||||
|
|
||||||
it('respects category_order when set', function()
|
it('respects category_order when set', function()
|
||||||
vim.g.pending = { data_path = tmpdir .. '/tasks.json', category_order = { 'Work', 'Inbox' } }
|
vim.g.pending = { data_path = tmpdir .. '/tasks.json', category_order = { 'Work', 'Inbox' } }
|
||||||
config.reset()
|
config.reset()
|
||||||
|
|
@ -399,5 +423,29 @@ describe('views', function()
|
||||||
end
|
end
|
||||||
assert.is_falsy(task_meta.overdue)
|
assert.is_falsy(task_meta.overdue)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('includes recur in LineMeta for recurring tasks', function()
|
||||||
|
store.add({ description = 'Recurring', category = 'Inbox', recur = 'daily' })
|
||||||
|
local _, meta = views.priority_view(store.active_tasks())
|
||||||
|
local task_meta
|
||||||
|
for _, m in ipairs(meta) do
|
||||||
|
if m.type == 'task' then
|
||||||
|
task_meta = m
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.are.equal('daily', task_meta.recur)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('has nil recur in LineMeta for non-recurring tasks', function()
|
||||||
|
store.add({ description = 'Normal', category = 'Inbox' })
|
||||||
|
local _, meta = views.priority_view(store.active_tasks())
|
||||||
|
local task_meta
|
||||||
|
for _, m in ipairs(meta) do
|
||||||
|
if m.type == 'task' then
|
||||||
|
task_meta = m
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_nil(task_meta.recur)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue