fix: allow templates to be applied on #Journal

This commit is contained in:
Tienson Qin
2025-03-04 06:04:40 +08:00
parent b7e81afd84
commit 72e57ad3a6
2 changed files with 30 additions and 28 deletions

View File

@@ -659,7 +659,8 @@
(mapcat
(fn [class]
(if (= :logseq.class/Root (:db/ident class))
(model/get-all-classes repo {:except-root-class? true})
(model/get-all-classes repo {:except-root-class? true
:except-private-tags? (not (contains? #{:logseq.property/template-applied-to} (:db/ident property)))})
(model/get-class-objects repo (:db/id class))))
classes)
distinct)

View File

@@ -51,33 +51,34 @@
(defn- insert-tag-templates
[repo conn tx-report]
(let [db (:db-after tx-report)
tx-data (->> (filter (fn [d] (and (= (:a d) :block/tags) (:added d))) (:tx-data tx-report))
(group-by :e)
(mapcat (fn [[e datoms]]
(let [object (d/entity db e)
template-blocks (->> (mapcat (fn [id]
(let [tag (d/entity db id)
parents (ldb/get-page-parents tag {:node-class? true})
templates (mapcat :logseq.property/_template-applied-to (conj parents tag))]
templates))
(set (map :v datoms)))
distinct
(mapcat (fn [template]
(let [template-blocks (rest (ldb/get-block-and-children db (:block/uuid template)))
blocks (->>
(cons (assoc (first template-blocks) :logseq.property/used-template (:db/id template))
(rest template-blocks))
(map (fn [e] (assoc (into {} e) :db/id (:db/id e)))))]
blocks))))
result (outliner-core/insert-blocks repo conn template-blocks object {:sibling? false})
tx-data (:tx-data result)]
;; Replace entities with eid because Datascript doesn't support entity transaction
(walk/prewalk
(fn [f]
(if (de/entity? f)
(:db/id f)
f))
tx-data)))))]
tx-data (some->> (filter (fn [d] (and (= (:a d) :block/tags) (:added d))) (:tx-data tx-report))
(group-by :e)
(mapcat (fn [[e datoms]]
(let [object (d/entity db e)
template-blocks (->> (mapcat (fn [id]
(let [tag (d/entity db id)
parents (ldb/get-page-parents tag {:node-class? true})
templates (mapcat :logseq.property/_template-applied-to (conj parents tag))]
templates))
(set (map :v datoms)))
distinct
(mapcat (fn [template]
(let [template-blocks (rest (ldb/get-block-and-children db (:block/uuid template)))
blocks (->>
(cons (assoc (first template-blocks) :logseq.property/used-template (:db/id template))
(rest template-blocks))
(map (fn [e] (assoc (into {} e) :db/id (:db/id e)))))]
blocks))))]
(when (seq template-blocks)
(let [result (outliner-core/insert-blocks repo conn template-blocks object {:sibling? false})
tx-data (:tx-data result)]
;; Replace entities with eid because Datascript doesn't support entity transaction
(walk/prewalk
(fn [f]
(if (de/entity? f)
(:db/id f)
f))
tx-data)))))))]
tx-data))
(defkeywords