diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index dc155497290..8dc7658dc0c 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2735,6 +2735,8 @@ [state config {:keys [title query view collapsed? children? breadcrumb-show? table-view?] :as q}] (let [dsl-query? (:dsl-query? config) query-atom (:query-atom state) + repo (state/get-current-repo) + view-fn (if (keyword? view) (state/sub [:config repo :query/views view]) view) current-block-uuid (or (:block/uuid (:block config)) (:block/uuid config)) current-block (db/entity [:block/uuid current-block-uuid]) @@ -2755,7 +2757,7 @@ _ (when-let [query-result (:query-result config)] (let [result (remove (fn [b] (some? (get-in b [:block/properties :template]))) result)] (reset! query-result result))) - view-f (and view (sci/eval-string (pr-str view))) + view-f (and view-fn (sci/eval-string (pr-str view-fn))) only-blocks? (:block/uuid (first result)) blocks-grouped-by-page? (and (seq result) (not not-grouped-by-page?) @@ -3262,4 +3264,4 @@ {})])))] :else - (blocks-container blocks config))]) + (blocks-container blocks config))]) \ No newline at end of file diff --git a/src/main/frontend/db/query_react.cljs b/src/main/frontend/db/query_react.cljs index 2d8b511a77c..ec4200f3e37 100644 --- a/src/main/frontend/db/query_react.cljs +++ b/src/main/frontend/db/query_react.cljs @@ -76,8 +76,10 @@ remove-nested-children-blocks (model/sort-by-left-recursive) (model/with-pages))) - result)] - (if-let [result-transform (:result-transform q)] + result) + result-transform-fn (:result-transform q) + repo (state/get-current-repo)] + (if-let [result-transform (if (keyword? result-transform-fn) (state/sub [:config repo :query/result-transforms result-transform-fn]) result-transform-fn)] (if-let [f (sci/eval-string (pr-str result-transform))] (try (sci/call-fn f result) @@ -130,4 +132,4 @@ k [:custom query']] (pprint "inputs (post-resolution):" resolved-inputs) (pprint "query-opts:" query-opts) - (apply react/q repo k query-opts query inputs)))) + (apply react/q repo k query-opts query inputs)))) \ No newline at end of file diff --git a/src/main/frontend/extensions/sci.cljs b/src/main/frontend/extensions/sci.cljs index acf878b7fb9..f0baed035e5 100644 --- a/src/main/frontend/extensions/sci.cljs +++ b/src/main/frontend/extensions/sci.cljs @@ -1,5 +1,6 @@ (ns frontend.extensions.sci - (:require [sci.core :as sci])) + (:require [sci.core :as sci] + [frontend.util :as util])) ;; Some helpers (def sum (partial apply +)) @@ -13,7 +14,9 @@ (sci/eval-string s {:bindings {'sum sum 'average average 'parseFloat js/parseFloat - 'isNaN js/isNaN}}) + 'isNaN js/isNaN + 'log js/console.log + 'pprint util/pp-str}}) (catch js/Error e (println "Query: sci eval failed:") (js/console.error e)))) @@ -29,4 +32,4 @@ [:div.results.mt-1 [:pre.code (let [result (eval-string code)] - (str result))]]]) + (str result))]]]) \ No newline at end of file diff --git a/templates/config.edn b/templates/config.edn index 96d90fdee76..d57093920fb 100644 --- a/templates/config.edn +++ b/templates/config.edn @@ -108,6 +108,16 @@ ;; Whether to show empty bullets for non-document mode (the default mode) :ui/show-empty-bullets? false + ;; Pre-defined :view function to use in Query + :query/views + {:pprint + (fn [r] [:pre.code (pprint r)])} + + ;; Pre-defined :result-transform function to use in Query + :query/result-transforms + {:sort-by-priority + (fn [result] (sort-by (fn [h] (get h :block/priority "Z")) result))} + ;; The app will show those queries in today's journal page, ;; the "NOW" query asks the tasks which need to be finished "now", ;; the "NEXT" query asks the future tasks. @@ -205,7 +215,7 @@ ;; ignore #+keyword: for parsing page references in orgmode ;; :ignored-page-references-keywords #{"author" "startup"} - + ;; Quick capture templates on mobile for recieving contents from other apps. ;; Each template contains three elements {time}, {text} and {url}, which can be auto-expanded ;; by received contents from other apps. Note: the {} cannot be omitted.