Sfoglia il codice sorgente

enhance: deprecate :default-templates config for db graphs

Db graph no longer invoke file graph config and queries for today
journal and on journal page load
Gabriel Horner 10 mesi fa
parent
commit
584faf2f48

+ 1 - 0
deps/common/resources/templates/config.edn

@@ -22,6 +22,7 @@
 
  ;; Define the default journal page template.
  ;; Enter the template name between the quotes.
+ ;; This is _only_ for file graphs.
  :default-templates
  {:journals ""}
 

+ 8 - 7
src/main/frontend/components/page.cljs

@@ -191,13 +191,14 @@
 
 (rum/defcs page-blocks-cp < rum/reactive db-mixins/query
   {:will-mount (fn [state]
-                 (let [page-e (first (:rum/args state))
-                       page-name (:block/name page-e)]
-                   (when (and page-name
-                              (db/journal-page? page-name)
-                              (>= (date/journal-title->int page-name)
-                                  (date/journal-title->int (date/today))))
-                     (state/pub-event! [:journal/insert-template page-name])))
+                 (when-not (config/db-based-graph?)
+                  (let [page-e (first (:rum/args state))
+                        page-name (:block/name page-e)]
+                    (when (and page-name
+                               (db/journal-page? page-name)
+                               (>= (date/journal-title->int page-name)
+                                   (date/journal-title->int (date/today))))
+                      (state/pub-event! [:journal/insert-template page-name]))))
                  state)}
   [state block* {:keys [sidebar? whiteboard?] :as config}]
   (when-let [id (:db/id block*)]

+ 3 - 1
src/main/frontend/handler/common/config_edn.cljs

@@ -115,7 +115,9 @@ nested keys or positional errors e.g. tuples"
     :feature/enable-block-timestamps?
     "is not used in DB graphs as it is always enabled"
     :favorites
-    "is not stored in config for DB graphs"}))
+    "is not stored in config for DB graphs"
+    :default-templates
+    "is replaced by #Template and the `Apply template to tags` property"}))
 
 (defn detect-deprecations
   "Detects config keys that will or have been deprecated"

+ 0 - 12
src/main/frontend/handler/events.cljs

@@ -343,18 +343,6 @@
 (defmethod handle :shortcut/refresh [[_]]
   (st/refresh!))
 
-(defmethod handle :journal/insert-template [[_ page-name]]
-  (let [page-name (util/page-name-sanity-lc page-name)]
-    (when-let [page (db/get-page page-name)]
-      (p/do!
-       (db-async/<get-block (state/get-current-repo) (:db/id page))
-       (when (db/page-empty? (state/get-current-repo) page-name)
-         (when-let [template (state/get-default-journal-template)]
-           (editor-handler/insert-template!
-            nil
-            template
-            {:target page})))))))
-
 (defmethod handle :editor/set-heading [[_ block heading]]
   (when-let [id (:block/uuid block)]
     (editor-handler/set-heading! id heading)))

+ 14 - 0
src/main/frontend/handler/file_based/events.cljs

@@ -10,9 +10,11 @@
             [frontend.config :as config]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
+            [frontend.db.async :as db-async]
             [frontend.fs :as fs]
             [frontend.fs.sync :as sync]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.editor :as editor-handler]
             [frontend.handler.events :as events]
             [frontend.handler.file-based.file :as file-handler]
             [frontend.handler.file-based.nfs :as nfs-handler]
@@ -353,3 +355,15 @@
                                           :remote? true)
                                    r))
                                (state/get-repos)))))))
+
+(defmethod events/handle :journal/insert-template [[_ page-name]]
+  (let [page-name (util/page-name-sanity-lc page-name)]
+    (when-let [page (db/get-page page-name)]
+      (p/do!
+       (db-async/<get-block (state/get-current-repo) (:db/id page))
+       (when (db/page-empty? (state/get-current-repo) page-name)
+         (when-let [template (state/get-default-journal-template)]
+           (editor-handler/insert-template!
+            nil
+            template
+            {:target page})))))))

+ 6 - 4
src/main/frontend/handler/page.cljs

@@ -366,18 +366,20 @@
         (let [title (date/today)
               today-page (util/page-name-sanity-lc title)
               format (state/get-preferred-format repo)
-              template (state/get-default-journal-template)
+              db-based? (config/db-based-graph? repo)
               create-f (fn []
                          (p/do!
                           (<create! title {:redirect? false
                                            :split-namespace? false
-                                           :create-first-block? (not template)
+                                           :create-first-block? (if db-based?
+                                                                  true
+                                                                  (not (state/get-default-journal-template)))
                                            :today-journal? true})
-                          (state/pub-event! [:journal/insert-template today-page])
+                          (when-not db-based? (state/pub-event! [:journal/insert-template today-page]))
                           (ui-handler/re-render-root!)
                           (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
           (when (db/page-empty? repo today-page)
-            (if (config/db-based-graph? repo)
+            (if db-based?
               (when-not (model/get-journal-page title)
                 (create-f))
               (p/let [file-name (date/journal-title->default title)