mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 08:26:40 +00:00
refactor: use <invoke-db-worker to replace @*db-worker
This commit is contained in:
@@ -13,59 +13,55 @@
|
||||
(defn ^:export export-block-data []
|
||||
;; Use editor state to locate most recent block
|
||||
(if-let [block-uuid (:block-id (first (state/get-editor-args)))]
|
||||
(when-let [worker @state/*db-worker]
|
||||
(p/let [result (worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :block :block-id [:block/uuid block-uuid]})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied block's data!" :success)))
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :block :block-id [:block/uuid block-uuid]})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied block's data!" :success))
|
||||
|
||||
(notification/show! "No block found" :warning)))
|
||||
|
||||
(defn export-view-nodes-data [nodes]
|
||||
(let [block-uuids (mapv #(vector :block/uuid (:block/uuid %)) nodes)]
|
||||
(when-let [worker @state/*db-worker]
|
||||
(p/let [result (worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :view-nodes :node-ids block-uuids})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied block's data!" :success)))))
|
||||
|
||||
(defn ^:export export-page-data []
|
||||
(if-let [page-id (page-util/get-current-page-id)]
|
||||
(when-let [worker @state/*db-worker]
|
||||
(p/let [result (worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :page :page-id page-id})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied page's data!" :success)))
|
||||
(notification/show! "No page found" :warning)))
|
||||
|
||||
(defn ^:export export-graph-ontology-data []
|
||||
(when-let [worker @state/*db-worker]
|
||||
(p/let [result (worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :graph-ontology})
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :view-nodes :node-ids block-uuids})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(js/console.log (str "Exported " (count (:classes result)) " classes and "
|
||||
(count (:properties result)) " properties"))
|
||||
(notification/show! "Copied graphs's ontology data!" :success))))
|
||||
(notification/show! "Copied block's data!" :success))))
|
||||
|
||||
(defn ^:export export-page-data []
|
||||
(if-let [page-id (page-util/get-current-page-id)]
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :page :page-id page-id})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied page's data!" :success))
|
||||
(notification/show! "No page found" :warning)))
|
||||
|
||||
(defn ^:export export-graph-ontology-data []
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :graph-ontology})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(js/console.log (str "Exported " (count (:classes result)) " classes and "
|
||||
(count (:properties result)) " properties"))
|
||||
(notification/show! "Copied graphs's ontology data!" :success)))
|
||||
|
||||
(defn- export-graph-edn-data []
|
||||
(when-let [worker @state/*db-worker]
|
||||
(p/let [result (worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :graph
|
||||
:graph-options {:include-timestamps? true}})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
pull-data)))
|
||||
(p/let [result (state/<invoke-db-worker :thread-api/export-edn
|
||||
(state/get-current-repo)
|
||||
{:export-type :graph
|
||||
:graph-options {:include-timestamps? true}})
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
pull-data))
|
||||
|
||||
;; Copied from handler.export
|
||||
(defn- file-name [repo extension]
|
||||
|
||||
Reference in New Issue
Block a user