mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
enhance: allow existing page and property to be used as tags
This commit is contained in:
@@ -33,15 +33,16 @@
|
||||
|
||||
(defn add-tag [repo block-id tag-entity]
|
||||
(let [opts {:outliner-op :save-block}]
|
||||
(ui-outliner-tx/transact! opts
|
||||
(p/do!
|
||||
(editor-handler/save-current-block!)
|
||||
;; Check after save-current-block to get most up to date block content
|
||||
(when (valid-tag? repo (db/entity repo [:block/uuid block-id]) tag-entity)
|
||||
(let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
|
||||
;; TODO: Move this to outliner.core to consistently add refs for tags
|
||||
[:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block})))))))
|
||||
(ui-outliner-tx/transact!
|
||||
opts
|
||||
(p/do!
|
||||
(editor-handler/save-current-block!)
|
||||
;; Check after save-current-block to get most up to date block content
|
||||
(when (valid-tag? repo (db/entity repo [:block/uuid block-id]) tag-entity)
|
||||
(let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
|
||||
;; TODO: Move this to outliner.core to consistently add refs for tags
|
||||
[:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block})))))))
|
||||
|
||||
(defn convert-to-tag!
|
||||
[page-entity]
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
[frontend.db.transact]
|
||||
[frontend.db.conn]
|
||||
[logseq.outliner.op]
|
||||
[frontend.modules.outliner.op])))
|
||||
[frontend.modules.outliner.op]
|
||||
[logseq.db])))
|
||||
|
||||
(defmacro transact!
|
||||
[opts & body]
|
||||
|
||||
@@ -169,15 +169,24 @@
|
||||
(let [db @conn
|
||||
date-formatter (:logseq.property.journal/title-format (d/entity db :logseq.class/Journal))
|
||||
title (sanitize-title title*)
|
||||
type (cond class?
|
||||
:logseq.class/Tag
|
||||
whiteboard?
|
||||
:logseq.class/Whiteboard
|
||||
today-journal?
|
||||
:logseq.class/Journal
|
||||
:else
|
||||
:logseq.class/Page)]
|
||||
(when-not (ldb/page-exists? db title #{type})
|
||||
types (cond class?
|
||||
#{:logseq.class/Tag :logseq.class/Property :logseq.class/Page}
|
||||
whiteboard?
|
||||
#{:logseq.class/Whiteboard}
|
||||
today-journal?
|
||||
#{:logseq.class/Journal}
|
||||
:else
|
||||
#{:logseq.class/Page})]
|
||||
(if-let [existing-page-id (first (ldb/page-exists? db title types))]
|
||||
(let [existing-page (d/entity db existing-page-id)
|
||||
tx-meta {:persist-op? persist-op?
|
||||
:outliner-op :save-block}]
|
||||
(when (and class?
|
||||
(not (ldb/class? existing-page))
|
||||
(or (ldb/property? existing-page) (ldb/internal-page? existing-page)))
|
||||
;; convert existing property or page to class
|
||||
(let [tx-data (db-class/build-new-class db (select-keys existing-page [:block/title :block/uuid :db/ident :block/created-at]))]
|
||||
(ldb/transact! conn tx-data tx-meta))))
|
||||
(let [format :markdown
|
||||
page (-> (gp-block/page-name->map title @conn true date-formatter
|
||||
{:class? class?
|
||||
|
||||
Reference in New Issue
Block a user