Compare commits

..

2 Commits

Author SHA1 Message Date
96a7f35a90
Allow entries in workload report to be sorted 2022-09-10 09:39:30 +02:00
735570d7c0
Include various timestamps in workload report
This should make it easier to decide which entries could be moved in case too
much work is planned for the upcoming days.
2022-09-10 09:25:37 +02:00

View File

@ -454,21 +454,50 @@ PARAMS is a property list of the following parameters:
`org-ql' expression (in sexp syntax) to filter the list of tasks. `org-ql' expression (in sexp syntax) to filter the list of tasks.
`:sort-column'
Specify the column to sort by. Can be any of `task', `effort',
`timestamp', `scheduled', or `deadline'.
All tasks between `:start-date' and `:end-date' will be collected All tasks between `:start-date' and `:end-date' will be collected
and their effort summed up. The date format is everything and their effort summed up. The date format is everything
understood by `org-read-date'." understood by `org-read-date'."
(let* ((start-date (plist-get params :start-date)) (let* ((start-date (plist-get params :start-date))
(end-date (plist-get params :end-date)) (end-date (plist-get params :end-date))
(org-ql-match (plist-get params :org-ql-match)) (org-ql-match (plist-get params :org-ql-match))
(sort-column-count (cl-case (plist-get params :sort-column)
((nil) 2) ; sort by effort by default
((task) 1)
((effort) 2)
((timestamp) 3)
((scheduled) 4)
((deadline) 5)
(otherwise (user-error ":sort-column value invalid, see docstring of `org-dblock-write:db/org-workload-report' for options"))))
(task-summary (db/org-planned-tasks-in-range start-date end-date org-ql-match))) (task-summary (db/org-planned-tasks-in-range start-date end-date org-ql-match)))
(insert "| Task | Effort |\n|---|\n") (message "foo %s %s" (plist-get params :sort-column) sort-column-count)
(insert "| Task | Effort | Timestamp | SCHEDULED | DEADLINE |\n|---|\n")
(pcase-dolist (`(,task-id . ,effort-string) (cdr task-summary)) (pcase-dolist (`(,task-id . ,effort-string) (cdr task-summary))
(insert (format "| %s | %s |\n" (insert (format "| %s | %s | %s | %s | %s |\n"
(db/org--format-link-from-org-id task-id) (db/org--format-link-from-org-id task-id)
(or effort-string "")))) (or effort-string "")
(or (org-entry-get (org-id-find task-id 'marker)
"TIMESTAMP")
"")
(or (org-entry-get (org-id-find task-id 'marker)
"SCHEDULED")
"")
(or (org-entry-get (org-id-find task-id 'marker)
"DEADLINE")
""))))
(insert (format "|---|\n| Total | %s |\n|---|" (car task-summary))) (insert (format "|---|\n| Total | %s |\n|---|" (car task-summary)))
(org-table-align))) (org-table-align)
(forward-line -4) ; go back to actual data
(beginning-of-line)
(dotimes (_ sort-column-count) ; move to column to sort
(org-table-next-field))
(org-table-sort-lines nil ?t)))
(defun db/org-insert-workload-report () (defun db/org-insert-workload-report ()
"Create dynamic block of planned tasks in given time range." "Create dynamic block of planned tasks in given time range."