How can I gather all open tasks?

I am doing my first steps… Having moved from Obsidian, I have tasks spread over a number of files. So I need to have a cental todo list which gathers all my open tasks from various files. How can this be accomplished?

This gathers all tasks, so now I need to filter for those which are not done:

${template.each(query[[from index.tag "task"]], templates.taskItem)}

Thanks for supporting my learning curve!
Peter

Add where not done to the query.

I created a concept like this:

```query
task
  where done = false
  render [[Library/Core/Query/Task_New]]
  order by deadline

Then the template looks like this

Hi

I am also coming from Obsidian tasks and I created a query like this which shows tasks that are due within a given number of days (here: 10):

${template.each(query[[
  from index.tag "task" where table.includes(tags, "work") and not done and _.due != nil and _.due <= custom.addDaysToDate(custom.todayAsString(), 10)
  order by due, prio
]],
template.new[==[
    * [${state}] ${name} 🗓 ${due} ${custom.prioAsIcon(prio)} ${custom.concatenateTags(_.tags)} [[${ref}]]
    ]==]
)}

Some comments:

  1. Query uses a template to format the final rows
  2. Custom function prioAsIcon() to show icons for the priority instead of a number
  3. Custom function concatenateTags() to bring together tags clickable
  4. Custom function addDaysToDate() which adds a given number of days to a date given in the format YYYY-MM-DD and returns the new das in the same format
  5. Custom function todayAsString which returns today’s date as string in the form YYY-MM-DD

I have the strong feeling that those date-related functions can be simplified, I am completely new to Lua and have no clue :slight_smile:

Here Are these functions:

-- From: https://community.silverbullet.md/t/queries-with-clickable-tags-for-v2/2387/9
custom = custom or {}

function custom.concatenateTags(tags)
    local result = {}
    for _, tag in ipairs(tags) do
        -- Format each tag as [[tag:tag_name|#tag_name]]
        local formattedTag = string.format("[[tag:%s|#%s]]", tag, tag)
        table.insert(result, formattedTag)
    end
    return table.concat(result, " ")
end


-- Deliver an icon for a given priority
function custom.prioAsIcon(prio)
    local result = ""
    if prio == 1 then
        result = "🔺"
    elseif prio == 2 then
        result = "⏫"
    elseif prio == 3 then
        result = "🔼"
    elseif prio == 4 then
        result = "🔽"
    else
        result = "NA"
    end
    return result
end


-- Deliver the full name of the weekay for a given date
function custom.dayOfDate(date)
    local year, month, day = date:match("^(%d%d%d%d)%-(%d%d)%-(%d%d)$")
    if not (year and month and day) then
        -- failed to parse date
        return os.date("%A")
    else
        return os.date("%A", os.time({year = year, month = month, day = day}))
    end
end


-- Deliver current date as string
function custom.todayAsString()
    local now = os.time()
    local dateYear = os.date("%Y", now)
    local dateMonth = os.date("%m", now)
    local dateDay = os.date("%d", now)
    local nowAsString = string.format("%s-%s-%s", dateYear, dateMonth, dateDay)
    return nowAsString
end


-- Deliver a new date by adding a given number of days to a start date
function custom.addDaysToDate(date, days)
    local year, month, day = date:match("^(%d%d%d%d)%-(%d%d)%-(%d%d)$")
    local epochTime = os.time{year=year, month=month, day=day, hour=0}
    local daysInSeconds = days * 24 * 60 * 60
    local newEpochTime = epochTime + daysInSeconds
    local newDateYear = os.date("%Y", newEpochTime)
    local newDateMonth = os.date("%m", newEpochTime)
    local newDateDay = os.date("%d", newEpochTime)
    local newDateString = string.format("%s-%s-%s", newDateYear, newDateMonth, newDateDay)
    return newDateString
end

Tasks are written in this form:

  • Task title [due: YYYY-MM-YY] [prio: n] #tag

Prio goes from 1-4.

What I am missing is the ability to also use icons to write tasks. I don’t know how to do this, since from these icons, numeric values for due date and priority would have to be derived automatically by some function that gets triggered.

Best,
Pascal