mirror of https://github.com/logseq/logseq
refactor(db): get-config reset-config!
parent
f93d643d08
commit
4410ae7147
|
@ -41,7 +41,7 @@
|
||||||
get-all-templates get-block-and-children get-block-and-children-no-cache get-block-by-uuid get-block-children
|
get-all-templates get-block-and-children get-block-and-children-no-cache get-block-by-uuid get-block-children
|
||||||
get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page
|
get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page
|
||||||
get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count
|
get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count
|
||||||
get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-config get-custom-css
|
get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-custom-css
|
||||||
get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file get-file-after-blocks get-file-after-blocks-meta
|
get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file get-file-after-blocks get-file-after-blocks-meta
|
||||||
get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id
|
get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id
|
||||||
get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
|
get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references
|
get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references
|
||||||
get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
|
get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
|
||||||
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
|
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
|
||||||
reset-config! set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages]
|
set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages]
|
||||||
|
|
||||||
[frontend.db.react
|
[frontend.db.react
|
||||||
get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value
|
get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value
|
||||||
|
|
|
@ -997,22 +997,6 @@
|
||||||
repo-url)
|
repo-url)
|
||||||
ffirst)))
|
ffirst)))
|
||||||
|
|
||||||
(defn get-config
|
|
||||||
[repo-url]
|
|
||||||
(get-file repo-url (str config/app-name "/" config/config-file)))
|
|
||||||
|
|
||||||
(defn reset-config!
|
|
||||||
[repo-url content]
|
|
||||||
(when-let [content (or content (get-config repo-url))]
|
|
||||||
(let [config (try
|
|
||||||
(reader/read-string content)
|
|
||||||
(catch js/Error e
|
|
||||||
(println "Parsing config file failed: ")
|
|
||||||
(js/console.dir e)
|
|
||||||
{}))]
|
|
||||||
(state/set-config! repo-url config)
|
|
||||||
config)))
|
|
||||||
|
|
||||||
(defn get-db-type
|
(defn get-db-type
|
||||||
[repo]
|
[repo]
|
||||||
(db-utils/get-key-value repo :db/type))
|
(db-utils/get-key-value repo :db/type))
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[cljs-time.coerce :as tc]
|
[cljs-time.coerce :as tc]
|
||||||
[frontend.utf8 :as utf8]
|
[frontend.utf8 :as utf8]
|
||||||
["ignore" :as Ignore]))
|
["ignore" :as Ignore]
|
||||||
|
[frontend.handler.utils :as h-utils]))
|
||||||
|
|
||||||
(defn load-file
|
(defn load-file
|
||||||
[repo-url path]
|
[repo-url path]
|
||||||
|
@ -79,10 +80,10 @@
|
||||||
(restore-config! repo-url nil project-changed-check?))
|
(restore-config! repo-url nil project-changed-check?))
|
||||||
([repo-url config-content project-changed-check?]
|
([repo-url config-content project-changed-check?]
|
||||||
(let [config-content (if config-content config-content
|
(let [config-content (if config-content config-content
|
||||||
(db/get-config repo-url))]
|
(h-utils/get-config repo-url))]
|
||||||
(when config-content
|
(when config-content
|
||||||
(let [old-project (:project (state/get-config))
|
(let [old-project (:project (state/get-config))
|
||||||
new-config (db/reset-config! repo-url config-content)]
|
new-config (h-utils/reset-config! repo-url config-content)]
|
||||||
(when (and (not (config/local-db? repo-url))
|
(when (and (not (config/local-db? repo-url))
|
||||||
project-changed-check?)
|
project-changed-check?)
|
||||||
(let [new-project (:project new-config)
|
(let [new-project (:project new-config)
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[frontend.dicts :as dicts]
|
[frontend.dicts :as dicts]
|
||||||
[frontend.helper :as helper]
|
[frontend.helper :as helper]
|
||||||
[frontend.spec :as spec]))
|
[frontend.spec :as spec]
|
||||||
|
[frontend.handler.utils :as h-utils]))
|
||||||
|
|
||||||
;; Project settings should be checked in two situations:
|
;; Project settings should be checked in two situations:
|
||||||
;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
|
;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
|
||||||
|
@ -61,7 +62,7 @@
|
||||||
(db/get-file repo-url path))
|
(db/get-file repo-url path))
|
||||||
content (or old-content default-content)]
|
content (or old-content default-content)]
|
||||||
(file-handler/reset-file! repo-url path content)
|
(file-handler/reset-file! repo-url path content)
|
||||||
(db/reset-config! repo-url content)
|
(h-utils/reset-config! repo-url content)
|
||||||
(when-not (= content old-content)
|
(when-not (= content old-content)
|
||||||
(git-handler/git-add repo-url path))))))))
|
(git-handler/git-add repo-url path))))))))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
(ns frontend.handler.utils
|
||||||
|
(:require [frontend.state :as state]
|
||||||
|
[cljs.reader :as reader]
|
||||||
|
[frontend.config :as config]
|
||||||
|
[frontend.db :as db]))
|
||||||
|
|
||||||
|
(defn get-config
|
||||||
|
[repo-url]
|
||||||
|
(db/get-file repo-url (str config/app-name "/" config/config-file)))
|
||||||
|
|
||||||
|
(defn reset-config!
|
||||||
|
[repo-url content]
|
||||||
|
(when-let [content (or content (get-config repo-url))]
|
||||||
|
(let [config (try
|
||||||
|
(reader/read-string content)
|
||||||
|
(catch js/Error e
|
||||||
|
(println "Parsing config file failed: ")
|
||||||
|
(js/console.dir e)
|
||||||
|
{}))]
|
||||||
|
(state/set-config! repo-url config)
|
||||||
|
config)))
|
Loading…
Reference in New Issue