mirror of https://github.com/logseq/logseq
Remove more :block/name lookup ref usage
parent
50e3ef5157
commit
9df8918f94
|
@ -114,7 +114,7 @@
|
|||
|
||||
(defn get-page-blocks
|
||||
"Return blocks of the designated page, without using cache.
|
||||
page - name / title of the page"
|
||||
page-id - eid"
|
||||
[db page-id {:keys [pull-keys]
|
||||
:or {pull-keys '[*]}}]
|
||||
(when page-id
|
||||
|
@ -164,18 +164,20 @@
|
|||
(map first)
|
||||
(remove hidden-page?)))
|
||||
|
||||
(def get-first-page-by-name sqlite-common-db/get-first-page-by-name)
|
||||
|
||||
(defn page-exists?
|
||||
"Whether a page exists."
|
||||
[db page-name]
|
||||
(when page-name
|
||||
(d/entity db [:block/name (common-util/page-name-sanity-lc page-name)])))
|
||||
(some? (get-first-page-by-name db page-name))))
|
||||
|
||||
(defn page-empty?
|
||||
"Whether a page is empty. Does it has a non-page block?
|
||||
`page-id` could be either a string or a db/id."
|
||||
[db page-id]
|
||||
(let [page-id (if (string? page-id)
|
||||
[:block/name (common-util/page-name-sanity-lc page-id)]
|
||||
(get-first-page-by-name db page-id)
|
||||
page-id)
|
||||
page (d/entity db page-id)]
|
||||
(nil? (:block/_left page))))
|
||||
|
@ -190,8 +192,8 @@
|
|||
orphaned-pages (->>
|
||||
(map
|
||||
(fn [page]
|
||||
(let [name (common-util/page-name-sanity-lc page)]
|
||||
(when-let [page (d/entity db [:block/name name])]
|
||||
(when-let [page (d/entity db (get-first-page-by-name db page))]
|
||||
(let [name (:block/name page)]
|
||||
(and
|
||||
(empty-ref-f page)
|
||||
(or
|
||||
|
@ -397,14 +399,11 @@
|
|||
|
||||
(defn get-page
|
||||
"Get a page given its unsanitized name"
|
||||
[db page-name]
|
||||
(d/entity db [:block/name (common-util/page-name-sanity-lc (name page-name))]))
|
||||
|
||||
(defn get-page-uuid
|
||||
"Get a user page's uuid given its unsanitized name"
|
||||
;; Get a page's uuid given its unsanitized name
|
||||
[db page-name]
|
||||
(:block/uuid (get-page db page-name)))
|
||||
[db page-name-or-uuid]
|
||||
(if-let [id (if (uuid? page-name-or-uuid) page-name-or-uuid
|
||||
(parse-uuid page-name-or-uuid))]
|
||||
(d/entity db [:block/uuid id])
|
||||
(d/entity db (get-first-page-by-name db (name page-name-or-uuid)))))
|
||||
|
||||
(defn get-page-alias
|
||||
[db page-id]
|
||||
|
@ -501,8 +500,6 @@
|
|||
[db]
|
||||
(when db (:graph/uuid (d/entity db :logseq.kv/graph-uuid))))
|
||||
|
||||
(def get-first-page-by-name sqlite-common-db/get-first-page-by-name)
|
||||
|
||||
(defn page?
|
||||
[block]
|
||||
(and block
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
(d/datoms db :avet :block/name (common-util/page-name-sanity-lc page-name)))
|
||||
|
||||
(defn get-first-page-by-name
|
||||
"Return the oldest page"
|
||||
"Return the oldest page's db id"
|
||||
[db page-name]
|
||||
(first (sort (map :e (get-pages-by-name db page-name)))))
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
[logseq.common.util :as common-util]
|
||||
[logseq.common.util.block-ref :as block-ref]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[datascript.impl.entity :as de]))
|
||||
[datascript.impl.entity :as de]
|
||||
[logseq.db :as ldb]))
|
||||
|
||||
(defn heading-block?
|
||||
[block]
|
||||
|
@ -292,7 +293,7 @@
|
|||
(and original-page-name (string? original-page-name))
|
||||
(let [original-page-name (common-util/remove-boundary-slashes original-page-name)
|
||||
[original-page-name page-name journal-day] (convert-page-if-journal original-page-name date-formatter)
|
||||
page-entity (some-> db (d/entity [:block/name page-name]))
|
||||
page-entity (some-> db (ldb/get-page page-name))
|
||||
original-page-name (or from-page (:block/original-name page-entity) original-page-name)]
|
||||
(merge
|
||||
{:block/name page-name
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
"Creates default pages if one of the default pages does not exist. This
|
||||
fn is idempotent"
|
||||
[db-conn]
|
||||
(when-not (d/entity @db-conn [:block/name "card"])
|
||||
(when-not (ldb/get-page @db-conn "card")
|
||||
(let [built-in-pages (build-pages-tx built-in-pages)]
|
||||
(ldb/transact! db-conn built-in-pages))))
|
||||
|
||||
|
@ -56,6 +56,5 @@
|
|||
|
||||
(defn get-page-file
|
||||
[db page-name]
|
||||
(some-> (or (d/entity db [:block/name page-name])
|
||||
(d/entity db [:block/original-name page-name]))
|
||||
(some-> (ldb/get-page db page-name)
|
||||
:block/file))
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
(defn- get-pid
|
||||
"Get a property's id (name or uuid) given its name. For db graphs"
|
||||
[db property-name]
|
||||
(:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc (name property-name))])))
|
||||
(:block/uuid (ldb/get-page db property-name)))
|
||||
|
||||
(defn- add-missing-timestamps
|
||||
"Add updated-at or created-at timestamps if they doesn't exist"
|
||||
|
@ -587,7 +587,7 @@
|
|||
(not (:block/file %))))
|
||||
;; remove file path relative
|
||||
(map #(dissoc % :block/file)))
|
||||
existing-pages (keep #(d/entity @conn [:block/name (:block/name %)]) all-pages)
|
||||
existing-pages (keep #(ldb/get-page @conn (:block/name %)) all-pages)
|
||||
existing-page-names (set (map :block/name existing-pages))
|
||||
new-pages (remove #(contains? existing-page-names (:block/name %)) all-pages)
|
||||
page-names-to-uuids (into {}
|
||||
|
@ -865,7 +865,7 @@
|
|||
[(get ?bp ?prop-uuid) ?_v]]
|
||||
@conn
|
||||
(set (map :block/name user-classes)))
|
||||
(remove #(ldb/built-in? (d/entity @conn [:block/name (second %)])))
|
||||
(remove #(ldb/built-in? (ldb/get-page @conn (second %))))
|
||||
(reduce (fn [acc [class-id _prop-name prop-uuid]]
|
||||
(update acc class-id (fnil conj #{}) prop-uuid))
|
||||
{}))
|
||||
|
@ -924,10 +924,10 @@
|
|||
(ldb/create-favorites-page repo)
|
||||
(if-let [favorited-ids
|
||||
(keep (fn [page-name]
|
||||
(some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
|
||||
(some-> (ldb/get-page @conn page-name)
|
||||
:block/uuid))
|
||||
favorites)]
|
||||
(let [page-entity (d/entity @conn [:block/name common-config/favorites-page-name])]
|
||||
(let [page-entity (ldb/get-page @conn common-config/favorites-page-name)]
|
||||
(insert-favorites repo favorited-ids (:db/id page-entity)))
|
||||
(log-fn :no-favorites-found {:favorites favorites})))))
|
||||
|
||||
|
|
|
@ -225,6 +225,7 @@
|
|||
blocks (->> (gp-block/extract-blocks ast content false format options')
|
||||
(attach-block-ids-if-match override-uuids)
|
||||
(mapv #(gp-block/fix-block-id-if-duplicated! db page-name extracted-block-ids %))
|
||||
;; FIXME: use page uuid
|
||||
(gp-block/with-parent-and-left {:block/name page-name})
|
||||
(vec))
|
||||
ref-pages (atom #{})
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
[logseq.graph-parser.db :as gp-db]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[datascript.core :as d]))
|
||||
[datascript.core :as d]
|
||||
[logseq.db :as ldb]))
|
||||
|
||||
(def foo-edn
|
||||
"Example exported whiteboard page as an edn exportable."
|
||||
|
@ -414,7 +415,7 @@ id:: 63f199bc-c737-459f-983d-84acfcda14fe
|
|||
id:: 63f199bc-c737-459f-983d-84acfcda14fe
|
||||
"
|
||||
parse-opts)
|
||||
(let [blocks (:block/_parent (d/entity @conn [:block/name "foo"]))]
|
||||
(let [blocks (:block/_parent (ldb/get-page @conn "foo"))]
|
||||
(is (= 2 (count blocks)))
|
||||
(is (= 1 (count (filter #(= (:block/uuid %) block-id) blocks)))))))
|
||||
|
||||
|
@ -442,6 +443,6 @@ bar
|
|||
(-> (d/entity @conn [:block/uuid block-id])
|
||||
:block/page
|
||||
:block/name)))
|
||||
(let [bar-block (first (:block/_parent (d/entity @conn [:block/name "bar"])))]
|
||||
(let [bar-block (first (:block/_parent (ldb/get-page @conn "bar")))]
|
||||
(is (some? (:block/uuid bar-block)))
|
||||
(is (not= (:block/uuid bar-block) block-id))))))
|
||||
|
|
|
@ -711,7 +711,7 @@
|
|||
(when-let [page-name-in-block (:block/name page)]
|
||||
(let [page-name-in-block (common-util/remove-boundary-slashes page-name-in-block)
|
||||
page-name (util/page-name-sanity-lc page-name-in-block)
|
||||
page-entity (db/entity [:block/name page-name])
|
||||
page-entity (db/get-page page-name)
|
||||
whiteboard-page? (model/whiteboard-page? page-name)
|
||||
inner (page-inner config
|
||||
page-name-in-block
|
||||
|
@ -719,7 +719,7 @@
|
|||
page-entity contents-page? children html-export? label whiteboard-page?)
|
||||
modal? (:modal/show? @state/state)]
|
||||
(if (and (not (util/mobile?))
|
||||
(not= (util/page-name-sanity-lc page-name-in-block) (:id config))
|
||||
(not= page-name (:id config))
|
||||
(not (false? preview?))
|
||||
(not disable-preview?)
|
||||
(not modal?))
|
||||
|
@ -885,7 +885,7 @@
|
|||
(defn- get-page
|
||||
[label]
|
||||
(when-let [label-text (get-label-text label)]
|
||||
(db/entity [:block/name (util/page-name-sanity-lc label-text)])))
|
||||
(db/get-page label-text)))
|
||||
|
||||
(defn- macro->text
|
||||
[name arguments]
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
:else
|
||||
(take 5 items))))
|
||||
page-exists? (when-not (string/blank? input)
|
||||
(db/entity [:block/name (string/trim input)]))
|
||||
(db/get-page (string/trim input)))
|
||||
include-slash? (or (string/includes? input "/")
|
||||
(string/starts-with? input "/"))
|
||||
order* (cond
|
||||
|
@ -216,15 +216,15 @@
|
|||
(remove nil?)
|
||||
(map
|
||||
(fn [page]
|
||||
(let [entity (db/entity [:block/name (util/page-name-sanity-lc page)])
|
||||
(let [entity (db/get-page page)
|
||||
whiteboard? (= (:block/type entity) "whiteboard")
|
||||
source-page (model/get-alias-source-page repo page)]
|
||||
(hash-map :icon (if whiteboard? "whiteboard" "page")
|
||||
:icon-theme :gray
|
||||
:text page
|
||||
:source-page (if source-page
|
||||
(:block/original-name source-page)
|
||||
page))))))]
|
||||
(:block/original-name source-page)
|
||||
page))))))]
|
||||
(swap! !results update group merge {:status :success :items items}))))
|
||||
|
||||
(defmethod load-results :whiteboards [group state]
|
||||
|
@ -238,7 +238,7 @@
|
|||
(remove nil?)
|
||||
(keep
|
||||
(fn [page]
|
||||
(let [entity (db/entity [:block/name (util/page-name-sanity-lc page)])
|
||||
(let [entity (db/get-page page)
|
||||
whiteboard? (= (:block/type entity) "whiteboard")]
|
||||
(when whiteboard?
|
||||
(hash-map :icon "whiteboard"
|
||||
|
@ -314,27 +314,6 @@
|
|||
files)]
|
||||
(swap! !results update group merge {:status :success :items items}))))
|
||||
|
||||
;; FIXME: recent search
|
||||
;; (defmethod load-results :recents [group state]
|
||||
;; (let [!input (::input state)
|
||||
;; !results (::results state)
|
||||
;; recent-searches (mapv (fn [q] {:type :search :data q}) (db/get-key-value :recent/search))
|
||||
;; recent-pages (->> (filter string? (db/get-key-value :recent/pages))
|
||||
;; (keep (fn [page]
|
||||
;; (when-let [page-entity (db/entity [:block/name (util/page-name-sanity-lc page)])]
|
||||
;; {:type :page :data (:block/original-name page-entity)})))
|
||||
;; vec)]
|
||||
;; (swap! !results assoc-in [group :status] :loading)
|
||||
;; (let [items (->> (concat recent-searches recent-pages)
|
||||
;; (filter #(string/includes? (lower-case-str (:data %)) (lower-case-str @!input)))
|
||||
;; (map #(hash-map :icon (if (= :page (:type %)) "page" "history")
|
||||
;; :icon-theme :gray
|
||||
;; :text (:data %)
|
||||
;; :source-recent %
|
||||
;; :source-page (when (= :page (:type %)) (:data %))
|
||||
;; :source-search (when (= :search (:type %)) (:data %)))))]
|
||||
;; (swap! !results update group merge {:status :success :items items}))))
|
||||
|
||||
(defn- get-filter-q
|
||||
[input]
|
||||
(or (when (string/starts-with? input "/")
|
||||
|
@ -407,7 +386,7 @@
|
|||
(defmethod handle-action :open-page [_ state _event]
|
||||
(when-let [page-name (get-highlighted-page-name state)]
|
||||
(let [redirect-page-name (model/get-redirect-page-name page-name)
|
||||
page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])
|
||||
page (db/get-page redirect-page-name)
|
||||
original-name (:block/original-name page)]
|
||||
(if (= (:block/type page) "whiteboard")
|
||||
(route-handler/redirect-to-page! original-name)
|
||||
|
@ -435,7 +414,7 @@
|
|||
(defmethod handle-action :open-page-right [_ state _event]
|
||||
(when-let [page-name (get-highlighted-page-name state)]
|
||||
(let [redirect-page-name (model/get-redirect-page-name page-name)
|
||||
page (db/entity [:block/name (util/page-name-sanity-lc redirect-page-name)])]
|
||||
page (db/get-page redirect-page-name)]
|
||||
(when page
|
||||
(editor-handler/open-block-in-sidebar! (:block/uuid page))))
|
||||
(state/close-modal!)))
|
||||
|
@ -509,7 +488,7 @@
|
|||
create-whiteboard? (whiteboard-handler/<create-new-whiteboard-and-redirect! @!input)
|
||||
create-page? (page-handler/<create! @!input {:redirect? true}))
|
||||
(if create-class?
|
||||
(state/pub-event! [:class/configure (db/entity [:block/name (util/page-name-sanity-lc class)])])
|
||||
(state/pub-event! [:class/configure (db/get-page class)])
|
||||
(state/close-modal!)))))
|
||||
|
||||
(defn- get-filter-user-input
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
:href (rfe/href :page {:name original-name})
|
||||
:on-click (fn [e]
|
||||
(when (gobj/get e "shiftKey")
|
||||
(when-let [page (db/entity [:block/name (util/page-name-sanity-lc original-name)])]
|
||||
(when-let [page (db/get-page original-name)]
|
||||
(state/sidebar-add-block!
|
||||
(state/get-current-repo)
|
||||
(:db/id page)
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
:options {:on-click
|
||||
(fn []
|
||||
(page-handler/update-public-attribute!
|
||||
page-name
|
||||
page
|
||||
(if public? false true))
|
||||
(state/close-modal!))}})
|
||||
|
||||
|
|
|
@ -103,11 +103,11 @@
|
|||
(let [journal (date/js-date->journal-title gd)]
|
||||
(p/do!
|
||||
(shui/popup-hide! id)
|
||||
(when-not (db/entity [:block/name (util/page-name-sanity-lc journal)])
|
||||
(when-not (db/get-page journal)
|
||||
(page-handler/<create! journal {:redirect? false
|
||||
:create-first-block? false}))
|
||||
(when (fn? on-change)
|
||||
(on-change (db/entity [:block/name (util/page-name-sanity-lc journal)])))
|
||||
(on-change (db/get-page journal)))
|
||||
(exit-edit-property))))))]
|
||||
(shui/calendar
|
||||
(cond->
|
||||
|
|
|
@ -205,7 +205,7 @@
|
|||
(boolean? value) (str value)
|
||||
;; string values will attempt to be rendered as pages, falling back to
|
||||
;; inline-text when no page entity is found
|
||||
(string? value) (if-let [page (db/entity [:block/name (util/page-name-sanity-lc value)])]
|
||||
(string? value) (if-let [page (db/get-page value)]
|
||||
(page-cp {} page)
|
||||
(inline-text row-block row-format value))
|
||||
;; render uuids as page refs
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
(sort-by second #(> %1 %2) references))
|
||||
|
||||
(defn filtered-refs
|
||||
[page-name filters filters-atom filtered-references]
|
||||
[page filters filters-atom filtered-references]
|
||||
[:div.flex.gap-2.flex-wrap.items-center
|
||||
(for [[ref-name ref-count] filtered-references]
|
||||
(when ref-name
|
||||
|
@ -38,13 +38,13 @@
|
|||
(swap! filters-atom #(if (nil? (get filters lc-reference))
|
||||
(assoc % lc-reference (not (.-shiftKey e)))
|
||||
(dissoc % lc-reference)))
|
||||
(page-handler/save-filter! page-name @filters-atom))
|
||||
(page-handler/save-filter! page @filters-atom))
|
||||
:small? true
|
||||
:variant :outline
|
||||
:key ref-name))))])
|
||||
|
||||
(rum/defcs filter-dialog-inner < rum/reactive (rum/local "" ::filterSearch)
|
||||
[state filters-atom *references page-name]
|
||||
[state page-entity filters-atom *references]
|
||||
(let [filter-search (get state ::filterSearch)
|
||||
references (rum/react *references)
|
||||
filtered-references (frequencies-sort
|
||||
|
@ -73,11 +73,11 @@
|
|||
(when (seq includes)
|
||||
[:div.flex.flex-row.flex-wrap.center-items
|
||||
[:div.mr-1.font-medium.py-1 (t :linked-references/filter-includes)]
|
||||
(filtered-refs page-name filters filters-atom includes)])
|
||||
(filtered-refs page-entity filters filters-atom includes)])
|
||||
(when (seq excludes)
|
||||
[:div.flex.flex-row.flex-wrap
|
||||
[:div.mr-1.font-medium.py-1 (t :linked-references/filter-excludes)]
|
||||
(filtered-refs page-name filters filters-atom excludes)])])
|
||||
(filtered-refs page-entity filters filters-atom excludes)])])
|
||||
[:div.cp__filters-input-panel.flex
|
||||
(ui/icon "search")
|
||||
[:input.cp__filters-input.w-full
|
||||
|
@ -90,12 +90,12 @@
|
|||
filtered-references)]
|
||||
(when (seq refs)
|
||||
[:div.mt-4
|
||||
(filtered-refs page-name filters filters-atom refs)]))]))
|
||||
(filtered-refs page-entity filters filters-atom refs)]))]))
|
||||
|
||||
(defn filter-dialog
|
||||
[filters-atom *references page-name]
|
||||
[page-entity filters-atom *references]
|
||||
(fn []
|
||||
(filter-dialog-inner filters-atom *references page-name)))
|
||||
(filter-dialog-inner page-entity filters-atom *references)))
|
||||
|
||||
(rum/defc block-linked-references < rum/reactive db-mixins/query
|
||||
{:init (fn [state]
|
||||
|
@ -136,7 +136,7 @@
|
|||
(content/content page-name {:hiccup ref-hiccup}))])
|
||||
|
||||
(rum/defc references-cp
|
||||
[page-name filters filters-atom filter-state total filter-n filtered-ref-blocks *ref-pages]
|
||||
[page-entity page-name filters filters-atom filter-state total filter-n filtered-ref-blocks *ref-pages]
|
||||
(let [threshold (state/get-linked-references-collapsed-threshold)
|
||||
default-collapsed? (>= total threshold)
|
||||
*collapsed? (atom nil)]
|
||||
|
@ -152,7 +152,7 @@
|
|||
:on-pointer-down (fn [e]
|
||||
(util/stop-propagation e))
|
||||
:on-click (fn []
|
||||
(state/set-modal! (filter-dialog filters-atom *ref-pages page-name)
|
||||
(state/set-modal! (filter-dialog page-entity filters-atom *ref-pages)
|
||||
{:center? true}))}
|
||||
(ui/icon "filter" {:class (cond
|
||||
(empty? filter-state)
|
||||
|
@ -254,7 +254,7 @@
|
|||
[:div.references.page-linked.flex-1.flex-row
|
||||
(sub-page-properties-changed page-entity page-props-v filters-atom)
|
||||
[:div.content.pt-6
|
||||
(references-cp page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
|
||||
(references-cp page-entity page-name filters filters-atom filter-state total filter-n filtered-ref-blocks' *ref-pages)]])))))))
|
||||
|
||||
(rum/defc references
|
||||
[page-entity]
|
||||
|
|
|
@ -173,11 +173,12 @@
|
|||
(str init-key))]
|
||||
|
||||
:page-slide-view
|
||||
(let [page-name (:block/name (db/entity db-id))]
|
||||
(let [page (db/entity db-id)
|
||||
page-name (:block/name page)]
|
||||
[[:a.page-title {:href (rfe/href :page {:name page-name})}
|
||||
(db-model/get-page-original-name page-name)]
|
||||
(:block/original-name page)]
|
||||
[:div.ml-2.slide.mt-2
|
||||
(slide/slide page-name)]])
|
||||
(slide/slide page)]])
|
||||
|
||||
:shortcut-settings
|
||||
[[:.flex.items-center (ui/icon "command" {:class "text-md mr-2"}) (t :help/shortcuts)]
|
||||
|
|
|
@ -530,11 +530,8 @@ independent of format as format specific heading characters are stripped"
|
|||
first))))
|
||||
|
||||
(defn get-page
|
||||
[page-name]
|
||||
(if-let [id (if (uuid? page-name) page-name
|
||||
(parse-uuid page-name))]
|
||||
(db-utils/entity [:block/uuid id])
|
||||
(db-utils/entity (ldb/get-first-page-by-name (conn/get-db) (str page-name)))))
|
||||
[page-name-or-uuid]
|
||||
(ldb/get-page (conn/get-db) page-name-or-uuid))
|
||||
|
||||
;; FIXME: should pass page's db id
|
||||
(defn get-redirect-page-name
|
||||
|
|
|
@ -383,7 +383,7 @@
|
|||
(when-not (and (:create-today-journal? tx-meta)
|
||||
(:today-journal-name tx-meta)
|
||||
(seq tx-data)
|
||||
(d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
|
||||
(ldb/get-page @conn (:today-journal-name tx-meta))) ; today journal created already
|
||||
|
||||
;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
|
||||
(worker-util/profile "Worker db transact"
|
||||
|
|
|
@ -88,10 +88,10 @@
|
|||
(reset! *loading? false)
|
||||
(render!)))))
|
||||
state)}
|
||||
[page-name]
|
||||
(let [loading? (rum/react *loading?)
|
||||
page (db/entity [:block/name page-name])
|
||||
journal? (:journal? page)
|
||||
[page]
|
||||
(let [page-name (:block/original-name page)
|
||||
loading? (rum/react *loading?)
|
||||
journal? (:block/journal? page)
|
||||
repo (state/get-current-repo)
|
||||
blocks (-> (db/get-page-blocks-no-cache repo (:db/id page))
|
||||
(outliner-tree/blocks->vec-tree (:db/id page)))
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
|
||||
(defn card-block?
|
||||
[block]
|
||||
(let [card-entity (db/entity [:block/name card-hash-tag])
|
||||
(let [card-entity (db/get-page card-hash-tag)
|
||||
refs (into #{} (:block/refs block))]
|
||||
(contains? refs card-entity)))
|
||||
|
||||
|
@ -264,7 +264,7 @@
|
|||
:or {use-cache? true}}]
|
||||
(when (string? query-string)
|
||||
(let [result (if (string/blank? query-string)
|
||||
(:block/_refs (db/entity [:block/name card-hash-tag]))
|
||||
(:block/_refs (db/get-page card-hash-tag))
|
||||
(let [query-string (template/resolve-dynamic-template! query-string)
|
||||
query-string (if-not (or (string/blank? query-string)
|
||||
(string/starts-with? query-string "(")
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
:getBlockPageName #(let [block-id-str %]
|
||||
(if (util/uuid-string? block-id-str)
|
||||
(:block/name (model/get-block-page (state/get-current-repo) (parse-uuid block-id-str)))
|
||||
(:block/name (db/entity [:block/name (util/page-name-sanity-lc block-id-str)]))))
|
||||
(:block/name (db/get-page block-id-str))))
|
||||
:exportToImage (fn [page-uuid-str options]
|
||||
(assert (common-util/uuid-string? page-uuid-str))
|
||||
(state/set-modal! #(export/export-blocks (uuid page-uuid-str) (merge (js->clj options :keywordize-keys true) {:whiteboard? true}))))
|
||||
|
|
|
@ -84,9 +84,9 @@
|
|||
[ref-blocks filters]
|
||||
(if (empty? filters)
|
||||
ref-blocks
|
||||
(let [exclude-ids (->> (keep (fn [page] (:db/id (db/entity [:block/name (util/page-name-sanity-lc page)]))) (get filters false))
|
||||
(let [exclude-ids (->> (keep (fn [page] (:db/id (db/get-page page))) (get filters false))
|
||||
(set))
|
||||
include-ids (->> (keep (fn [page] (:db/id (db/entity [:block/name (util/page-name-sanity-lc page)]))) (get filters true))
|
||||
include-ids (->> (keep (fn [page] (:db/id (db/get-page page))) (get filters true))
|
||||
(set))]
|
||||
(cond->> ref-blocks
|
||||
(seq exclude-ids)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
[frontend.modules.outliner.ui :as ui-outliner-tx]
|
||||
[frontend.modules.outliner.op :as outliner-op]))
|
||||
|
||||
;; TODO: return page entity instead
|
||||
(defn create!
|
||||
"Create page. Has the following options:
|
||||
|
||||
|
@ -43,11 +42,12 @@
|
|||
(let [repo (state/get-current-repo)
|
||||
conn (db/get-db repo false)
|
||||
config (state/get-config repo)
|
||||
;; FIXME: create! returns page-entity
|
||||
[_ page-name] (worker-page/create! repo conn config title options)]
|
||||
(when redirect?
|
||||
;; FIXME: use uuid instead
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
|
||||
(when-let [first-block (first (:block/_left (db/get-page page-name)))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page-name)))
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
(when redirect?
|
||||
;; FIXME: use uuid instead
|
||||
(route-handler/redirect-to-page! page-name))
|
||||
(let [page (db/entity [:block/name page-name])]
|
||||
(let [page (db/get-page page-name)]
|
||||
(when-let [first-block (first (:block/_left page))]
|
||||
(block-handler/edit-block! first-block :max nil))
|
||||
page))))
|
||||
|
@ -120,14 +120,14 @@
|
|||
(defn <favorite-page!-v2
|
||||
[page-block-uuid]
|
||||
{:pre [(uuid? page-block-uuid)]}
|
||||
(let [favorites-page (d/entity (conn/get-db) [:block/name common-config/favorites-page-name])]
|
||||
(let [favorites-page (db/get-page common-config/favorites-page-name)]
|
||||
(when (d/entity (conn/get-db) [:block/uuid page-block-uuid])
|
||||
(p/do!
|
||||
(when-not favorites-page (ldb/create-favorites-page (state/get-current-repo)))
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :insert-blocks}
|
||||
(outliner-op/insert-blocks! [(ldb/build-favorite-tx page-block-uuid)]
|
||||
(d/entity (conn/get-db) [:block/name common-config/favorites-page-name])
|
||||
(db/get-page common-config/favorites-page-name)
|
||||
{}))))))
|
||||
|
||||
(defn <unfavorite-page!-v2
|
||||
|
@ -170,9 +170,7 @@
|
|||
(let [repo-dir (config/get-repo-dir repo)]
|
||||
;; TODO: move favorite && unfavorite to worker too
|
||||
(if (config/db-based-graph? repo)
|
||||
(when-let [page-block-uuid (:block/uuid
|
||||
(d/entity (conn/get-db repo)
|
||||
[:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||
(when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
|
||||
(<unfavorite-page!-v2 page-block-uuid))
|
||||
(unfavorite-page! page-name))
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@
|
|||
(let [tag-without-hash (common-util/safe-subs (string/trim v) 1)
|
||||
tag (or (page-ref/get-page-name tag-without-hash) tag-without-hash)]
|
||||
(when-not (string/blank? tag)
|
||||
(let [e (db/entity [:block/name (util/page-name-sanity-lc tag)])
|
||||
(let [e (db/get-page tag)
|
||||
e' (if e
|
||||
(do
|
||||
(when-not (contains? (:block/type e) "tag")
|
||||
|
@ -453,7 +453,7 @@
|
|||
[block property value parse-block]
|
||||
(let [current-page-id (:block/uuid (or (:block/page block) block))
|
||||
page-name (str "$$$" current-page-id)
|
||||
page-entity (db/entity [:block/name page-name])
|
||||
page-entity (db/get-page page-name)
|
||||
page (or page-entity
|
||||
(-> (block/page-name->map page-name true)
|
||||
(assoc :block/type #{"hidden"}
|
||||
|
@ -505,7 +505,7 @@
|
|||
[block property template]
|
||||
(let [current-page-id (:block/uuid (or (:block/page block) block))
|
||||
page-name (str "$$$" current-page-id)
|
||||
page-entity (db/entity [:block/name page-name])
|
||||
page-entity (db/get-page page-name)
|
||||
page (or page-entity
|
||||
(-> (block/page-name->map page-name true)
|
||||
(assoc :block/type #{"hidden"}
|
||||
|
@ -532,7 +532,7 @@
|
|||
(defn- get-property-hidden-page
|
||||
[property]
|
||||
(let [page-name (str db-property-util/hidden-page-name-prefix (:block/uuid property))]
|
||||
(or (db/entity [:block/name page-name])
|
||||
(or (db/get-page page-name)
|
||||
(db-property-util/build-property-hidden-page property))))
|
||||
|
||||
(defn re-init-commands!
|
||||
|
|
|
@ -486,7 +486,7 @@
|
|||
sibling? (boolean sibling?)
|
||||
sibling? (if before? true (if page false sibling?))
|
||||
block (if page
|
||||
(db/entity [:block/name (util/page-name-sanity-lc page)])
|
||||
(db/get-page page)
|
||||
(db/entity [:block/uuid block-uuid]))
|
||||
db-based? (config/db-based-graph? repo)]
|
||||
(when block
|
||||
|
@ -2268,7 +2268,7 @@
|
|||
(when id
|
||||
(when-let [entity (if-let [id' (parse-uuid (str id))]
|
||||
(db/entity [:block/uuid id'])
|
||||
(db/entity [:block/name (util/page-name-sanity-lc id)]))]
|
||||
(db/get-page id))]
|
||||
(= (:block/uuid entity) (otree/-get-parent-id current-node (db/get-db false))))))
|
||||
|
||||
(defn insert
|
||||
|
|
|
@ -694,13 +694,13 @@
|
|||
|
||||
(defmethod handle :journal/insert-template [[_ page-name]]
|
||||
(let [page-name (util/page-name-sanity-lc page-name)]
|
||||
(when-let [page (db/pull [:block/name page-name])]
|
||||
(when-let [page (db/get-page page-name)]
|
||||
(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}))))))
|
||||
nil
|
||||
template
|
||||
{:target page}))))))
|
||||
|
||||
(defmethod handle :editor/set-org-mode-heading [[_ block heading]]
|
||||
(when-let [id (:block/uuid block)]
|
||||
|
|
|
@ -444,9 +444,10 @@
|
|||
(common/get-page-content root-block-uuids-or-page-uuid)
|
||||
(common/root-block-uuids->content repo root-block-uuids-or-page-uuid))
|
||||
title (if (uuid? root-block-uuids-or-page-uuid)
|
||||
(:block/original-name (db/entity [:block/name root-block-uuids-or-page-uuid]))
|
||||
(:block/original-name (db/entity [:block/uuid root-block-uuids-or-page-uuid]))
|
||||
"untitled")
|
||||
first-block (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)])
|
||||
first-block (and (coll? root-block-uuids-or-page-uuid)
|
||||
(db/entity [:block/uuid (first root-block-uuids-or-page-uuid)]))
|
||||
format (or (:block/format first-block) (state/get-preferred-format))]
|
||||
(export-helper content format options :title title))))
|
||||
|
||||
|
|
|
@ -50,39 +50,38 @@
|
|||
content kvs))
|
||||
|
||||
(defn add-property!
|
||||
[page-name key value]
|
||||
(let [repo (state/get-current-repo)]
|
||||
(when-let [page (db/pull [:block/name (util/page-name-sanity-lc page-name)])]
|
||||
(let [key (keyword key)
|
||||
pre-block (db/get-pre-block repo (:db/id page))
|
||||
format (state/get-preferred-format)
|
||||
page-id {:db/id (:db/id page)}
|
||||
org? (= format :org)
|
||||
value (if (contains? #{:filters} key) (pr-str value) value)]
|
||||
(if pre-block
|
||||
(let [properties (:block/properties pre-block)
|
||||
new-properties (assoc properties key value)
|
||||
content (:block/content pre-block)
|
||||
new-content (insert-property format content key value)
|
||||
block {:db/id (:db/id pre-block)
|
||||
:block/properties new-properties
|
||||
:block/content new-content
|
||||
:block/page page-id}
|
||||
tx [(assoc page-id :block/properties new-properties)
|
||||
block]]
|
||||
(db/transact! tx))
|
||||
(let [block {:block/uuid (db/new-block-id)
|
||||
:block/left page-id
|
||||
:block/parent page-id
|
||||
:block/page page-id
|
||||
:block/content (if org?
|
||||
(str "#+" (string/upper-case (name key)) ": " value)
|
||||
(str (name key) ":: " value))
|
||||
:block/format format
|
||||
:block/properties {key value}
|
||||
:block/pre-block? true}
|
||||
page-properties-tx [(assoc page-id :block/properties {key value})]]
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :insert-blocks
|
||||
:additional-tx page-properties-tx}
|
||||
(outliner-op/insert-blocks! block page {:sibling? false}))))))))
|
||||
[page key value]
|
||||
(let [repo (state/get-current-repo)
|
||||
key (keyword key)
|
||||
pre-block (db/get-pre-block repo (:db/id page))
|
||||
format (state/get-preferred-format)
|
||||
page-id {:db/id (:db/id page)}
|
||||
org? (= format :org)
|
||||
value (if (contains? #{:filters} key) (pr-str value) value)]
|
||||
(if pre-block
|
||||
(let [properties (:block/properties pre-block)
|
||||
new-properties (assoc properties key value)
|
||||
content (:block/content pre-block)
|
||||
new-content (insert-property format content key value)
|
||||
block {:db/id (:db/id pre-block)
|
||||
:block/properties new-properties
|
||||
:block/content new-content
|
||||
:block/page page-id}
|
||||
tx [(assoc page-id :block/properties new-properties)
|
||||
block]]
|
||||
(db/transact! tx))
|
||||
(let [block {:block/uuid (db/new-block-id)
|
||||
:block/left page-id
|
||||
:block/parent page-id
|
||||
:block/page page-id
|
||||
:block/content (if org?
|
||||
(str "#+" (string/upper-case (name key)) ": " value)
|
||||
(str (name key) ":: " value))
|
||||
:block/format format
|
||||
:block/properties {key value}
|
||||
:block/pre-block? true}
|
||||
page-properties-tx [(assoc page-id :block/properties {key value})]]
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :insert-blocks
|
||||
:additional-tx page-properties-tx}
|
||||
(outliner-op/insert-blocks! block page {:sibling? false}))))))
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
default-content)
|
||||
file-rpath (path/path-join (config/get-journals-directory) (str file-name "."
|
||||
(config/get-file-extension format)))
|
||||
page-exists? (db/entity repo-url [:block/name (util/page-name-sanity-lc title)])
|
||||
page-exists? (db/page-exists? title)
|
||||
empty-blocks? (db/page-empty? repo-url (util/page-name-sanity-lc title))]
|
||||
(when (or empty-blocks? (not page-exists?))
|
||||
(p/let [_ (nfs/check-directory-permission! repo-url)
|
||||
|
|
|
@ -101,21 +101,21 @@
|
|||
(p/do!
|
||||
(when (not (db/page-exists? page-name))
|
||||
(page-handler/<create! page-name {:redirect? false}))
|
||||
(let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)])
|
||||
children (:block/_parent page-block)
|
||||
blocks (db/sort-by-left children page-block)
|
||||
last-block (last blocks)
|
||||
snd-last-block (last (butlast blocks))
|
||||
[target-block sibling?] (if (and last-block (seq (:block/content last-block)))
|
||||
[last-block true]
|
||||
(if snd-last-block
|
||||
[snd-last-block true]
|
||||
[page-block false]))]
|
||||
(editor/paste-blocks
|
||||
parsed-blocks
|
||||
{:target-block target-block
|
||||
:sibling? sibling?})
|
||||
(finished-ok-handler [page-name]))))))
|
||||
(let [page-block (db/get-page page-name)
|
||||
children (:block/_parent page-block)
|
||||
blocks (db/sort-by-left children page-block)
|
||||
last-block (last blocks)
|
||||
snd-last-block (last (butlast blocks))
|
||||
[target-block sibling?] (if (and last-block (seq (:block/content last-block)))
|
||||
[last-block true]
|
||||
(if snd-last-block
|
||||
[snd-last-block true]
|
||||
[page-block false]))]
|
||||
(editor/paste-blocks
|
||||
parsed-blocks
|
||||
{:target-block target-block
|
||||
:sibling? sibling?})
|
||||
(finished-ok-handler [page-name]))))))
|
||||
|
||||
(defn create-page-with-exported-tree!
|
||||
"Create page from the per page object generated in `export-repo-as-edn-v2!`
|
||||
|
@ -146,7 +146,7 @@
|
|||
"\nSkipped and continue the remaining import.") :error)))
|
||||
(when has-children?
|
||||
(let [page-name (util/page-name-sanity-lc title)
|
||||
page-block (db/entity [:block/name page-name])]
|
||||
page-block (db/get-page page-name)]
|
||||
;; Missing support for per block format (or deprecated?)
|
||||
(try (if whiteboard?
|
||||
;; only works for file graph :block/properties
|
||||
|
|
|
@ -51,9 +51,8 @@
|
|||
(p/do!
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (config/db-based-graph? repo)
|
||||
(let [db (conn/get-db)]
|
||||
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||
(page-common-handler/<unfavorite-page!-v2 page-block-uuid)))
|
||||
(when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
|
||||
(page-common-handler/<unfavorite-page!-v2 page-block-uuid))
|
||||
(page-common-handler/unfavorite-page! page-name)))
|
||||
(state/update-favorites-updated!)))
|
||||
|
||||
|
@ -62,9 +61,8 @@
|
|||
(p/do!
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (config/db-based-graph? repo)
|
||||
(let [db (conn/get-db)]
|
||||
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||
(page-common-handler/<favorite-page!-v2 page-block-uuid)))
|
||||
(when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
|
||||
(page-common-handler/<favorite-page!-v2 page-block-uuid))
|
||||
(page-common-handler/favorite-page! page-name)))
|
||||
(state/update-favorites-updated!)))
|
||||
|
||||
|
@ -72,10 +70,9 @@
|
|||
[page-name]
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (config/db-based-graph? repo)
|
||||
(when-let [db (conn/get-db)]
|
||||
(boolean
|
||||
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||
(page-common-handler/favorited?-v2 page-block-uuid))))
|
||||
(boolean
|
||||
(when-let [page-block-uuid (:block/uuid (db/get-page page-name))]
|
||||
(page-common-handler/favorited?-v2 page-block-uuid)))
|
||||
(page-common-handler/favorited? page-name))))
|
||||
|
||||
|
||||
|
@ -98,7 +95,7 @@
|
|||
(filter string?)
|
||||
(mapv util/safe-page-name-sanity-lc)
|
||||
(distinct))]
|
||||
(keep (fn [page-name] (d/entity db [:block/name page-name])) page-names))))))
|
||||
(keep (fn [page-name] (db/get-page page-name)) page-names))))))
|
||||
|
||||
|
||||
;; FIXME: add whiteboard
|
||||
|
@ -151,12 +148,11 @@
|
|||
[favorites]
|
||||
(let [conn (conn/get-db false)
|
||||
db @conn]
|
||||
(when-let [page-id (ldb/get-first-page-by-name db common-config/favorites-page-name)]
|
||||
(when-let [page-id (db/get-page common-config/favorites-page-name)]
|
||||
(let [favorites-page-entity (d/entity db page-id)
|
||||
favorite-page-block-db-id-coll
|
||||
(keep (fn [page-name]
|
||||
(some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
|
||||
:db/id))
|
||||
(:db/id (db/get-page page-name)))
|
||||
favorites)
|
||||
current-blocks (ldb/sort-by-left (ldb/get-page-blocks @conn common-config/favorites-page-name {})
|
||||
favorites-page-entity)]
|
||||
|
@ -179,8 +175,8 @@
|
|||
(state/set-journals-length! (+ (:journals-length @state/state) 7))))
|
||||
|
||||
(defn update-public-attribute!
|
||||
[page-name value]
|
||||
(property-handler/add-page-property! page-name :logseq.property/public value))
|
||||
[page value]
|
||||
(property-handler/add-page-property! page :logseq.property/public value))
|
||||
|
||||
(defn get-page-ref-text
|
||||
[page]
|
||||
|
@ -262,8 +258,8 @@
|
|||
(log/error :syntax/filters e))))))
|
||||
|
||||
(defn save-filter!
|
||||
[page-name filter-state]
|
||||
(property-handler/add-page-property! page-name :logseq.property/filters filter-state))
|
||||
[page filter-state]
|
||||
(property-handler/add-page-property! page :logseq.property/filters filter-state))
|
||||
|
||||
;; Editor
|
||||
(defn page-not-exists-handler
|
||||
|
@ -286,7 +282,7 @@
|
|||
(cursor/move-cursor-forward input (+ 2 (count current-selected))))))
|
||||
|
||||
(defn add-tag [repo block-id tag & {:keys [tag-entity]}]
|
||||
(let [tag-entity (or tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)]))
|
||||
(let [tag-entity (or tag-entity (db/get-page tag))
|
||||
tx-data [[:db/add (:db/id tag-entity) :block/type "class"]
|
||||
[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
|
||||
;; TODO: Should classes counted as refs
|
||||
|
@ -330,12 +326,12 @@
|
|||
(let [tag (string/trim chosen)
|
||||
edit-block (state/get-edit-block)]
|
||||
(when (and (not (string/blank? tag)) (:block/uuid edit-block))
|
||||
(p/let [tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])
|
||||
(p/let [tag-entity (db/get-page tag)
|
||||
_ (when-not tag-entity
|
||||
(<create! tag {:redirect? false
|
||||
:create-first-block? false
|
||||
:class? class?}))
|
||||
tag-entity (db/entity [:block/name (util/page-name-sanity-lc tag)])]
|
||||
tag-entity (db/get-page tag)]
|
||||
(when class?
|
||||
(add-tag (state/get-current-repo) (:block/uuid edit-block) tag {:tag-entity tag-entity}))))))
|
||||
(editor-handler/insert-command! id
|
||||
|
@ -404,7 +400,7 @@
|
|||
|
||||
(defn open-today-in-sidebar
|
||||
[]
|
||||
(when-let [page (db/entity [:block/name (util/page-name-sanity-lc (date/today))])]
|
||||
(when-let [page (db/get-page (date/today))]
|
||||
(state/sidebar-add-block!
|
||||
(state/get-current-repo)
|
||||
(:db/id page)
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
[frontend.handler.file-based.property :as file-property-handler]
|
||||
[frontend.handler.file-based.page-property :as file-page-property]
|
||||
[frontend.config :as config]
|
||||
[frontend.util :as util]
|
||||
[frontend.state :as state]
|
||||
[frontend.db :as db]))
|
||||
[frontend.state :as state]))
|
||||
|
||||
(defn remove-block-property!
|
||||
[repo block-id property-id-or-key]
|
||||
|
@ -26,12 +24,12 @@
|
|||
|
||||
(defn add-page-property!
|
||||
"Sanitized page-name, unsanitized key / value"
|
||||
[page-name key value]
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (config/db-based-graph? repo)
|
||||
(when-let [page (db/entity [:block/name (util/page-name-sanity-lc page-name)])]
|
||||
(set-block-property! repo (:block/uuid page) key value))
|
||||
(file-page-property/add-property! page-name key value))))
|
||||
[page-entity key value]
|
||||
(when page-entity
|
||||
(let [repo (state/get-current-repo)]
|
||||
(if (config/db-based-graph? repo)
|
||||
(set-block-property! repo (:block/uuid page-entity) key value)
|
||||
(file-page-property/add-property! page-entity key value)))))
|
||||
|
||||
(defn set-editing-new-property!
|
||||
[value]
|
||||
|
|
|
@ -133,8 +133,8 @@
|
|||
(str (subs content 0 48) "...")
|
||||
content))
|
||||
"Page no longer exists!!")
|
||||
(let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
|
||||
(or (util/get-page-original-name page)
|
||||
(let [page (db/get-page name)]
|
||||
(or (:block/original-name page)
|
||||
"Logseq"))))
|
||||
:whiteboard
|
||||
(let [name (:name path-params)
|
||||
|
@ -142,8 +142,8 @@
|
|||
(str
|
||||
(if block?
|
||||
(t :untitled)
|
||||
(let [page (db/pull [:block/name (util/page-name-sanity-lc name)])]
|
||||
(or (util/get-page-original-name page)
|
||||
(let [page (db/get-page name)]
|
||||
(or (:block/original-name page)
|
||||
"Logseq"))) " - " (t :whiteboard)))
|
||||
:tag
|
||||
(str "#" (:name path-params))
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
:as opts}]
|
||||
(when-not (string/blank? q)
|
||||
(let [page-db-id (if (string? page-db-id)
|
||||
(:db/id (db/entity repo [:block/name (util/page-name-sanity-lc page-db-id)]))
|
||||
(:db/id (db/get-page page-db-id))
|
||||
page-db-id)
|
||||
opts (if page-db-id (assoc opts :page (str page-db-id)) opts)]
|
||||
(p/let [blocks (search/block-search repo q opts)
|
||||
|
|
|
@ -315,11 +315,11 @@
|
|||
(when-let [app (state/active-tldraw-app)]
|
||||
(let [tl-page ^js (second (first (.-pages app)))]
|
||||
(when tl-page
|
||||
(when-let [page (db/entity [:block/name page-name])]
|
||||
(let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
|
||||
shapes-index (:shapes-index page-metadata)]
|
||||
(when (seq shapes-index)
|
||||
(.updateShapesIndex tl-page (bean/->js shapes-index)))))))))
|
||||
(when-let [page (db/get-page page-name)]
|
||||
(let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
|
||||
shapes-index (:shapes-index page-metadata)]
|
||||
(when (seq shapes-index)
|
||||
(.updateShapesIndex tl-page (bean/->js shapes-index)))))))))
|
||||
|
||||
(defn populate-onboarding-whiteboard
|
||||
[api]
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
[frontend.date :as date]
|
||||
[frontend.state :as state]
|
||||
[frontend.db.utils :as db-utils]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util.page-ref :as page-ref]))
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[logseq.db :as ldb]
|
||||
[frontend.db.conn :as conn]))
|
||||
|
||||
(defn- variable-rules
|
||||
[]
|
||||
|
@ -19,7 +20,7 @@
|
|||
(let [block-uuid (parse-uuid current-page)
|
||||
page (if block-uuid
|
||||
(:block/page (db-utils/entity [:block/uuid block-uuid]))
|
||||
(db-utils/entity [:block/name (util/page-name-sanity-lc current-page)]))
|
||||
(ldb/get-page (conn/get-db) current-page))
|
||||
current-page' (:block/original-name page)]
|
||||
(page-ref/->page-ref current-page')))})
|
||||
|
||||
|
|
|
@ -15,13 +15,12 @@
|
|||
"Fetches the current page id. Looks up page based on latest route and if
|
||||
nothing is found, gets page of last edited block"
|
||||
[]
|
||||
(let [page-name (some-> (or (state/get-current-page) (state/get-current-whiteboard))
|
||||
util/page-name-sanity-lc)]
|
||||
(or (and page-name (:db/id (db/entity [:block/name page-name])))
|
||||
(let [page-name (or (state/get-current-page) (state/get-current-whiteboard))]
|
||||
(or (and page-name (db/get-page page-name))
|
||||
(get-in (first (state/get-editor-args)) [:block :block/page :db/id]))))
|
||||
|
||||
(defn get-editing-page-id
|
||||
"Fetch the editing page id. If there is an edit-input-id set, we are probably still
|
||||
"Fetch the editing page id. If there is an edit-input-id set, we are probably still
|
||||
on editing mode"
|
||||
[]
|
||||
(if (or (state/editing?) (state/get-edit-input-id))
|
||||
|
@ -36,4 +35,4 @@ Returns nil if no file path is found or no page is detected or given"
|
|||
(get-in (db/entity page-id) [:block/file :file/path])))
|
||||
([page-name]
|
||||
(when-let [page-name' (some-> page-name util/page-name-sanity-lc)]
|
||||
(get-in (db/entity [:block/name page-name']) [:block/file :file/path]))))
|
||||
(get-in (db/get-page page-name') [:block/file :file/path]))))
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
[?b :block/original-name]
|
||||
[?b :block/name]] db)
|
||||
|
||||
(map (fn [[{:block/keys [name] :as page}]]
|
||||
(map (fn [[page]]
|
||||
(let [whiteboard? (contains? (set (:block/type page)) "whiteboard")
|
||||
blocks (ldb/get-page-blocks db name {})
|
||||
blocks (ldb/get-page-blocks db (:db/id page) {})
|
||||
blocks' (if whiteboard?
|
||||
blocks
|
||||
(map (fn [b]
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
(not (worker-state/tx-idle? repo {:diff 3000})))
|
||||
(async/put! file-writes-chan [repo page-db-id outliner-op (tc/to-long (t/now)) request-id])
|
||||
(let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
|
||||
blocks (ldb/get-page-blocks @conn (:block/name page-block) {:pull-keys pull-keys})
|
||||
blocks (ldb/get-page-blocks @conn (:db/id page-block) {:pull-keys pull-keys})
|
||||
blocks (if whiteboard? (map cleanup-whiteboard-block blocks) blocks)]
|
||||
(if (and (= 1 (count blocks))
|
||||
(string/blank? (:block/content (first blocks)))
|
||||
|
|
|
@ -475,8 +475,8 @@
|
|||
|
||||
(defn- move-all-blocks-to-another-page
|
||||
[repo conn from-page-name to-page-name]
|
||||
(let [blocks (ldb/get-page-blocks @conn from-page-name {})
|
||||
target-page-block (d/entity @conn (ldb/get-first-page-by-name @conn to-page-name))]
|
||||
(let [blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn from-page-name)) {})
|
||||
target-page-block (ldb/get-page @conn to-page-name)]
|
||||
(when (and (seq blocks) target-page-block)
|
||||
(outliner-tx/transact!
|
||||
{:persist-op? true
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
;; (let [opts {:redirect? false :create-first-block? false}
|
||||
;; _ (page-handler/create! "page1" opts)
|
||||
;; _ (page-handler/create! "page2" opts)
|
||||
;; p1id (:block/uuid (db/entity [:block/name "page1"]))
|
||||
;; p2id (:block/uuid (db/entity [:block/name "page2"]))]
|
||||
;; p1id (:block/uuid (db/get-page "page1"))
|
||||
;; p2id (:block/uuid (db/get-page "page2"))]
|
||||
;; (db-property-handler/upsert-property! repo "property-1" {:type :page} {})
|
||||
;; (db-property-handler/set-block-property! repo fbid "property-1" p1id {})
|
||||
;; (db-property-handler/set-block-property! repo sbid "property-1" p2id {})
|
||||
|
@ -50,30 +50,30 @@
|
|||
(is (= ["Task" "card" "class1" "class2"] (sort (map first (model/get-all-classes repo)))))))
|
||||
|
||||
(deftest get-class-objects-test
|
||||
(let [opts {:redirect? false :create-first-block? false :class? true}
|
||||
_ (page-handler/create! "class1" opts)
|
||||
class (db/entity [:block/name "class1"])
|
||||
_ (test-helper/save-block! repo fbid "Block 1" {:tags ["class1"]})]
|
||||
(is (= (model/get-class-objects repo (:db/id class))
|
||||
[(:db/id (db/entity [:block/uuid fbid]))]))
|
||||
(let [opts {:redirect? false :create-first-block? false :class? true}
|
||||
_ (page-handler/create! "class1" opts)
|
||||
class (db/get-page "class1")
|
||||
_ (test-helper/save-block! repo fbid "Block 1" {:tags ["class1"]})]
|
||||
(is (= (model/get-class-objects repo (:db/id class))
|
||||
[(:db/id (db/entity [:block/uuid fbid]))]))
|
||||
|
||||
(testing "classes parent"
|
||||
(page-handler/create! "class2" opts)
|
||||
(testing "classes parent"
|
||||
(page-handler/create! "class2" opts)
|
||||
;; set class2's parent to class1
|
||||
(let [class2 (db/entity [:block/name "class2"])]
|
||||
(db/transact! [{:db/id (:db/id class2)
|
||||
:class/parent (:db/id class)}]))
|
||||
(test-helper/save-block! repo sbid "Block 2" {:tags ["class2"]})
|
||||
(is (= (model/get-class-objects repo (:db/id class))
|
||||
[(:db/id (db/entity [:block/uuid fbid]))
|
||||
(:db/id (db/entity [:block/uuid sbid]))])))))
|
||||
(let [class2 (db/get-page "class2")]
|
||||
(db/transact! [{:db/id (:db/id class2)
|
||||
:class/parent (:db/id class)}]))
|
||||
(test-helper/save-block! repo sbid "Block 2" {:tags ["class2"]})
|
||||
(is (= (model/get-class-objects repo (:db/id class))
|
||||
[(:db/id (db/entity [:block/uuid fbid]))
|
||||
(:db/id (db/entity [:block/uuid sbid]))])))))
|
||||
|
||||
(deftest get-classes-with-property-test
|
||||
(let [opts {:redirect? false :create-first-block? false :class? true}
|
||||
_ (page-handler/create! "class1" opts)
|
||||
_ (page-handler/create! "class2" opts)
|
||||
class1 (db/entity [:block/name "class1"])
|
||||
class2 (db/entity [:block/name "class2"])]
|
||||
class1 (db/get-page "class1")
|
||||
class2 (db/get-page "class2")]
|
||||
(db-property-handler/upsert-property! repo :user.property/property-1 {:type :page} {})
|
||||
(db-property-handler/class-add-property! repo (:block/uuid class1) :user.property/property-1)
|
||||
(db-property-handler/class-add-property! repo (:block/uuid class2) :user.property/property-1)
|
||||
|
@ -95,7 +95,7 @@
|
|||
(deftest hidden-page-test
|
||||
(let [opts {:redirect? false :create-first-block? false}
|
||||
_ (page-handler/create! "page 1" opts)]
|
||||
(is (false? (model/hidden-page? (db/entity [:block/name "page 1"]))))
|
||||
(is (false? (model/hidden-page? (db/get-page "page 1"))))
|
||||
(is (true? (model/hidden-page? "$$$test")))
|
||||
(is (true? (model/hidden-page? (str "$$$" (random-uuid)))))))
|
||||
|
||||
|
@ -104,13 +104,13 @@
|
|||
_ (page-handler/create! "class1" opts)
|
||||
_ (page-handler/create! "class2" opts)
|
||||
_ (page-handler/create! "class3" opts)
|
||||
class1 (db/entity [:block/name "class1"])
|
||||
class2 (db/entity [:block/name "class2"])
|
||||
class3 (db/entity [:block/name "class3"])
|
||||
class1 (db/get-page "class1")
|
||||
class2 (db/get-page "class2")
|
||||
class3 (db/get-page "class3")
|
||||
_ (db/transact! [{:db/id (:db/id class2)
|
||||
:class/parent (:db/id class1)}
|
||||
{:db/id (:db/id class3)
|
||||
:class/parent (:db/id class2)}])]
|
||||
(is
|
||||
(= (model/get-class-children repo (:db/id (db/entity [:block/name "class1"])))
|
||||
(= (model/get-class-children repo (:db/id (db/get-page "class1")))
|
||||
[(:db/id class2) (:db/id class3)]))))
|
||||
|
|
|
@ -161,16 +161,16 @@
|
|||
_ (page-handler/create! "class1" opts)
|
||||
_ (page-handler/create! "class2" opts)
|
||||
_ (page-handler/create! "class3" opts)
|
||||
c1 (db/entity [:block/name "class1"])
|
||||
c2 (db/entity [:block/name "class2"])
|
||||
c1 (db/get-page "class1")
|
||||
c2 (db/get-page "class2")
|
||||
c1id (:block/uuid c1)
|
||||
c2id (:block/uuid c2)]
|
||||
|
||||
(testing "Create classes"
|
||||
(are [x y] (= x y)
|
||||
(:block/type (db/entity [:block/name "class1"]))
|
||||
(:block/type (db/get-page "class1"))
|
||||
#{"class"}
|
||||
(:block/type (db/entity [:block/name "class2"]))
|
||||
(:block/type (db/get-page "class2"))
|
||||
#{"class"}))
|
||||
|
||||
(testing "Class add property"
|
||||
|
@ -194,7 +194,7 @@
|
|||
(is (= 2 (count (:block/tags (db/entity [:block/uuid fbid]))))))
|
||||
(testing "Get block's classes properties"
|
||||
;; set c2 as parent of c3
|
||||
(let [c3 (db/entity [:block/name "class3"])]
|
||||
(let [c3 (db/get-page "class3")]
|
||||
(db/transact! [{:db/id (:db/id c3)
|
||||
:class/parent (:db/id c2)}]))
|
||||
(db-property-handler/class-add-property! repo c2id :user.property/property-3)
|
||||
|
|
|
@ -295,7 +295,9 @@
|
|||
-"}])
|
||||
(let [conn (db/get-db test-helper/test-db false)
|
||||
block (->> (d/q '[:find (pull ?b [*])
|
||||
:where [?b :block/content ""] [?b :block/page [:block/name "page1"]]]
|
||||
:where [?b :block/content ""]
|
||||
[?p :block/name "page1"]
|
||||
[?b :block/page ?p]]
|
||||
@conn)
|
||||
ffirst)
|
||||
_ (delete-block @conn block {})
|
||||
|
@ -316,7 +318,9 @@
|
|||
-"}])
|
||||
(let [conn (db/get-db test-helper/test-db false)
|
||||
block (->> (d/q '[:find (pull ?b [*])
|
||||
:where [?b :block/content ""] [?b :block/page [:block/name "page1"]]]
|
||||
:where [?b :block/content ""]
|
||||
[?p :block/name "page1"]
|
||||
[?b :block/page ?p]]
|
||||
@conn)
|
||||
ffirst)
|
||||
_ (delete-block @conn block {:embed? true})
|
||||
|
@ -324,4 +328,4 @@
|
|||
:where [?b :block/content] [(missing? $ ?b :block/pre-block?)]]
|
||||
@conn)
|
||||
(map (comp :block/content first)))]
|
||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted"))))
|
||||
(is (= ["b1" "b2"] updated-blocks) "Block is deleted"))))
|
||||
|
|
|
@ -26,25 +26,25 @@
|
|||
|
||||
(deftest rename-test
|
||||
(testing "Case change"
|
||||
(let [page (db/entity [:block/name "test"])]
|
||||
(let [page (db/get-page "test")]
|
||||
(page-rename "test" "Test")
|
||||
(let [entity (db/entity [:block/name "test"])]
|
||||
(let [entity (db/get-page "test")]
|
||||
(is (= "Test" (:block/original-name entity)))
|
||||
;; db id not changed
|
||||
(is (= (:db/id page) (:db/id entity))))))
|
||||
|
||||
(testing "Name changed"
|
||||
(let [page (db/entity [:block/name "test"])]
|
||||
(let [page (db/get-page "test")]
|
||||
(page-rename "Test" "New name")
|
||||
(let [entity (db/entity [:block/name "new name"])]
|
||||
(let [entity (db/get-page "new name")]
|
||||
(is (= "New name" (:block/original-name entity)))
|
||||
(is (= (:db/id page) (:db/id entity))))))
|
||||
|
||||
;; (testing "Merge existing page"
|
||||
;; (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
|
||||
;; (page-rename "New name" "Existing page")
|
||||
;; (let [e1 (db/entity [:block/name "new name"])
|
||||
;; e2 (db/entity [:block/name "existing page"])]
|
||||
;; (let [e1 (db/get-page "new name")
|
||||
;; e2 (db/get-page "existing page")]
|
||||
;; ;; Old page deleted
|
||||
;; (is (nil? e1))
|
||||
;; ;; Blocks from both pages have been merged
|
||||
|
@ -56,8 +56,8 @@
|
|||
;; (deftest merge-with-empty-page
|
||||
;; (page-handler/create! "Existing page" {:redirect? false :create-first-block? false})
|
||||
;; (page-rename "Test" "Existing page")
|
||||
;; (let [e1 (db/entity [:block/name "test"])
|
||||
;; e2 (db/entity [:block/name "existing page"])]
|
||||
;; (let [e1 (db/get-page "test")
|
||||
;; e2 (db/get-page "existing page")]
|
||||
;; ;; Old page deleted
|
||||
;; (is (nil? e1))
|
||||
;; ;; Blocks from both pages have been merged
|
||||
|
@ -70,8 +70,8 @@
|
|||
;; (editor-handler/save-block! repo fbid "Block 1 [[Test]]")
|
||||
;; (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
|
||||
;; (page-rename "Test" "Existing page")
|
||||
;; (let [e1 (db/entity [:block/name "test"])
|
||||
;; e2 (db/entity [:block/name "existing page"])]
|
||||
;; (let [e1 (db/get-page "test")
|
||||
;; e2 (db/get-page "existing page")]
|
||||
;; ;; Old page deleted
|
||||
;; (is (nil? e1))
|
||||
;; ;; Blocks from both pages have been merged
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
(let [conn (db/get-db test-helper/test-db false)
|
||||
blocks (get-blocks @conn)
|
||||
;; Update parent block to replace #foo with #bar
|
||||
new-tag-id (:db/id (d/entity @conn [:block/name "bar"]))
|
||||
new-tag-id (:db/id (db/get-page "bar"))
|
||||
modified-blocks (map #(if (= "parent #foo" (:block/content %))
|
||||
(assoc %
|
||||
:block/refs [{:db/id new-tag-id}]
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
{:block/uuid uuid2 :block/content "uuid2-client"
|
||||
:block/left [:block/uuid uuid1]
|
||||
:block/parent [:block/uuid page1-uuid]}]
|
||||
(d/pull @conn '[*] [:block/name page1-name])
|
||||
(ldb/get-page @conn page1-name)
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
(let [ops (gen-ops-fn)]
|
||||
(is (= #{[:move uuid1 page1-uuid]
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
[frontend.worker.rtc.op-mem-layer :as op-mem-layer]
|
||||
[logseq.outliner.core :as outliner-core]
|
||||
[logseq.outliner.transaction :as outliner-tx]
|
||||
[logseq.db :as ldb]
|
||||
[spy.core :as spy]))
|
||||
|
||||
(use-fixtures :each
|
||||
|
@ -48,7 +49,7 @@
|
|||
conn (conn/get-db repo false)]
|
||||
(page-handler/create! "gen-local-ops-test-2--create-page&insert-blocks"
|
||||
{:redirect? false :create-first-block? false})
|
||||
(let [page-block (d/pull @conn '[*] [:block/name "gen-local-ops-test-2--create-page&insert-blocks"])
|
||||
(let [page-block (ldb/get-page @conn "gen-local-ops-test-2--create-page&insert-blocks")
|
||||
[block-uuid1 block-uuid2] (repeatedly random-uuid)]
|
||||
(outliner-tx/transact!
|
||||
{:transact-opts {:repo repo
|
||||
|
@ -97,7 +98,7 @@
|
|||
(<! (timeout 500))
|
||||
(is (= {:block/uuid #uuid "26c4b513-e251-4ce9-a421-364b774eb736"
|
||||
:block/original-name "Push-Data-From-Ws-Test-1"}
|
||||
(select-keys (d/pull @conn '[*] [:block/name "push-data-from-ws-test-1"])
|
||||
(select-keys (ldb/get-page @conn "push-data-from-ws-test-1")
|
||||
[:block/uuid :block/original-name])))
|
||||
(reset)
|
||||
(done))))))
|
||||
|
|
|
@ -93,14 +93,14 @@
|
|||
{:block/uuid uuid4 :block/content "uuid4-block"
|
||||
:block/left [:block/uuid uuid3]
|
||||
:block/parent [:block/uuid uuid1]}]
|
||||
(d/pull @conn '[*] [:block/name "gen-remote-ops-test"])
|
||||
(ldb/get-page @conn "gen-remote-ops-test")
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
|
||||
(op-mem-layer/init-empty-ops-store! repo)
|
||||
(op-mem-layer/add-ops! repo [["move" {:block-uuid (str uuid2) :epoch 1}]
|
||||
["move" {:block-uuid (str uuid4) :epoch 2}]
|
||||
["move" {:block-uuid (str uuid3) :epoch 3}]
|
||||
["update" {:block-uuid (str uuid4) :epoch 4}]])
|
||||
["move" {:block-uuid (str uuid4) :epoch 2}]
|
||||
["move" {:block-uuid (str uuid3) :epoch 3}]
|
||||
["update" {:block-uuid (str uuid4) :epoch 4}]])
|
||||
(let [_ (op-mem-layer/new-branch! repo)
|
||||
r1 (rtc-core/gen-block-uuid->remote-ops repo conn "user-uuid" :n 1)
|
||||
_ (op-mem-layer/rollback! repo)
|
||||
|
@ -137,7 +137,7 @@
|
|||
{:block/uuid uuid2-client :block/content "uuid2-client"
|
||||
:block/left [:block/uuid uuid1-client]
|
||||
:block/parent [:block/uuid page-uuid]}]
|
||||
(d/pull @conn '[*] [:block/name page-name])
|
||||
(ldb/get-page @conn page-name)
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
(testing "apply-remote-move-ops-test1"
|
||||
(let [data-from-ws {:req-id "req-id"
|
||||
|
@ -155,7 +155,7 @@
|
|||
repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
|
||||
(is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))
|
||||
|
||||
|
@ -179,7 +179,7 @@
|
|||
repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-remote uuid2-remote uuid1-client uuid2-client} (set (map :block/uuid page-blocks))))
|
||||
(is (= uuid1-client (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid2-remote])))))
|
||||
(is (= uuid2-remote (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid1-remote]))))))))))
|
||||
|
@ -210,7 +210,7 @@
|
|||
{:block/uuid uuid2-client :block/content "uuid2-client"
|
||||
:block/left [:block/uuid uuid1-client]
|
||||
:block/parent [:block/uuid page-uuid]}]
|
||||
(d/pull @conn '[*] [:block/name page-name])
|
||||
(ldb/get-page @conn page-name)
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
(testing "apply-remote-update-ops-test1"
|
||||
(let [data-from-ws {:req-id "req-id"
|
||||
|
@ -230,7 +230,7 @@
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
|
||||
(is (= [uuid1-client #{"property"}]
|
||||
((juxt (comp :block/uuid :block/link) :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
|
||||
|
@ -253,7 +253,7 @@
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
|
||||
(is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
|
||||
(testing "apply-remote-update-ops-test3"
|
||||
|
@ -270,7 +270,7 @@
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-update-ops repo conn date-formatter update-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-client uuid2-client uuid1-remote} (set (map :block/uuid page-blocks))))
|
||||
(is (= [nil nil] ((juxt :block/link :block/type) (d/entity @conn [:block/uuid uuid1-remote])))))))
|
||||
(testing "update-attr :block/tags"
|
||||
|
@ -317,7 +317,7 @@
|
|||
{:block/uuid uuid2-client :block/content "uuid2-client"
|
||||
:block/left [:block/uuid uuid1-client]
|
||||
:block/parent [:block/uuid page-uuid]}]
|
||||
(d/pull @conn '[*] [:block/name page-name])
|
||||
(ldb/get-page @conn page-name)
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
(testing "apply-remote-remove-ops-test1"
|
||||
(let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
|
||||
|
@ -330,7 +330,7 @@
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1-client uuid2-client} (set (map :block/uuid page-blocks)))))))
|
||||
(testing "apply-remote-remove-ops-test2"
|
||||
(let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
|
||||
|
@ -342,7 +342,7 @@
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid2-client} (set (map :block/uuid page-blocks)))))))))
|
||||
|
||||
(deftest apply-remote-remove-ops-test2
|
||||
|
@ -384,7 +384,7 @@ server: ;; remove 2
|
|||
{:block/uuid uuid3 :block/content "3"
|
||||
:block/left [:block/uuid uuid2]
|
||||
:block/parent [:block/uuid uuid2]}]
|
||||
(d/pull @conn '[*] [:block/name page-name])
|
||||
(ldb/get-page @conn page-name)
|
||||
{:sibling? false :keep-uuid? true}))
|
||||
(let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
|
||||
:affected-blocks
|
||||
|
@ -396,7 +396,7 @@ server: ;; remove 2
|
|||
(#'rtc-core/affected-blocks->diff-type-ops repo (:affected-blocks data-from-ws))))]
|
||||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-remove-ops repo conn date-formatter remove-ops)
|
||||
(let [page-blocks (ldb/get-page-blocks @conn page-name {})]
|
||||
(let [page-blocks (ldb/get-page-blocks @conn (:db/id (ldb/get-page @conn page-name)) {})]
|
||||
(is (= #{uuid1 uuid3} (set (map :block/uuid page-blocks))))
|
||||
(is (= page-uuid (:block/uuid (:block/left (d/entity @conn [:block/uuid uuid3]))))))))))
|
||||
|
||||
|
@ -473,7 +473,7 @@ server: ;; remove 2
|
|||
:block/content "uuid2-client"
|
||||
:block/left [:block/uuid uuid1-client]
|
||||
:block/parent [:block/uuid page1-uuid]}]
|
||||
(d/pull @conn '[*] [:block/name page-name])
|
||||
(ldb/get-page @conn page-name)
|
||||
{:sibling? true :keep-uuid? true}))
|
||||
(let [data-from-ws {:req-id "req-id" :t 1 :t-before 0
|
||||
:affected-blocks
|
||||
|
@ -497,6 +497,7 @@ server: ;; remove 2
|
|||
(is (rtc-const/data-from-ws-validator data-from-ws))
|
||||
(rtc-core/apply-remote-update-page-ops repo conn date-formatter update-page-ops)
|
||||
(rtc-core/apply-remote-move-ops repo conn date-formatter move-ops)
|
||||
(is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
|
||||
(set (map :block/uuid (ldb/get-page-blocks @conn page-name {})))))
|
||||
(is (= page2-uuid (:block/uuid (d/entity @conn [:block/name page-name])))))))
|
||||
(let [page (ldb/get-page @conn page-name)]
|
||||
(is (= #{uuid1-client uuid2-client uuid1-remote uuid2-remote}
|
||||
(set (map :block/uuid (ldb/get-page-blocks @conn (:db/id page) {})))))
|
||||
(is (= page2-uuid (:block/uuid page)))))))
|
||||
|
|
Loading…
Reference in New Issue