diff --git a/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs b/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs index e6dbe147e5..4970e0f993 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs +++ b/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs @@ -41,8 +41,6 @@ :blocks [{:block/content "default property block" :properties {:default "haha"}} {:block/content "url property block" :properties {:url "https://logseq.com"}} - ;; TODO: Add a default many example with blocks - #_{:block/content "default-many property block" :properties {:default-many #{"woo" "hoo"}}} {:block/content "url-many property block" :properties {:url-many #{"https://logseq.com" "https://docs.logseq.com"}}} {:block/content "checkbox property block" :properties {:checkbox true}} {:block/content "number property block" :properties {:number 5}} @@ -56,13 +54,14 @@ :blocks [{:block/content "{{query (property :default \"haha\")}}"} {:block/content "{{query (property :url \"https://logseq.com\")}}"} - #_{:block/content "{{query (property :default-many \"woo\")}}"} {:block/content "{{query (property :url-many \"https://logseq.com\")}}"} {:block/content "{{query (property :checkbox true)}}"} {:block/content "{{query (property :number 5)}}"} {:block/content "{{query (property :number-many 10)}}"} - {:block/content "{{query (property :page \"Page 1\")}}"} - {:block/content "{{query (property :page-many \"Page 2\")}}"}]} + {:block/content "{{query (property :page [[Page 1]])}}"} + {:block/content "{{query (property :page-many [[Page 2]])}}"} + {:block/content (str "{{query (property :date [[" (string/capitalize (date-journal-title today)) "]])}}")} + {:block/content (str "{{query (property :date-many [[" (string/capitalize (date-journal-title yesterday)) "]])}}")}]} {:page {:block/name "page 1"} :blocks [{:block/content "yee"} diff --git a/src/main/frontend/components/query/builder.cljs b/src/main/frontend/components/query/builder.cljs index 7ac1a454a6..b080969593 100644 --- a/src/main/frontend/components/query/builder.cljs +++ b/src/main/frontend/components/query/builder.cljs @@ -1,7 +1,8 @@ (ns frontend.components.query.builder "DSL query builder." - (:require [frontend.ui :as ui] + (:require [frontend.config :as config] [frontend.date :as date] + [frontend.ui :as ui] [frontend.db :as db] [frontend.db.model :as db-model] [frontend.db.query-dsl :as query-dsl] @@ -146,7 +147,9 @@ (reset! *property (keyword value))))) "property-value" - (let [values (cons "Select all" (db-model/get-property-values @*property))] + (let [values (cons "Select all" (if (config/db-based-graph? repo) + (db-model/get-db-property-values repo @*property) + (db-model/get-property-values @*property)))] (select values (fn [{:keys [value]}] (let [x (if (= value "Select all") diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index 3a42e62c7b..840f1e4888 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -92,7 +92,7 @@ (d/q '[:find ?page-name ?tag :where [?page :block/tags ?e] - [?e :block/name ?tag] + [?e :block/original-name ?tag] [?page :block/name ?page-name]] (conn/get-db repo))) @@ -102,7 +102,7 @@ :where [?page :block/name ?page-name] [?page :block/namespace ?e] - [?e :block/name ?parent]] + [?e :block/original-name ?parent]] (conn/get-db repo))) (defn get-all-namespace-parents @@ -1204,7 +1204,6 @@ independent of format as format specific heading characters are stripped" %) refs))) -;; FIXME: property values for db version (defn get-property-values [property] (let [pred (fn [_db properties text-properties] @@ -1228,6 +1227,43 @@ independent of format as format specific heading characters are stripped" (distinct) (sort)))) +(defn get-db-property-values + "Returns all property values of a given property for use in a simple query. + Property values that are references are displayed as page references" + [repo property] + (->> (d/q + '[:find ?prop-type ?v + :in $ ?prop-name + :where + [?b :block/properties ?bp] + [?prop-b :block/name ?prop-name] + [?prop-b :block/uuid ?prop-uuid] + [?prop-b :block/schema ?prop-schema] + [(get ?prop-schema :type) ?prop-type] + [(get ?bp ?prop-uuid) ?v]] + (conn/get-db repo) + (name property)) + (map (fn [[prop-type v]] [prop-type (if (coll? v) v [v])])) + (mapcat (fn [[prop-type vals]] + (case prop-type + :enum + (map #(:block/content (db-utils/entity repo [:block/uuid %])) vals) + :default + ;; Remove multi-block properties as there isn't a supported approach to query them yet + (map str (remove uuid? vals)) + (:page :date) + (map #(page-ref/->page-ref (:block/original-name (db-utils/entity repo [:block/uuid %]))) + vals) + :number + vals + ;; Checkboxes returned as strings as builder doesn't display boolean values correctly + (map str vals)))) + ;; Remove blanks as they match on everything + (remove string/blank?) + (distinct) + (sort))) + + (defn get-block-property-values "Get blocks which have this property." [property-uuid] diff --git a/src/main/frontend/handler/graph.cljs b/src/main/frontend/handler/graph.cljs index 2180197a63..ab02a2dfa4 100644 --- a/src/main/frontend/handler/graph.cljs +++ b/src/main/frontend/handler/graph.cljs @@ -7,7 +7,8 @@ [frontend.state :as state] [frontend.util :as util] [frontend.handler.property.util :as pu] - [frontend.config :as config])) + [frontend.config :as config] + [logseq.graph-parser.util :as gp-util])) (defn- build-links [links] @@ -89,8 +90,8 @@ current-page (or (:block/name (db/get-current-page)) "")] (when-let [repo (state/get-current-repo)] (let [relation (db/get-pages-relation repo journal?) - tagged-pages (db/get-all-tagged-pages repo) - namespaces (db/get-all-namespace-relation repo) + tagged-pages (map (fn [[x y]] [x (gp-util/page-name-sanity-lc y)]) (db/get-all-tagged-pages repo)) + namespaces (map (fn [[x y]] [x (gp-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) tags (set (map second tagged-pages)) full-pages (db/get-all-pages repo) full-pages-map (into {} (map (juxt :block/name identity) full-pages)) @@ -143,7 +144,7 @@ tags (remove #(= page %) tags) ref-pages (db/get-page-referenced-pages repo page) mentioned-pages (db/get-pages-that-mentioned-page repo page show-journal) - namespaces (db/get-all-namespace-relation repo) + namespaces (map (fn [[x y]] [x (gp-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) links (concat namespaces (map (fn [[p _aliases]] @@ -195,7 +196,7 @@ (let [dark? (= "dark" theme)] (when-let [repo (state/get-current-repo)] (let [ref-blocks (db/get-block-referenced-blocks block) - namespaces (db/get-all-namespace-relation repo) + namespaces (map (fn [[x y]] [x (gp-util/page-name-sanity-lc y)]) (db/get-all-namespace-relation repo)) links (concat (map (fn [[p _aliases]] [block p]) ref-blocks)