mirror of https://github.com/logseq/logseq
enhance: allow class pages to be deleted if unused
parent
19be2850ff
commit
e7423f93ac
|
@ -26,7 +26,9 @@
|
||||||
(page-handler/delete! page-name
|
(page-handler/delete! page-name
|
||||||
(fn []
|
(fn []
|
||||||
(notification/show! (str "Page " page-name " was deleted successfully!")
|
(notification/show! (str "Page " page-name " was deleted successfully!")
|
||||||
:success)))
|
:success))
|
||||||
|
{:error-handler (fn [{:keys [msg]}]
|
||||||
|
(notification/show! msg :error))})
|
||||||
(state/close-modal!)
|
(state/close-modal!)
|
||||||
(route-handler/redirect-to-home!))
|
(route-handler/redirect-to-home!))
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,16 @@
|
||||||
(conn/get-db repo)
|
(conn/get-db repo)
|
||||||
(util/page-name-sanity-lc tag-name))))
|
(util/page-name-sanity-lc tag-name))))
|
||||||
|
|
||||||
|
(defn get-tag-blocks
|
||||||
|
[repo tag-name]
|
||||||
|
(d/q '[:find ?b
|
||||||
|
:in $ ?tag
|
||||||
|
:where
|
||||||
|
[?e :block/name ?tag]
|
||||||
|
[?b :block/tags ?e]]
|
||||||
|
(conn/get-db repo)
|
||||||
|
(util/page-name-sanity-lc tag-name)))
|
||||||
|
|
||||||
(defn get-all-tagged-pages
|
(defn get-all-tagged-pages
|
||||||
[repo]
|
[repo]
|
||||||
(d/q '[:find ?page-name ?tag
|
(d/q '[:find ?page-name ?tag
|
||||||
|
|
|
@ -476,11 +476,23 @@
|
||||||
refs)]
|
refs)]
|
||||||
tx-data)))))
|
tx-data)))))
|
||||||
|
|
||||||
|
(defn- page-unable-to-delete
|
||||||
|
"If a page is unable to delete, returns a map with more information. Otherwise returns nil"
|
||||||
|
[repo page]
|
||||||
|
(cond
|
||||||
|
(and (= "class" (:block/type page))
|
||||||
|
(seq (model/get-tag-blocks repo (:block/name page))))
|
||||||
|
{:msg "Unable to delete this page because blocks are tagged with this page"}
|
||||||
|
(= "property" (:block/type page))
|
||||||
|
{:msg "Unable to delete this page because this page is a property"}))
|
||||||
|
|
||||||
(defn delete!
|
(defn delete!
|
||||||
[page-name ok-handler & {:keys [delete-file? redirect-to-home? persist-op?]
|
"Deletes a page and then either calls the ok-handler or the error-handler if unable to delete"
|
||||||
|
[page-name ok-handler & {:keys [delete-file? redirect-to-home? persist-op? error-handler]
|
||||||
:or {delete-file? true
|
:or {delete-file? true
|
||||||
redirect-to-home? true
|
redirect-to-home? true
|
||||||
persist-op? true}}]
|
persist-op? true
|
||||||
|
error-handler (fn [{:keys [msg]}] (log/error :msg msg))}}]
|
||||||
(when redirect-to-home? (route-handler/redirect-to-home!))
|
(when redirect-to-home? (route-handler/redirect-to-home!))
|
||||||
(when page-name
|
(when page-name
|
||||||
(when-let [repo (state/get-current-repo)]
|
(when-let [repo (state/get-current-repo)]
|
||||||
|
@ -490,14 +502,14 @@
|
||||||
(fn [block]
|
(fn [block]
|
||||||
[:db.fn/retractEntity [:block/uuid (:block/uuid block)]])
|
[:db.fn/retractEntity [:block/uuid (:block/uuid block)]])
|
||||||
blocks)
|
blocks)
|
||||||
page (db/entity [:block/name page-name])
|
page (db/entity [:block/name page-name])]
|
||||||
_ (delete-file! repo page-name delete-file?)
|
(if-let [msg (and (config/db-based-graph? repo)
|
||||||
|
(page-unable-to-delete repo page))]
|
||||||
|
(error-handler msg)
|
||||||
|
(let [_ (delete-file! repo page-name delete-file?)
|
||||||
;; if other page alias this pagename,
|
;; if other page alias this pagename,
|
||||||
;; then just remove some attrs of this entity instead of retractEntity
|
;; then just remove some attrs of this entity instead of retractEntity
|
||||||
delete-page-tx (cond
|
delete-page-tx (cond
|
||||||
(contains? #{"property" "class"} (:block/type page))
|
|
||||||
nil
|
|
||||||
|
|
||||||
(not (:block/_namespace page))
|
(not (:block/_namespace page))
|
||||||
(if (model/get-alias-source-page (state/get-current-repo) page-name)
|
(if (model/get-alias-source-page (state/get-current-repo) page-name)
|
||||||
(when-let [id (:db/id (db/entity [:block/name page-name]))]
|
(when-let [id (:db/id (db/entity [:block/name page-name]))]
|
||||||
|
@ -509,14 +521,15 @@
|
||||||
|
|
||||||
:else
|
:else
|
||||||
nil)
|
nil)
|
||||||
|
_ (prn :PTX delete-page-tx)
|
||||||
|
_ (prn :BTX truncate-blocks-tx-data)
|
||||||
tx-data (concat truncate-blocks-tx-data delete-page-tx)]
|
tx-data (concat truncate-blocks-tx-data delete-page-tx)]
|
||||||
|
|
||||||
(db/transact! repo tx-data {:outliner-op :delete-page :persist-op? persist-op?})
|
(db/transact! repo tx-data {:outliner-op :delete-page :persist-op? persist-op?})
|
||||||
|
|
||||||
(unfavorite-page! page-name)
|
(unfavorite-page! page-name)
|
||||||
|
|
||||||
(when (fn? ok-handler) (ok-handler))
|
(when (fn? ok-handler) (ok-handler))
|
||||||
(ui-handler/re-render-root!)))))
|
(ui-handler/re-render-root!)))))))
|
||||||
|
|
||||||
(defn- rename-update-block-refs!
|
(defn- rename-update-block-refs!
|
||||||
[refs from-id to-id]
|
[refs from-id to-id]
|
||||||
|
|
Loading…
Reference in New Issue