All pages that have no task block?

Hi all,

I am trying to build a query that will show a list with all pages (from a specific namespace) that have no task block or - more advanced - do not have exactly one task block with a specific state (“TODO”)

Background: For my project management I want to ensure that all of my projects (pages in the project namespace) have a TODO. And I want to build a query that will show me all pages that do NOT have this requirement, so I want to find the “uncompliant” pages.

My current approach will only show pages, which have a least one block without a task which is not what I want:

          #+BEGIN_QUERY
          {:title [:h3 "Project pages without a task"]
           :query [:find (pull ?p [*])
           :where
             [?p :page/name ?name]
             [?b :block/page ?p]
             [(clojure.string/starts-with? ?name "project/")]
             [(missing? $ ?b :block/marker)]
           ]
          }
          #+END_QUERY

Does anybody have an idea what I need to improve/change so I can get the result I want?

So you need to say that “none of the blocks with a block marker are on the project page”. Instead of “on the project page any block doesn’t have a block marker”. (which is to say your current query only filters out those pages that of which all blocks have a block marker)

I threw in a bonus namespace. Should also help with performance as the result set gets reduced earlier on in de query.

#+BEGIN_QUERY
{:title [:h3 "Project pages without a task"]
 :query [:find (pull ?p [*])
  :where
   [?ns :block/name "project"]
   [?p :block/namespace ?ns]
   (not
     [?b :block/marker]
     [?b :block/page ?p]
   )   
 ]
}
#+END_QUERY
1 Like

My solution is one or more task blocks.
You can change [?b :block/marker] to [?b :block/marker "TODO"].
However do be mindful that should all tasks in this project have a “DONE” state it will also show up.
So you may want to include a clause to filter out completed projects (unless of course they are no longer in this namespace at that point)

1 Like

Thank you very much, awesome! This is a good starting point, I will try to add more filters later on.

1 Like