Can anyone get these "GTD" queries working?

Hi, I’m kind of liking this approach to task management:

But the queries (especially the first one) don’t seem to work.

Does anyone have them working, or can point out to me what’s wrong with them?

The 2nd one won’t work if your projects pages are nested (into namespaces) apparently.

The blogger did mention having trouble with complex queries in that regard.

I’d just like to get something working in that template.

I saw some functionality on the ones put on one’s “Queries” pages.

I also don’t know enough about how to build a “home page” and put the report they mention on that, if someone could steer me in the right direction on that I’d appreciate it.

Another question I’d have is, how do I make it so I can change/fix the existing projects queries built with this template in just one place?

Like can I create functions in the config file representing these queries then just call that named function in the template so I don’t have to go around and “fix” a query in hundreds of places when I want to enhance/repair it?



Here’s my approach to the first query. I’ve factored out rules to hopefully make it easier to understand each part.

It has some upgrades, the sort function sorts by priority then deadline/scheduled, then when the todo was created.

I put this query on the page for each person on my team, too.

{:title [:h3 "Related tasks"]
  :inputs [:query-page]
  :query [
      :find (pull ?b [*])
      :in $ ?current-page %
        (page-ref ?b ?current-page)
        (not-on-page ?b ?current-page)
        (active-task ?b)
  :rules [
    [(active-task ?b)
      [?b :block/marker ?marker]
      (not [(contains? #{"DONE" "CANCELED"} ?marker)])]
    [(not-on-page ?b ?p)
      (not [?b :block/page ?p])]
      (fn [result]
        (sort-by (fn [b] [
            (get b :block/priority "Z")
            (min (get b :block/scheduled 98765432100)
                     (get b :block/deadline 98765432100))
            (get b :block/created-at)]) result))
    :breadcrumb-show? false
    :table-view? false

Here’s my approach to the second query. For this, I just looked for any page in a set of namespaces that had active tasks.

{ :title [:h3 "Active projects"]
  :inputs [#{"project"} #{}]
  :query [
      :find (pull ?p [*]);?page-name
      :in $ ?allowed-namespaces ?skipped-namespaces %
          ; ?p is a page with active tasks referencing it
          ; ?page-name is its name
          ;(page-with-active-task ?p ?page-name)
          (active-task ?b)
          (page-ref ?b ?page-name)
          [?p :block/name ?page-name]

          ; exclude the allowed/skipped pages themselves
          (not (or
              [(contains? ?allowed-namespaces ?page-name)]
              [(contains? ?skipped-namespaces ?page-name)]))

          ; apply the namespace filters to the page
          (namespace ?p ?ns)
          [(contains? ?allowed-namespaces ?ns)]
          (not [(contains? ?skipped-namespaces ?ns)])
  :rules [
      [(active-task ?b)
          [?b :block/marker ?marker]
          (not [(contains? #{"DONE" "CANCELED"} ?marker)])]

I haven’t figured out how to make a page-listing pretty (or how to link to a page in :view section), so this just uses the standard page table listing.