Browse Source

fix: allow templates to be applied on #Journal

Tienson Qin 8 months ago
parent
commit
72e57ad3a6

+ 2 - 1
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)

+ 28 - 27
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