mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix: add pre-configured properties when creating a new db graph
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
[:div.grid.grid-cols-4.gap-1.leading-8
|
||||
[:label "Schema type:"]
|
||||
(let [schema-types (->> (keys property-handler/builtin-schema-types)
|
||||
(remove gp-property/db-built-in-properties-keys)
|
||||
(map (comp string/capitalize name))
|
||||
(map (fn [type]
|
||||
{:label type
|
||||
@@ -548,7 +549,7 @@
|
||||
(:properties (:block/schema e))))))
|
||||
(map (fn [id]
|
||||
[id nil])))
|
||||
built-in-properties (set (map name (gp-property/full-built-in-properties)))
|
||||
built-in-properties (set (map name gp-property/db-built-in-properties-keys))
|
||||
properties (->> (concat (seq properties) class-properties)
|
||||
(util/distinct-by first)
|
||||
(remove (fn [[k _v]]
|
||||
|
||||
@@ -110,9 +110,11 @@
|
||||
|
||||
(defn get-columns [current-block result {:keys [page?]}]
|
||||
(let [properties (:block/properties current-block)
|
||||
query-properties (or (pu/lookup properties :query-properties) "")
|
||||
query-properties (some-> query-properties
|
||||
(common-handler/safe-read-string "Parsing query properties failed"))
|
||||
query-properties (pu/lookup properties :query-properties)
|
||||
query-properties (if (config/db-based-graph? (state/get-current-repo))
|
||||
query-properties
|
||||
(some-> query-properties
|
||||
(common-handler/safe-read-string "Parsing query properties failed")))
|
||||
query-properties (if page? (remove #{:block} query-properties) query-properties)
|
||||
columns (if (seq query-properties)
|
||||
query-properties
|
||||
|
||||
@@ -192,11 +192,11 @@
|
||||
ref-block)
|
||||
(let [text (:text content)
|
||||
wrap-props #(if-let [stamp (:image content)]
|
||||
(assoc % :hl-type "area" :hl-stamp stamp)
|
||||
(assoc % :hl-type :area :hl-stamp stamp)
|
||||
%)
|
||||
properties (->>
|
||||
(wrap-props
|
||||
{:ls-type "annotation"
|
||||
{:ls-type :annotation
|
||||
:hl-page page
|
||||
:hl-color (:color properties)
|
||||
;; force custom uuid
|
||||
|
||||
@@ -56,7 +56,14 @@
|
||||
logseq-block?]
|
||||
:object [:fn
|
||||
{:error/message "should be an object"}
|
||||
logseq-object?]})
|
||||
logseq-object?]
|
||||
|
||||
;; internal usage
|
||||
:map map?
|
||||
:coll coll?
|
||||
:any some?})
|
||||
|
||||
(def internal-builtin-schema-types #{:map :coll :any})
|
||||
|
||||
;; schema -> type, cardinality, object's class
|
||||
;; min, max -> string length, number range, cardinality size limit
|
||||
|
||||
@@ -804,19 +804,26 @@
|
||||
[block-id all-properties key add?]
|
||||
(when-let [block (db/entity [:block/uuid block-id])]
|
||||
(let [properties (:block/properties block)
|
||||
query-properties (or (pu/lookup properties :query-properties) "")
|
||||
query-properties (-> query-properties
|
||||
(common-handler/safe-read-string "Failed to parse query properties"))
|
||||
query-properties (pu/lookup properties :query-properties)
|
||||
repo (state/get-current-repo)
|
||||
db-based? (config/db-based-graph? repo)
|
||||
query-properties (if db-based?
|
||||
query-properties
|
||||
(some-> query-properties
|
||||
(common-handler/safe-read-string "Parsing query properties failed")))
|
||||
query-properties (if (seq query-properties)
|
||||
query-properties
|
||||
all-properties)
|
||||
query-properties (if add?
|
||||
(distinct (conj query-properties key))
|
||||
(remove #{key} query-properties))
|
||||
query-properties (vec query-properties)
|
||||
repo (state/get-current-repo)]
|
||||
query-properties (vec query-properties)]
|
||||
(if (seq query-properties)
|
||||
(property-handler/set-block-property! repo block-id :query-properties (str query-properties))
|
||||
(property-handler/set-block-property! repo block-id
|
||||
:query-properties
|
||||
(if db-based?
|
||||
query-properties
|
||||
(str query-properties)))
|
||||
(property-handler/remove-block-property! repo block-id :query-properties)))))
|
||||
|
||||
(defn set-block-timestamp!
|
||||
|
||||
@@ -949,16 +949,20 @@
|
||||
(let [name (:block/name p)]
|
||||
(or (util/uuid-string? name)
|
||||
(gp-config/draw? name)
|
||||
(db/built-in-pages-names (string/upper-case name))))))
|
||||
(db/built-in-pages-names (string/upper-case name))
|
||||
(gp-property/db-built-in-properties-keys-str name)
|
||||
(contains? #{"macro"} (:block/type p))))))
|
||||
(common-handler/fix-pages-timestamps)))
|
||||
|
||||
(defn get-filters
|
||||
[page-name]
|
||||
(let [properties (db/get-page-properties page-name)
|
||||
properties-str (or (pu/lookup properties :filters) "{}")]
|
||||
(try (reader/read-string properties-str)
|
||||
(catch :default e
|
||||
(log/error :syntax/filters e)))))
|
||||
(let [properties (db/get-page-properties page-name)]
|
||||
(if (config/db-based-graph? (state/get-current-repo))
|
||||
(pu/lookup properties :filters)
|
||||
(let [properties-str (or (:filters properties) "{}")]
|
||||
(try (reader/read-string properties-str)
|
||||
(catch :default e
|
||||
(log/error :syntax/filters e)))))))
|
||||
|
||||
(defn save-filter!
|
||||
[page-name filter-state]
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (and (config/db-based-graph? repo)
|
||||
(keyword? key)
|
||||
(contains? (gp-property/full-built-in-properties) key))
|
||||
(contains? gp-property/db-built-in-properties-keys key))
|
||||
(when-let [property (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name key))])]
|
||||
(get coll (:block/uuid property)))
|
||||
(get coll key))))
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
[frontend.db.persist :as db-persist]
|
||||
[logseq.graph-parser :as graph-parser]
|
||||
[logseq.graph-parser.config :as gp-config]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[electron.ipc :as ipc]
|
||||
[cljs-bean.core :as bean]
|
||||
[clojure.core.async :as async]
|
||||
@@ -34,7 +35,8 @@
|
||||
[logseq.common.path :as path]
|
||||
[logseq.common.config :as common-config]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.db.listener :as db-listener]))
|
||||
[frontend.db.listener :as db-listener]
|
||||
[frontend.modules.outliner.core :as outliner-core]))
|
||||
|
||||
;; Project settings should be checked in two situations:
|
||||
;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
|
||||
@@ -544,16 +546,27 @@
|
||||
_ (state/add-repo! {:url full-graph-name})
|
||||
_ (route-handler/redirect-to-home!)
|
||||
_ (db/transact! full-graph-name [(react/kv :db/type "db")]
|
||||
{:skip-persist? true})
|
||||
initial-data [{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "config.edn")
|
||||
:file/content config/config-default-content}
|
||||
{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "custom.css")
|
||||
:file/content ""}
|
||||
{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "custom.js")
|
||||
:file/content ""}]
|
||||
{:skip-persist? true})
|
||||
initial-files [{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "config.edn")
|
||||
:file/content config/config-default-content}
|
||||
{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "custom.css")
|
||||
:file/content ""}
|
||||
{:block/uuid (db/new-block-id)
|
||||
:file/path (str "logseq/" "custom.js")
|
||||
:file/content ""}]
|
||||
default-properties (map
|
||||
(fn [[k-keyword {:keys [schema]}]]
|
||||
(let [k-name (name k-keyword)]
|
||||
(outliner-core/block-with-timestamps
|
||||
{:block/schema schema
|
||||
:block/original-name k-name
|
||||
:block/name (util/page-name-sanity-lc k-name)
|
||||
:block/uuid (db/new-block-id)
|
||||
:block/type "property"})))
|
||||
gp-property/db-built-in-properties)
|
||||
initial-data (concat initial-files default-properties)
|
||||
_ (db/transact! full-graph-name initial-data)
|
||||
_ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
||||
;; TODO: handle global graph
|
||||
|
||||
Reference in New Issue
Block a user