Skip to content

Commit

Permalink
fix: query dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 25, 2021
1 parent 1f17da3 commit e7879c5
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 139 deletions.
3 changes: 2 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@
(rum/defc block-children < rum/reactive
[config children collapsed? *ref-collapsed?]
(let [ref? (:ref? config)
collapsed? (if ref? (rum/react *ref-collapsed?) collapsed?)]
collapsed? (if ref? (rum/react *ref-collapsed?) collapsed?)
children (filter map? children)]
(when (and (seq children) (not collapsed?))
(let [doc-mode? (:document/mode? config)]
[:div.block-children {:style {:margin-left (if doc-mode? 12 21)
Expand Down
41 changes: 25 additions & 16 deletions src/main/frontend/db/query_dsl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
[clojure.walk :as walk]
[clojure.core]
[clojure.set :as set]
[frontend.template :as template]))
[frontend.template :as template]
[frontend.util.property :as property]))

;; Query fields:

Expand Down Expand Up @@ -218,25 +219,30 @@

(and (= 'property fe)
(= 3 (count e)))
(let [v (nth e 2)
v (if (or (string? v) (symbol? v))
(some-> (name v)
(text/page-ref-un-brackets!))
(let [k (string/replace (name (nth e 1)) "_" "-")
v (nth e 2)
v (if-not (nil? v)
(property/parse-property k v)
v)
v (if (coll? v) (first v) v)
sym (if (= current-filter 'or)
'?v
(uniq-symbol counter "?v"))]
(uniq-symbol counter "?v"))]
[['?b :block/properties '?prop]
[(list 'get '?prop (keyword (nth e 1))) sym]
[(list 'missing? '$ '?b :block/name)]
[(list 'get '?prop (keyword k)) sym]
(list
'or
[(list '= sym v)]
[(list 'contains? sym v)])])

(and (= 'property fe)
(= 2 (count e)))
[['?b :block/properties '?prop]
[(list 'get '?prop (keyword (nth e 1)))]]
(let [k (string/replace (name (nth e 1)) "_" "-")]
[['?b :block/properties '?prop]
[(list 'missing? '$ '?b :block/name)]
[(list 'get '?prop (keyword k)) '?prop-v]
[true]])

(or (= 'todo fe) (= 'task fe))
(let [markers (if (coll? (first (rest e)))
Expand Down Expand Up @@ -280,20 +286,23 @@
[['?b :block/page [:block/name page-name]]])

(= 'page-property fe)
(let [[k v] (rest e)]
(if v
(let [v (some->> (name (nth e 2))
(text/page-ref-un-brackets!))
(let [[k v] (rest e)
k (string/replace (name k) "_" "-")]
(if-not (nil? v)
(let [v (property/parse-property k v)
v (if (coll? v) (first v) v)
sym '?v]
[['?p :block/name]
['?p :block/properties '?prop]
[(list 'get '?prop (keyword (nth e 1))) sym]
[(list 'get '?prop (keyword k)) sym]
(list
'or
[(list '= sym v)]
[(list 'contains? sym v)])])
[['?p :block/properties '?prop]
[(list 'get '?prop (keyword (nth e 1)))]]))
[['?p :block/name]
['?p :block/properties '?prop]
[(list 'get '?prop (keyword k)) '?prop-v]
[true]]))

(= 'page-tags fe)
(do
Expand Down
24 changes: 1 addition & 23 deletions src/main/frontend/format/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,7 @@
k)
v (if (coll? v)
v
(let [v (string/trim v)
v (cond
(= v "true")
true
(= v "false")
false

(util/safe-re-find #"^\d+$" v)
(util/safe-parse-int v)

(and (= "\"" (first v) (last v))) ; wrapped in ""
(string/trim (subs v 1 (dec (count v))))

(contains? @non-parsing-properties (string/lower-case k))
v

:else
(if (and k v
(contains? config/markers k)
(util/safe-parse-int v))
(util/safe-parse-int v)
(text/split-page-refs-without-brackets v true)))]
v))
(property/parse-property k v))
k (keyword k)
v (if (and
(string? v)
Expand Down
7 changes: 4 additions & 3 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@
([node pos]
(scroll-to node pos true))
([node pos animate?]
(.scroll node
#js {:top pos
:behavior (if animate? "smooth" "auto")}))))
(when node
(.scroll node
#js {:top pos
:behavior (if animate? "smooth" "auto")})))))

#?(:cljs
(defn scroll-to-top
Expand Down
29 changes: 28 additions & 1 deletion src/main/frontend/util/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[clojure.set :as set]
[frontend.config :as config]
[medley.core :as medley]
[frontend.format.mldoc :as mldoc]))
[frontend.format.mldoc :as mldoc]
[frontend.text :as text]))

(defonce properties-start ":PROPERTIES:")
(defonce properties-end ":END:")
Expand Down Expand Up @@ -321,3 +322,29 @@
(vector? block)
(contains? #{"Property_Drawer" "Properties"}
(first block))))

(defonce non-parsing-properties
(atom #{"background-color" "background_color"}))

(defn parse-property
[k v]
(let [k (name k)
v (if (or (symbol? v) (keyword? v)) (name v) (str v))
v (string/trim v)]
(cond
(= v "true")
true
(= v "false")
false

(util/safe-re-find #"^\d+$" v)
(util/safe-parse-int v)

(and (= "\"" (first v) (last v))) ; wrapped in ""
(string/trim (subs v 1 (dec (count v))))

(contains? @non-parsing-properties (string/lower-case k))
v

:else
(text/split-page-refs-without-brackets v true))))
Loading

0 comments on commit e7879c5

Please sign in to comment.