From 72e57ad3a65f6391c6de2e0e8b8607cb19516dca Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 4 Mar 2025 06:04:40 +0800 Subject: [PATCH] fix: allow templates to be applied on #Journal --- .../frontend/components/property/value.cljs | 3 +- src/main/frontend/worker/pipeline.cljs | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 1ca9b3d82f..8843a43073 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -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) diff --git a/src/main/frontend/worker/pipeline.cljs b/src/main/frontend/worker/pipeline.cljs index f762f435da..fbff1d1829 100644 --- a/src/main/frontend/worker/pipeline.cljs +++ b/src/main/frontend/worker/pipeline.cljs @@ -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