mirror of https://github.com/logseq/logseq
Adds support for :query-page as an input
parent
f0744e32c5
commit
c76da13570
|
@ -74,7 +74,7 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
|||
|
||||
(defn keyword-input-dispatch [input]
|
||||
(cond
|
||||
(#{:current-page :current-block :parent-block :today :yesterday :tomorrow :right-now-ms} input) input
|
||||
(#{:current-page :query-page :current-block :parent-block :today :yesterday :tomorrow :right-now-ms} input) input
|
||||
|
||||
(re-find #"^[+-]\d+[dwmy]?$" (name input)) :relative-date
|
||||
(re-find #"^[+-]\d+[dwmy]-(ms|start|end|\d{2}|\d{4}|\d{6}|\d{9})?$" (name input)) :relative-date-time
|
||||
|
@ -91,6 +91,10 @@ it will return 1622433600000, which is equivalent to Mon May 31 2021 00 :00:00."
|
|||
(when current-page-fn
|
||||
(some-> (current-page-fn) string/lower-case)))
|
||||
|
||||
(defmethod resolve-keyword-input :query-page [db _ {:keys [current-block-uuid]}]
|
||||
(when-let [current-block (and current-block-uuid (d/entity db [:block/uuid current-block-uuid]))]
|
||||
(get-in current-block [:block/page :block/name])))
|
||||
|
||||
(defmethod resolve-keyword-input :current-block [db _ {:keys [current-block-uuid]}]
|
||||
(when current-block-uuid
|
||||
(:db/id (d/entity db [:block/uuid current-block-uuid]))))
|
||||
|
|
|
@ -213,8 +213,8 @@
|
|||
(def default-formatter (tf/formatter "MMM do, yyyy"))
|
||||
(def zh-formatter (tf/formatter "YYYY年MM月dd日"))
|
||||
|
||||
(tf/show-formatters)
|
||||
(tf/show-formatters))
|
||||
|
||||
;; :date 2020-05-31
|
||||
;; :rfc822 Sun, 31 May 2020 03:00:57 Z
|
||||
)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[clojure.pprint]
|
||||
[clojure.string :as string]
|
||||
[frontend.state :as state]
|
||||
[frontend.date :as date]
|
||||
[logseq.graph-parser.util.db :as db-util]
|
||||
[frontend.test.helper :as test-helper :refer [load-test-files]]
|
||||
[frontend.db.query-custom :as query-custom]
|
||||
|
@ -40,6 +41,34 @@ adds rules that users often use"
|
|||
:in $ ?start ?end
|
||||
:where (between ?b ?start ?end)]})))
|
||||
|
||||
; (let [block-uuid (-> (db-utils/q '[:find (pull ?b [:block/uuid])
|
||||
; :where [?b :block/content "parent"]])
|
||||
; ffirst
|
||||
; :block/uuid)]
|
||||
; (map :block/content
|
||||
; (custom-query {:inputs [:current-block]
|
||||
; :query '[:find (pull ?b [*])
|
||||
; :in $ ?current-block
|
||||
; :where [?b :block/parent ?current-block]]}
|
||||
; {:current-block-uuid block-uuid})))))
|
||||
|
||||
(defn- block-with-content [block-content]
|
||||
(-> (db-utils/q '[:find (pull ?b [:block/uuid])
|
||||
:in $ ?content
|
||||
:where [?b :block/content ?content]]
|
||||
block-content)
|
||||
ffirst))
|
||||
|
||||
(defn- blocks-on-journal-page-from-block-with-content [page-input block-content]
|
||||
(prn :blocks-on-journal-page-from-block-with-content page-input)
|
||||
(prn :blocks-on-journal-page-from-block-with-content block-content)
|
||||
(map :block/content (custom-query {:inputs [page-input]
|
||||
:query '[:find (pull ?b [*])
|
||||
:in $ ?page
|
||||
:where [?b :block/page ?e]
|
||||
[?e :block/name ?page]]}
|
||||
{:current-block-uuid (get (block-with-content block-content) :block/uuid)})))
|
||||
|
||||
(deftest resolve-input-for-page-and-block-inputs
|
||||
(load-test-files [{:file/path "pages/page1.md"
|
||||
:file/content
|
||||
|
@ -270,3 +299,21 @@ created-at:: %s"
|
|||
(is (= ["+1d" "now"] (blocks-journaled-between-inputs :today :today/+1d))
|
||||
":today/+1d and today resolve to correct journal range")))
|
||||
|
||||
(deftest resolve-input-for-query-page
|
||||
(load-test-files [{:file/content "- -1d" :file/path "journals/2022_12_31.md"}
|
||||
{:file/content "- now" :file/path "journals/2023_01_01.md"}
|
||||
{:file/content "- +1d" :file/path "journals/2023_01_02.md"}])
|
||||
|
||||
(with-redefs [state/get-current-page (constantly (date/journal-name (t/date-time 2023 1 1)))]
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :current-page "now"))
|
||||
":current-page resolves to the stateful page when called from a block on the stateful page")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :query-page "now"))
|
||||
":query-page resolves to the stateful page when called from a block on the stateful page")
|
||||
|
||||
(is (= ["now"] (blocks-on-journal-page-from-block-with-content :current-page "+1d"))
|
||||
":current-page resolves to the stateful page when called from a block on another page")
|
||||
|
||||
(is (= ["+1d"] (blocks-on-journal-page-from-block-with-content :query-page "+1d"))
|
||||
":query-page resolves to the parent page when called from another page")))
|
||||
|
||||
|
|
Loading…
Reference in New Issue