branch: externals/org-gnosis
commit 970613d1dc92e05a2a2db1c23e742b1b8b6f934e
Author: Thanos Apollo <[email protected]>
Commit: Thanos Apollo <[email protected]>

    [Refactor] Extract node selection by tag into a separate function.
    
    * Extract the logic for retrieving ids to a helper function.
      * Which will be used in gnosis-dashboard.
---
 org-gnosis.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/org-gnosis.el b/org-gnosis.el
index ad2b710bfc..22b564aafd 100644
--- a/org-gnosis.el
+++ b/org-gnosis.el
@@ -565,6 +565,11 @@ DIRECTORY."
              "File %s does not exist.  Try running `org-gnosis-db-sync' to 
resolve this"
              file)))))
 
+(defun org-gnosis--nodes-by-tag (tag)
+  "Return all nodes associated with TAG.
+Returns a list of (ID) pairs for nodes that have TAG."
+  (org-gnosis-select 'id 'nodes `(like tags ',(format "%%\\\"%s\\\"%%" tag)) 
t))
+
 ;;;###autoload
 (defun org-gnosis-find-by-tag (&optional tag)
   "Find node under TAG."
@@ -572,11 +577,9 @@ DIRECTORY."
   (let* ((tag (or tag (funcall org-gnosis-completing-read-func
                               "Select tag: "
                               (org-gnosis-select 'tag 'tags nil t))))
-        (node
-         (funcall org-gnosis-completing-read-func
-                  "Select node: "
-                  (org-gnosis-select 'title 'nodes
-                                     `(like tags ',(format "%%\"%s\"%%" tag)) 
t))))
+        (nodes-ids (org-gnosis--nodes-by-tag tag))
+        (node-titles (org-gnosis-select 'title 'nodes `(in id ,(vconcat 
nodes-ids)) t))
+        (node (completing-read "Select node: " node-titles nil t)))
     (org-gnosis-find node)))
 
 (defun org-gnosis-select-template (templates)

Reply via email to