From b9e491d6ab0ab7a8d900d127ef1d3a0fdaa2ffe1 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Mon, 2 Aug 2021 18:31:18 +0200 Subject: feature: tag filtering lotic and ui --- org-roam-ui.el | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'org-roam-ui.el') diff --git a/org-roam-ui.el b/org-roam-ui.el index 098e99e..5ac7eac 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -159,9 +159,14 @@ This serves the web-build and API over HTTP." (defun org-roam-ui--send-graphdata () "Get roam data, make JSON, send through websocket to org-roam-ui." - (let* ((nodes-columns [id file title level properties]) + (let* ((nodes-columns [id file title level properties ,(funcall group-concat tag (emacsql-escape-raw \, ))]) + (nodes-names [id file title level properties tags]) (links-columns [links:source links:dest links:type refs:node-id]) - (nodes-db-rows (org-roam-db-query `[:select ,nodes-columns :from nodes])) + (nodes-db-rows (org-roam-db-query `[:select ,nodes-columns :as tags + :from nodes + :left-join tags + :on (= id node_id) + :group :by id])) ;; Left outer join on refs means any id link (or cite link without a ;; corresponding node) will have 'nil for the `refs:node-id' value. Any ;; cite link where a node has that `:ROAM_REFS:' will have a value. @@ -177,8 +182,9 @@ This serves the web-build and API over HTTP." (if node-id (list source node-id "cite") (list source dest type)))) links-db-rows)) - (response `((nodes . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist (append nodes-columns nil)) nodes-db-rows)) - (links . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist '(source target type)) links-db-rows))))) + (response `((nodes . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist (append nodes-names nil)) nodes-db-rows)) + (links . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist '(source target type)) links-db-rows)) + (tags . ,(seq-mapcat #'seq-reverse (org-roam-db-query [:select :distinct tag :from tags])))))) (websocket-send-text oru-ws (json-encode `((type . "graphdata") (data . ,response)))))) (defun org-roam-ui--update-current-node () @@ -227,7 +233,15 @@ This serves the web-build and API over HTTP." ROWS is the sql result, while COLUMN-NAMES is the columns to use." (let (res) (while rows - (push (cons (pop column-names) (pop rows)) res)) + ;; emacsql does not want to give us the tags as a list, so we post process it + (if (not (string= (car column-names) "tags")) + (push (cons (pop column-names) (pop rows)) res) + (push (cons (pop column-names) + (seq-remove + (lambda (elt) (string= elt ",")) + rows)) + res) + (setq rows nil))) res)) -- cgit v1.2.3