Query to get task overview in table, with date, page and owner

So deadline isn’t so easy to do. Would require an even more complex query. The rest is easy enough, so I added those.

#+BEGIN_QUERY
{:title "🟠 SLIPPING"
 :query [:find (pull ?b [*]) ?ref
  :keys block owner
  :in $ ?start ?today
  :where
   (task ?b #{"NOW" "LATER" "TODO" "DOING" "WAITING"})
   (between ?b ?start ?today)
   [?b :block/refs ?r]
   [?r :block/original-name ?ref]
   [(clojure.string/starts-with? ?ref "@")]
 ]
 :inputs [:-7d :today]
 :result-transform (fn [result] (sort-by 
   (fn [h] (get h :block/created-at)) 
   (map 
     (fn [m] (update (:block m) :block/properties 
       (fn [u] (assoc u :owner (get-in m [:owner]) ) )
     ) )
     result
   )
 ) )
 :view (fn [rows] [:table
[:thead [:tr
[:th "Page"]
[:th "Owner"]
[:th "Task"]
[:th "Priority"]
[:th "Deadline"]
]]
[:tbody (for
[r rows
:let [content (str (get r :block/content))]
:let [firstline (first (str/split-lines content))] ;this will show only the first line of the task.
:let [noprio (clojure.string/replace firstline (str "[#" (get r :block/priority) "]") "")]
:let [nomark (clojure.string/replace noprio (get r :block/marker) "")]
:let [task (clojure.string/replace nomark (str "#" (get-in r [:block/properties :owner])) "")]
:let [name (clojure.string/replace (get-in r [:block/properties :owner]) "@" "")]
]
[:tr
[:td [:a {:href (str "#/page/" (clojure.string/replace (get-in r [:block/page :block/original-name]) "/" "%2F"))}
(get-in r [:block/page :block/original-name])] ] ;make a workable link to the page, even when it is in a namespace
[:td [:a {:href (str "#/page/" (clojure.string/replace (get-in r [:block/properties :owner]) "/" "%2F"))}
name] ] ;get the property value for owner and link it 
[:td [:a {:href (str "#/page/" (get-in r [:block/uuid]))} task] ] ;link to the block and show the first line
[:td [:a {:href (str "#/page/" (clojure.string/replace (get r :block/priority) "/" "%2F"))}
(get r :block/priority)] ] ;get the priority from the results and link it
[:td (get r :block/deadline)] ;get the deadline from the results
]
)]
])
:collapsed? false
}
#+END_QUERY
1 Like