From fe39d9ee94acad2d3a61475a946c9368b46cca0e Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Thu, 14 Oct 2021 16:29:03 +0200
Subject: [PATCH] DRAFT: Add function to extract and transform query string

---
 src/core/js/ext_bookmarks.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/core/js/ext_bookmarks.js b/src/core/js/ext_bookmarks.js
index 025f3f3c..676d25c5 100644
--- a/src/core/js/ext_bookmarks.js
+++ b/src/core/js/ext_bookmarks.js
@@ -599,6 +599,20 @@ var ext_bookmarks = function ($, logger, config) {
         }
     }
 
+    /**
+     * Return the SELECT query created from the contents of the query response field
+     */
+    const get_query_from_response = function () {
+        // Go through divs in response field and extract the query string.
+        const divs = $(".caosdb-query-response-heading").find("div");
+        for (const div of divs) {
+            if (div.innerText.startsWith("Query:") && !div.innerText.includes("Results:")) {
+                return get_select_id_query_string(
+                    div.innerText.slice(div.innerText.indexOf(" ") + 1));
+            }
+        }
+    }
+
     /**
      * Initialize this module.
      */
@@ -690,6 +704,7 @@ var ext_bookmarks = function ($, logger, config) {
         init_button: init_button,
         get_bookmark_data: get_bookmark_data,
         get_select_id_query_string: get_select_id_query_string,
+        get_query_from_response: get_query_from_response,
     }
 };
 
-- 
GitLab