mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 20:24:15 +00:00
Merge branch 'feat/db' into feat/capacitor-new
This commit is contained in:
3
deps/db/src/logseq/db/frontend/db.cljs
vendored
3
deps/db/src/logseq/db/frontend/db.cljs
vendored
@@ -40,8 +40,7 @@
|
||||
(defn get-all-properties
|
||||
[db]
|
||||
(->> (d/datoms db :avet :block/tags :logseq.class/Property)
|
||||
(map (fn [d]
|
||||
(d/entity db (:e d))))))
|
||||
(map (fn [d] (d/entity db (:e d))))))
|
||||
|
||||
(defn get-page-parents
|
||||
[node & {:keys [node-class?]}]
|
||||
|
||||
@@ -2131,8 +2131,9 @@
|
||||
own-number-list? (:own-order-number-list? config)
|
||||
order-list? (boolean own-number-list?)
|
||||
order-list-idx (:own-order-list-index config)
|
||||
page-title? (:page-title? config)
|
||||
collapsable? (editor-handler/collapsable? uuid {:semantic? true
|
||||
:ignore-children? (:page-title? config)})
|
||||
:ignore-children? page-title?})
|
||||
link? (boolean (:original-block config))
|
||||
icon-size (if collapsed? 12 14)
|
||||
icon (icon-component/get-node-icon-cp block {:size icon-size :color? true})
|
||||
@@ -2147,7 +2148,8 @@
|
||||
:is-with-icon with-icon?
|
||||
:bullet-closed collapsed?
|
||||
:bullet-hidden (:hide-bullet? config)}])}
|
||||
(when (and (or (not fold-button-right?) collapsable?) (not (:table? config)))
|
||||
(when (and (or (not fold-button-right?) collapsable?)
|
||||
(not (:table? config)))
|
||||
[:a.block-control
|
||||
{:id (str "control-" uuid)
|
||||
:on-click (fn [event]
|
||||
@@ -2162,7 +2164,7 @@
|
||||
(when (and (state/developer-mode?) (.-metaKey event))
|
||||
(js/console.debug "[block config]==" config)))}
|
||||
[:span {:class (if (or (and control-show? (or collapsed? collapsable?))
|
||||
(and collapsed? (or order-list? config/publishing?)))
|
||||
(and collapsed? (or page-title? order-list? config/publishing?)))
|
||||
"control-show cursor-pointer"
|
||||
"control-hide")}
|
||||
(ui/rotating-arrow collapsed?)]])
|
||||
|
||||
@@ -94,9 +94,10 @@
|
||||
:add-new-object! add-new-object!
|
||||
:show-add-property? true
|
||||
:show-items-count? true
|
||||
:add-property! (fn []
|
||||
:add-property! (fn [e]
|
||||
(state/pub-event! [:editor/new-property {:block class
|
||||
:class-schema? true}]))})]))
|
||||
:class-schema? true
|
||||
:target (.-target e)}]))})]))
|
||||
|
||||
(rum/defcs class-objects < rum/reactive db-mixins/query mixins/container-id
|
||||
[state class {:keys [current-page? sidebar?]}]
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
[frontend.components.file-based.hierarchy :as hierarchy]
|
||||
[frontend.components.objects :as objects]
|
||||
[frontend.components.plugins :as plugins]
|
||||
[frontend.components.property.config :as property-config]
|
||||
[frontend.components.query :as query]
|
||||
[frontend.components.reference :as reference]
|
||||
[frontend.components.scheduled-deadlines :as scheduled]
|
||||
@@ -438,9 +439,24 @@
|
||||
:size :sm
|
||||
:class "px-2 py-0 h-6 text-xs text-muted-foreground"
|
||||
:on-click (fn [e]
|
||||
(state/pub-event! [:editor/new-property {:block page
|
||||
:target (.-target e)}]))}
|
||||
"Set property")]])
|
||||
(if (ldb/property? page)
|
||||
(shui/popup-show!
|
||||
(.-target e)
|
||||
(fn []
|
||||
[:div.ls-property-dropdown
|
||||
(property-config/property-dropdown page nil {})])
|
||||
{:align :center})
|
||||
(let [opts (cond-> {:block page :target (.-target e)}
|
||||
(ldb/class? page)
|
||||
(assoc :class-schema? true))]
|
||||
(state/pub-event! [:editor/new-property opts]))))}
|
||||
(cond
|
||||
(ldb/class? page)
|
||||
"Add tag property"
|
||||
(ldb/property? page)
|
||||
"Configure"
|
||||
:else
|
||||
"Set property"))]])
|
||||
|
||||
(rum/defc db-page-title
|
||||
[page whiteboard-page? sidebar? container-id]
|
||||
@@ -558,7 +574,7 @@
|
||||
(shui/tabs
|
||||
{:defaultValue default-tab
|
||||
:class "w-full"}
|
||||
(when (or both? property?)
|
||||
(when both?
|
||||
[:div.flex.flex-row.gap-1.items-center
|
||||
(shui/tabs-list
|
||||
{:class "h-8"}
|
||||
|
||||
@@ -148,22 +148,19 @@
|
||||
[:span "Changing the property type clears some property configurations."]))]))
|
||||
|
||||
(rum/defc property-select
|
||||
[exclude-properties select-opts]
|
||||
[select-opts]
|
||||
(let [[properties set-properties!] (rum/use-state nil)
|
||||
[classes set-classes!] (rum/use-state nil)
|
||||
[excluded-properties set-excluded-properties!] (rum/use-state nil)]
|
||||
[classes set-classes!] (rum/use-state nil)]
|
||||
(hooks/use-effect!
|
||||
(fn []
|
||||
(p/let [repo (state/get-current-repo)
|
||||
properties (db-async/db-based-get-all-properties repo)
|
||||
properties (if (:class-schema? select-opts)
|
||||
(property-handler/get-class-property-choices)
|
||||
(db-model/get-all-properties repo {:remove-ui-non-suitable-properties? true}))
|
||||
classes (->> (db-model/get-all-classes repo)
|
||||
(remove ldb/built-in?))]
|
||||
(set-classes! classes)
|
||||
(set-properties! (remove exclude-properties properties))
|
||||
(set-excluded-properties! (->> properties
|
||||
(filter exclude-properties)
|
||||
(map :block/title)
|
||||
set))))
|
||||
(set-properties! properties)))
|
||||
[])
|
||||
(let [items (->>
|
||||
(concat
|
||||
@@ -186,7 +183,7 @@
|
||||
:close-modal? false
|
||||
:new-case-sensitive? true
|
||||
:show-new-when-not-exact-match? true
|
||||
:exact-match-exclude-items (fn [s] (contains? excluded-properties s))
|
||||
;; :exact-match-exclude-items (fn [s] (contains? excluded-properties s))
|
||||
:input-default-placeholder "Add or change property"}
|
||||
select-opts))]])))
|
||||
|
||||
@@ -270,7 +267,8 @@
|
||||
(shui/trigger-as
|
||||
:a
|
||||
{:tabIndex 0
|
||||
:title (:block/title property)
|
||||
:title (or (:block/title (:logseq.property/description property))
|
||||
(:block/title property))
|
||||
:class "property-k flex select-none jtrigger w-full"
|
||||
:on-pointer-down (fn [^js e]
|
||||
(when (util/meta-key? e)
|
||||
@@ -367,22 +365,6 @@
|
||||
*show-new-property-config? (::show-new-property-config? state)
|
||||
*show-class-select? (::show-class-select? state)
|
||||
*property-schema (::property-schema state)
|
||||
page? (entity-util/page? block)
|
||||
block-types (let [types (ldb/get-entity-types block)]
|
||||
(cond-> types
|
||||
(and page? (not (contains? types :page)))
|
||||
(conj :page)
|
||||
(empty? types)
|
||||
(conj :block)))
|
||||
exclude-properties (fn [m]
|
||||
(let [view-context (get m :logseq.property/view-context :all)]
|
||||
(or (contains? #{:logseq.property/query} (:db/ident m))
|
||||
(and (not page?) (contains? #{:block/alias} (:db/ident m)))
|
||||
;; Filters out properties from being in wrong :view-context and :never view-contexts
|
||||
(and (not= view-context :all) (not (contains? block-types view-context)))
|
||||
(and (ldb/built-in? block) (contains? #{:logseq.property/parent} (:db/ident m)))
|
||||
;; Filters out adding buggy class properties e.g. Alias and Parent
|
||||
(and class-schema? (ldb/public-built-in-property? m) (:logseq.property/view-context m)))))
|
||||
property (rum/react *property)
|
||||
property-key (rum/react *property-key)
|
||||
batch? (pv/batch-operation?)
|
||||
@@ -405,7 +387,7 @@
|
||||
[:div.flex.flex-row {:on-pointer-down (fn [e] (util/stop-propagation e))}
|
||||
(when (not= @*show-new-property-config? :adding-property)
|
||||
(cond
|
||||
@*show-new-property-config?
|
||||
(or (nil? property) @*show-new-property-config?)
|
||||
(property-type-select property (merge opts
|
||||
{:*property *property
|
||||
:*property-name *property-key
|
||||
@@ -434,9 +416,9 @@
|
||||
(= "" (.-value (.-target e))))
|
||||
(util/stop e)
|
||||
(shui/popup-hide!)))}]
|
||||
(property-select exclude-properties
|
||||
(merge (:select-opts opts) {:on-chosen on-chosen
|
||||
:input-opts input-opts}))))]))
|
||||
(property-select (merge (:select-opts opts) {:on-chosen on-chosen
|
||||
:input-opts input-opts
|
||||
:class-schema? class-schema?}))))]))
|
||||
|
||||
(rum/defcs new-property < rum/reactive
|
||||
[state block opts]
|
||||
@@ -491,8 +473,6 @@
|
||||
:page-cp page-cp))]
|
||||
[:div {:key (str "property-pair-" (:db/id block) "-" (:db/id property))
|
||||
:class (cond
|
||||
(= (:db/ident property) :logseq.property.class/properties)
|
||||
"property-pair !flex !flex-col"
|
||||
(or date? datetime? checkbox?)
|
||||
"property-pair items-center"
|
||||
:else
|
||||
@@ -501,21 +481,14 @@
|
||||
(dnd/sortable-item (assoc sortable-opts :class "property-key") property-key-cp')
|
||||
[:div.property-key property-key-cp'])
|
||||
|
||||
(let [class-properties? (= (:db/ident property) :logseq.property.class/properties)
|
||||
property-desc (when-not (= (:db/ident property) :logseq.property/description)
|
||||
(let [property-desc (when-not (= (:db/ident property) :logseq.property/description)
|
||||
(:logseq.property/description property))]
|
||||
[:div.ls-block.property-value-container.flex.flex-row.gap-1.items-center
|
||||
(cond-> {}
|
||||
class-properties? (assoc :class (if (:logseq.property.class/properties block)
|
||||
"ml-2 -mt-1"
|
||||
"-ml-1")))
|
||||
(when-not (or block? class-properties? (and property-desc (:class-schema? opts)))
|
||||
(when-not (or block? (and property-desc (:class-schema? opts)))
|
||||
[:div {:class "pl-1.5 -mr-[3px] opacity-60"}
|
||||
[:span.bullet-container [:span.bullet]]])
|
||||
[:div.flex.flex-1
|
||||
[:div.property-value.flex.flex-1
|
||||
(cond-> {}
|
||||
class-properties? (assoc :class :opacity-90))
|
||||
(if (:class-schema? opts)
|
||||
(pv/property-value property (db/entity :logseq.property/description) opts)
|
||||
(pv/property-value block property opts))]]])]))))
|
||||
@@ -592,7 +565,6 @@
|
||||
(and show?
|
||||
(or (= mode :global)
|
||||
(and (set? ids) (contains? ids (:block/uuid block))))))
|
||||
class? (ldb/class? block)
|
||||
properties (:block/properties block)
|
||||
remove-built-in-or-other-position-properties
|
||||
(fn [properties]
|
||||
@@ -666,11 +638,12 @@
|
||||
(into result cur-properties)
|
||||
result)))
|
||||
result))
|
||||
full-properties (->> (concat block-own-properties'
|
||||
(map (fn [p] [p (get block p)]) class-properties)
|
||||
(when (and class? (nil? (:logseq.property.class/properties block)))
|
||||
[[:logseq.property.class/properties nil]]))
|
||||
remove-built-in-or-other-position-properties)]
|
||||
full-properties (cond->
|
||||
(->> (concat block-own-properties'
|
||||
(map (fn [p] [p (get block p)]) class-properties))
|
||||
remove-built-in-or-other-position-properties)
|
||||
(and (ldb/class? block) (empty? (:logseq.property.class/properties block)))
|
||||
(concat [[:logseq.property.class/properties nil]]))]
|
||||
(cond
|
||||
(empty? full-properties)
|
||||
(when sidebar-properties?
|
||||
@@ -678,28 +651,15 @@
|
||||
|
||||
:else
|
||||
(let [remove-properties #{:logseq.property/icon :logseq.property/query}
|
||||
properties' (remove (fn [[k _v]] (contains? remove-properties k)) full-properties)
|
||||
properties'' (->> properties'
|
||||
(remove (fn [[k _v]] (= k :logseq.property.class/properties))))
|
||||
properties' (remove (fn [[k _v]] (contains? remove-properties k))
|
||||
full-properties)
|
||||
page? (entity-util/page? block)]
|
||||
[:div.ls-properties-area
|
||||
{:id id
|
||||
:class (util/classnames [{:ls-page-properties page?}])
|
||||
:tab-index 0}
|
||||
[:<>
|
||||
(properties-section block properties'' opts)
|
||||
(properties-section block properties' opts)
|
||||
|
||||
(when (and page? (not class?))
|
||||
(rum/with-key (new-property block opts) (str id "-add-property")))]
|
||||
|
||||
(when class?
|
||||
(let [properties (->> (:logseq.property.class/properties block)
|
||||
(map (fn [e] [(:db/ident e)])))
|
||||
opts' (assoc opts :class-schema? true)]
|
||||
[:<>
|
||||
[:div.mt-2
|
||||
[:div.text-sm.text-muted-foreground.mb-2 {:style {:margin-left 10}}
|
||||
"Tag Properties:"]
|
||||
[:div
|
||||
(properties-section block properties opts')
|
||||
(rum/with-key (new-property block opts') (str id "-class-add-property"))]]]))]))))
|
||||
(when page?
|
||||
(rum/with-key (new-property block opts) (str id "-add-property")))]]))))
|
||||
|
||||
@@ -679,7 +679,7 @@
|
||||
|
||||
(rum/defc ^:large-vars/cleanup-todo select-node < rum/static
|
||||
[property
|
||||
{:keys [block multiple-choices? dropdown? input-opts on-input add-new-choice!] :as opts}
|
||||
{:keys [block multiple-choices? dropdown? input-opts on-input add-new-choice! target] :as opts}
|
||||
result]
|
||||
(let [repo (state/get-current-repo)
|
||||
classes (:logseq.property/classes property)
|
||||
@@ -695,9 +695,6 @@
|
||||
parent-property? (= (:db/ident property) :logseq.property/parent)
|
||||
children-pages (when parent-property? (model/get-structured-children repo (:db/id block)))
|
||||
property-type (:logseq.property/type property)
|
||||
get-all-classes-f (fn []
|
||||
(model/get-all-classes repo {:except-root-class? true
|
||||
:except-private-tags? (not (contains? #{:logseq.property/template-applied-to} (:db/ident property)))}))
|
||||
nodes (cond
|
||||
parent-property?
|
||||
(let [;; Disallows cyclic hierarchies
|
||||
@@ -709,8 +706,14 @@
|
||||
excluded-options (remove (fn [e] (contains? exclude-ids (:block/uuid e))) options)]
|
||||
excluded-options)
|
||||
|
||||
(= property-type :class)
|
||||
(get-all-classes-f)
|
||||
(contains? #{:class :property} property-type)
|
||||
(let [classes (model/get-all-classes
|
||||
repo
|
||||
{:except-root-class? true
|
||||
:except-private-tags? (not (contains? #{:logseq.property/template-applied-to} (:db/ident property)))})]
|
||||
(if (= property-type :class)
|
||||
classes
|
||||
(property-handler/get-class-property-choices)))
|
||||
|
||||
(seq classes)
|
||||
(->>
|
||||
@@ -766,7 +769,7 @@
|
||||
(breadcrumb {:search? true} (state/get-current-repo) (:block/uuid node) {})]))
|
||||
label [:div.flex.flex-row.items-center.gap-1
|
||||
(when-not (or (:logseq.property/classes property)
|
||||
(= (:db/ident property) :block/tags))
|
||||
(contains? #{:class :property} (:logseq.property/type property)))
|
||||
(ui/icon icon {:size 14}))
|
||||
[:div title]]]
|
||||
[header label])
|
||||
@@ -806,10 +809,18 @@
|
||||
:input-opts input-opts
|
||||
:on-input (debounce on-input 50)
|
||||
:on-chosen (fn [chosen selected?]
|
||||
(p/let [id (if (integer? chosen)
|
||||
(p/let [add-tag-property? (and (= (:db/ident property) :logseq.property.class/properties) (not (integer? chosen)))
|
||||
id (if (integer? chosen)
|
||||
chosen
|
||||
(when-not (string/blank? (string/trim chosen))
|
||||
(<create-page-if-not-exists! block property classes' chosen)))
|
||||
(if (= (:db/ident property) :logseq.property.class/properties)
|
||||
(do
|
||||
(shui/popup-hide!)
|
||||
(state/pub-event! [:editor/new-property {:block block
|
||||
:class-schema? true
|
||||
:property-key chosen
|
||||
:target target}]))
|
||||
(<create-page-if-not-exists! block property classes' chosen))))
|
||||
_ (when (and (integer? id) (not (entity-util/page? (db/entity id))))
|
||||
(db-async/<get-block repo id))]
|
||||
(if id
|
||||
@@ -820,7 +831,8 @@
|
||||
(let [e (db/entity id)]
|
||||
{:value (select-keys e [:db/id :block/uuid])
|
||||
:label (:block/title e)}))))
|
||||
(log/error :msg "No :db/id found or created for chosen" :chosen chosen))))})
|
||||
(when-not add-tag-property?
|
||||
(log/error :msg "No :db/id found or created for chosen" :chosen chosen)))))})
|
||||
|
||||
(and (seq classes') (not tags-or-alias?))
|
||||
(assoc
|
||||
@@ -1144,17 +1156,17 @@
|
||||
editing? (:editing? opts)
|
||||
type (:logseq.property/type property)
|
||||
select-opts' (assoc select-opts :multiple-choices? false)
|
||||
popup-content (fn content-fn [_]
|
||||
popup-content (fn content-fn [target]
|
||||
[:div.property-select
|
||||
(case type
|
||||
(:entity :number :default :url)
|
||||
(select block property select-opts' opts)
|
||||
|
||||
(:node :class :property :page :date)
|
||||
(property-value-select-node block property select-opts' opts))])
|
||||
(property-value-select-node block property select-opts' (assoc opts :target target)))])
|
||||
trigger-id (str "trigger-" (:container-id opts) "-" (:db/id block) "-" (:db/id property))
|
||||
show-popup! (fn [target]
|
||||
(shui/popup-show! target popup-content
|
||||
(shui/popup-show! target (fn [] (popup-content target))
|
||||
{:align "start"
|
||||
:as-dropdown? true
|
||||
:auto-focus? true
|
||||
@@ -1368,7 +1380,7 @@
|
||||
items (cond->> (if (entity-map? v) #{v} v)
|
||||
(= (:db/ident property) :block/tags)
|
||||
(remove (fn [v] (contains? ldb/hidden-tags (:db/ident v)))))
|
||||
select-cp (fn [select-opts]
|
||||
select-cp (fn [select-opts target]
|
||||
(let [select-opts (merge {:multiple-choices? true
|
||||
:on-chosen (fn []
|
||||
(when on-chosen (on-chosen)))}
|
||||
@@ -1378,18 +1390,20 @@
|
||||
[:div.property-select
|
||||
(if (contains? #{:node :page :class :property} type)
|
||||
(property-value-select-node block property
|
||||
select-opts
|
||||
(assoc select-opts :target target)
|
||||
opts)
|
||||
(select block property select-opts opts))]))]
|
||||
(if editing?
|
||||
(select-cp {})
|
||||
(select-cp {} nil)
|
||||
(let [toggle-fn shui/popup-hide!
|
||||
content-fn (fn [{:keys [_id content-props]}]
|
||||
(select-cp {:content-props content-props}))
|
||||
content-fn (fn [{:keys [_id content-props]} target]
|
||||
(select-cp {:content-props content-props} target))
|
||||
show-popup! (fn [^js e]
|
||||
(let [target (.-target e)]
|
||||
(when-not (or (util/link? target) (.closest target "a") config/publishing?)
|
||||
(shui/popup-show! (rum/deref *el) content-fn
|
||||
(shui/popup-show! (rum/deref *el)
|
||||
(fn [opts]
|
||||
(content-fn opts target))
|
||||
{:as-dropdown? true :as-content? false
|
||||
:align "start" :auto-focus? true}))))]
|
||||
[:div.multi-values.jtrigger
|
||||
@@ -1432,7 +1446,6 @@
|
||||
(ui/catch-error
|
||||
(ui/block-error "Something wrong" {})
|
||||
(let [block-cp (state/get-component :block/blocks-container)
|
||||
properties-cp (state/get-component :block/properties-cp)
|
||||
opts (merge opts
|
||||
{:page-cp (state/get-component :block/page-cp)
|
||||
:inline-text (state/get-component :block/inline-text)
|
||||
@@ -1486,10 +1499,6 @@
|
||||
:class (str (when empty-value? "empty-value")
|
||||
(when-not (:other-position? opts) " w-full"))}
|
||||
(cond
|
||||
(= property-ident :logseq.property.class/properties)
|
||||
(properties-cp {} block {:selected? false
|
||||
:class-schema? true})
|
||||
|
||||
(and multiple-values? (contains? #{:default :url} type) (not closed-values?) (not editing?))
|
||||
(property-normal-block-value block property v opts)
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.query.builder :as query-builder]
|
||||
[frontend.mixins :as mixins]
|
||||
[frontend.util.ref :as ref]
|
||||
[frontend.state :as state]
|
||||
[frontend.ui :as ui]
|
||||
[frontend.util :as util]
|
||||
[frontend.util.ref :as ref]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[logseq.db :as ldb]
|
||||
@@ -91,43 +91,38 @@
|
||||
{:will-unmount (fn [state]
|
||||
(swap! *between-dates dissoc (first (:rum/args state)))
|
||||
state)}
|
||||
[state id placeholder {:keys [auto-focus on-select]}]
|
||||
[state id placeholder {:keys [on-select]}]
|
||||
(let [*input-value (::input-value state)]
|
||||
[:div.ml-4
|
||||
[:input.query-builder-datepicker.form-input.block.sm:text-sm.sm:leading-5
|
||||
{:auto-focus (or auto-focus false)
|
||||
:data-key (name id)
|
||||
:placeholder placeholder
|
||||
:aria-label placeholder
|
||||
:value (some-> @*input-value (first))
|
||||
:on-focus (fn [^js e]
|
||||
(js/setTimeout
|
||||
#(shui/popup-show! (.-target e)
|
||||
(let [select-handle! (fn [^js d]
|
||||
(let [gd (date/js-date->goog-date d)
|
||||
journal-date (date/js-date->journal-title gd)]
|
||||
(reset! *input-value [journal-date d])
|
||||
(swap! *between-dates assoc id journal-date))
|
||||
(some-> on-select (apply []))
|
||||
(shui/popup-hide!))]
|
||||
(ui/single-calendar
|
||||
{:initial-focus true
|
||||
:selected (some-> @*input-value (second))
|
||||
:on-select select-handle!}))
|
||||
{:id :query-datepicker
|
||||
:content-props {:class "p-0"}
|
||||
:align :start}) 16))}]]))
|
||||
(shui/button
|
||||
{:variant :secondary
|
||||
:size :sm
|
||||
:on-click (fn [^js e]
|
||||
(shui/popup-show! (.-target e)
|
||||
(let [select-handle! (fn [^js d]
|
||||
(let [gd (date/js-date->goog-date d)
|
||||
journal-date (date/js-date->journal-title gd)]
|
||||
(reset! *input-value [journal-date d])
|
||||
(swap! *between-dates assoc id journal-date))
|
||||
(some-> on-select (apply []))
|
||||
(shui/popup-hide!))]
|
||||
(ui/single-calendar
|
||||
{:initial-focus false
|
||||
:selected (some-> @*input-value (second))
|
||||
:on-select select-handle!}))
|
||||
{:id :query-datepicker
|
||||
:content-props {:class "p-0"}
|
||||
:align :start}))}
|
||||
(or (first @*input-value) placeholder))))
|
||||
|
||||
(rum/defcs between <
|
||||
(rum/local nil ::start)
|
||||
(rum/local nil ::end)
|
||||
[state {:keys [tree loc] :as opts}]
|
||||
[:div.between-date.p-4 {:on-pointer-down (fn [e] (util/stop-propagation e))}
|
||||
[:div.flex.flex-row
|
||||
[:div.font-medium.mt-2 "Between: "]
|
||||
[:div.flex.flex-row.items-center.gap-2
|
||||
[:div.font-medium "Between: "]
|
||||
(datepicker :start "Start date"
|
||||
(merge opts {:auto-focus true
|
||||
:on-select (fn []
|
||||
(merge opts {:on-select (fn []
|
||||
(when-let [^js end-input (js/document.querySelector ".query-builder-datepicker[data-key=end]")]
|
||||
(when (string/blank? (.-value end-input))
|
||||
(.focus end-input))))}))
|
||||
@@ -506,9 +501,13 @@
|
||||
(symbol? end))
|
||||
(name end)
|
||||
(second end))]
|
||||
(str (if (= k :block/created-at)
|
||||
(str (cond
|
||||
(= k :block/created-at)
|
||||
"Created"
|
||||
"Updated")
|
||||
(= k :block/updated-at)
|
||||
"Updated"
|
||||
:else
|
||||
(or (:block/title (db/entity k)) (name k)))
|
||||
" " start
|
||||
(when end
|
||||
(str " ~ " end))))
|
||||
|
||||
@@ -695,7 +695,7 @@
|
||||
{:id "add property"
|
||||
:prop {:style {:width "-webkit-fill-available"
|
||||
:min-width 160}
|
||||
:on-click (fn [] (when (fn? add-property!) (add-property!)))}
|
||||
:on-click (fn [e] (when (fn? add-property!) (add-property! e)))}
|
||||
:value :add-new-property
|
||||
:content (add-property-button)
|
||||
:disabled? true})
|
||||
|
||||
@@ -9,16 +9,14 @@
|
||||
[frontend.db :as db]
|
||||
[frontend.db.async.util :as db-async-util]
|
||||
[frontend.db.file-based.async :as file-async]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.db.file-based.model :as file-model]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.db.utils :as db-utils]
|
||||
[frontend.handler.file-based.property.util :as property-util]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def <q db-async-util/<q)
|
||||
@@ -54,28 +52,6 @@
|
||||
(p/let [templates (<get-all-templates repo)]
|
||||
(get templates name))))
|
||||
|
||||
(defn db-based-get-all-properties
|
||||
"Return seq of all property names except for private built-in properties."
|
||||
[graph & {:keys [remove-built-in-property? remove-non-queryable-built-in-property?]
|
||||
:or {remove-built-in-property? true
|
||||
remove-non-queryable-built-in-property? false}}]
|
||||
(let [result (->> (d/datoms (db/get-db graph) :avet :block/tags :logseq.class/Property)
|
||||
(map (fn [datom] (db/entity (:e datom))))
|
||||
(sort-by (juxt ldb/built-in? :block/title)))]
|
||||
(cond->> result
|
||||
remove-built-in-property?
|
||||
;; remove private built-in properties
|
||||
(remove (fn [p]
|
||||
(let [ident (:db/ident p)]
|
||||
(and (ldb/built-in? p)
|
||||
(not (ldb/public-built-in-property? p))
|
||||
(not= ident :logseq.property/icon)))))
|
||||
remove-non-queryable-built-in-property?
|
||||
(remove (fn [p]
|
||||
(let [ident (:db/ident p)]
|
||||
(and (ldb/built-in? p)
|
||||
(not (:queryable? (db-property/built-in-properties ident))))))))))
|
||||
|
||||
(defn <get-all-properties
|
||||
"Returns all public properties as property maps including their
|
||||
:block/title and :db/ident. For file graphs the map only contains
|
||||
@@ -83,7 +59,7 @@
|
||||
[& {:as opts}]
|
||||
(when-let [graph (state/get-current-repo)]
|
||||
(if (config/db-based-graph? graph)
|
||||
(db-based-get-all-properties graph opts)
|
||||
(db-model/get-all-properties graph opts)
|
||||
(p/let [properties (file-async/<file-based-get-all-properties graph)
|
||||
hidden-properties (set (map name (property-util/hidden-properties)))]
|
||||
(remove #(hidden-properties (:block/title %)) properties)))))
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.frontend.class :as db-class]
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.frontend.rules :as rules]))
|
||||
|
||||
;; TODO: extract to specific models and move data transform logic to the
|
||||
@@ -529,6 +530,52 @@ independent of format as format specific heading characters are stripped"
|
||||
(keep (fn [e] (when-not (= :logseq.class/Root (:db/ident e)) e)) classes)
|
||||
classes)))
|
||||
|
||||
(defn ui-non-suitable-property?
|
||||
[block m {:keys [class-schema?]}]
|
||||
(when block
|
||||
(let [block-page? (ldb/page? block)
|
||||
block-types (let [types (ldb/get-entity-types block)]
|
||||
(cond-> types
|
||||
(and block-page? (not (contains? types :page)))
|
||||
(conj :page)
|
||||
(empty? types)
|
||||
(conj :block)))
|
||||
view-context (get m :logseq.property/view-context :all)]
|
||||
(or (contains? #{:logseq.property/query} (:db/ident m))
|
||||
(and (not block-page?) (contains? #{:block/alias} (:db/ident m)))
|
||||
;; Filters out properties from being in wrong :view-context and :never view-contexts
|
||||
(and (not= view-context :all) (not (contains? block-types view-context)))
|
||||
(and (ldb/built-in? block) (contains? #{:logseq.property/parent} (:db/ident m)))
|
||||
;; Filters out adding buggy class properties e.g. Alias and Parent
|
||||
(and class-schema? (ldb/public-built-in-property? m) (:logseq.property/view-context m))))))
|
||||
|
||||
(defn get-all-properties
|
||||
"Return seq of all property names except for private built-in properties."
|
||||
[graph & {:keys [remove-built-in-property? remove-non-queryable-built-in-property? remove-ui-non-suitable-properties?
|
||||
class-schema? block]
|
||||
:or {remove-built-in-property? true
|
||||
remove-non-queryable-built-in-property? false
|
||||
remove-ui-non-suitable-properties? false}}]
|
||||
(let [db (conn/get-db graph)
|
||||
result (sort-by (juxt ldb/built-in? :block/title)
|
||||
(ldb/get-all-properties db))]
|
||||
(cond->> result
|
||||
remove-built-in-property?
|
||||
;; remove private built-in properties
|
||||
(remove (fn [p]
|
||||
(let [ident (:db/ident p)]
|
||||
(and (ldb/built-in? p)
|
||||
(not (ldb/public-built-in-property? p))
|
||||
(not= ident :logseq.property/icon)))))
|
||||
remove-non-queryable-built-in-property?
|
||||
(remove (fn [p]
|
||||
(let [ident (:db/ident p)]
|
||||
(and (ldb/built-in? p)
|
||||
(not (:queryable? (db-property/built-in-properties ident)))))))
|
||||
remove-ui-non-suitable-properties?
|
||||
(remove (fn [p]
|
||||
(ui-non-suitable-property? block p {:class-schema? class-schema?}))))))
|
||||
|
||||
(defn get-all-readable-classes
|
||||
"Gets all classes that are used in a read only context e.g. querying or used
|
||||
for property value selection. This should _not_ be used in a write context e.g.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[logseq.db.file-based.rules :as file-rules]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.graph-parser.text :as text]))
|
||||
|
||||
@@ -208,25 +209,30 @@
|
||||
;; ===============
|
||||
(defn- resolve-timestamp-property
|
||||
[e]
|
||||
(let [k' (second e)]
|
||||
(when (or (keyword? k') (symbol? k') (string? k'))
|
||||
(let [k (-> k'
|
||||
(name)
|
||||
(string/lower-case)
|
||||
(string/replace "_" "-")
|
||||
keyword)]
|
||||
(case k
|
||||
:created-at
|
||||
:block/created-at
|
||||
:updated-at
|
||||
:block/updated-at
|
||||
k)))))
|
||||
(let [k (second e)]
|
||||
(when (or (keyword? k) (symbol? k) (string? k))
|
||||
(let [k' (-> k
|
||||
(name)
|
||||
(string/lower-case)
|
||||
(string/replace "_" "-")
|
||||
keyword)]
|
||||
(if (and (config/db-based-graph?) (db-property/property? k'))
|
||||
k'
|
||||
(case k'
|
||||
:created-at
|
||||
:block/created-at
|
||||
:updated-at
|
||||
:block/updated-at
|
||||
nil))))))
|
||||
|
||||
(defn get-timestamp-property
|
||||
[e]
|
||||
(let [k (resolve-timestamp-property e)]
|
||||
(when (contains? #{:block/created-at :block/updated-at} k)
|
||||
k)))
|
||||
(when-let [k (resolve-timestamp-property e)]
|
||||
(if (config/db-based-graph?)
|
||||
(when (keyword? k)
|
||||
k)
|
||||
(when (contains? #{:block/created-at :block/updated-at} k)
|
||||
k))))
|
||||
|
||||
(defn- build-journal-between-two-arg
|
||||
[e]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns frontend.handler.property
|
||||
"Property fns for both file and DB graphs"
|
||||
(:require [frontend.config :as config]
|
||||
[frontend.db.model :as db-model]
|
||||
[frontend.handler.db-based.property :as db-property-handler]
|
||||
[frontend.handler.file-based.page-property :as file-page-property]
|
||||
[frontend.handler.file-based.property :as file-property-handler]
|
||||
@@ -66,3 +67,20 @@
|
||||
(assert (uuid? block-id))
|
||||
(when (config/db-based-graph? repo)
|
||||
(db-property-handler/set-block-properties! block-id properties)))
|
||||
|
||||
(defonce class-property-excludes
|
||||
#{:logseq.property.class/properties :block/tags
|
||||
:logseq.property/icon :block/alias :logseq.property/enable-history?
|
||||
:logseq.property/exclude-from-graph-view :logseq.property/template-applied-to
|
||||
:logseq.property/hide-empty-value :logseq.property.class/hide-from-node
|
||||
:logseq.property/page-tags :logseq.property/parent
|
||||
:logseq.property/publishing-public? :logseq.property.user/avatar
|
||||
:logseq.property.user/email :logseq.property.user/name})
|
||||
|
||||
(defn get-class-property-choices
|
||||
[]
|
||||
(->>
|
||||
(db-model/get-all-properties (state/get-current-repo)
|
||||
{:remove-ui-non-suitable-properties? true})
|
||||
(remove (fn [p]
|
||||
(contains? class-property-excludes (:db/ident p))))))
|
||||
|
||||
Reference in New Issue
Block a user