mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
enhance: add export edn graph as file
Remove command version of export which is a less useful dev tool than what's possible with cli
This commit is contained in:
@@ -102,6 +102,7 @@
|
||||
frontend.handler.common.plugin plugin-common-handler
|
||||
frontend.handler.config config-handler
|
||||
frontend.handler.db-based.editor db-editor-handler
|
||||
frontend.handler.db-based.export db-export-handler
|
||||
frontend.handler.db-based.page db-page-handler
|
||||
frontend.handler.db-based.property db-property-handler
|
||||
frontend.handler.db-based.property.util db-pu
|
||||
|
||||
@@ -1072,6 +1072,7 @@
|
||||
[:a#download-as-json-v2.hidden]
|
||||
[:a#download-as-transit-debug.hidden]
|
||||
[:a#download-as-sqlite-db.hidden]
|
||||
[:a#download-as-db-edn.hidden]
|
||||
[:a#download-as-roam-json.hidden]
|
||||
[:a#download-as-html.hidden]
|
||||
[:a#download-as-zip.hidden]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[frontend.config :as config]
|
||||
[frontend.context.i18n :refer [t]]
|
||||
[frontend.db :as db]
|
||||
[frontend.handler.db-based.export :as db-export-handler]
|
||||
[frontend.handler.export :as export]
|
||||
[frontend.handler.export.html :as export-html]
|
||||
[frontend.handler.export.opml :as export-opml]
|
||||
@@ -100,6 +101,10 @@
|
||||
[:div
|
||||
[:a.font-medium {:on-click #(export/export-repo-as-zip! current-repo)}
|
||||
(t :export-zip)]])
|
||||
(when db-based?
|
||||
[:div
|
||||
[:a.font-medium {:on-click #(db-export-handler/export-repo-as-db-edn! current-repo)}
|
||||
(t :export-db-edn)]])
|
||||
(when db-based?
|
||||
[:div
|
||||
[:a.font-medium {:on-click #(export/export-repo-as-debug-transit! current-repo)}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
"Handles DB graph exports and imports across graphs"
|
||||
(:require [cljs.pprint :as pprint]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.string :as string]
|
||||
[frontend.config :as config]
|
||||
[frontend.db :as db]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.ui :as ui-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[frontend.util.page :as page-util]
|
||||
[goog.dom :as gdom]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.sqlite.export :as sqlite-export]
|
||||
[logseq.shui.ui :as shui]
|
||||
@@ -61,14 +64,35 @@
|
||||
(count (:properties result)) " properties"))
|
||||
(notification/show! "Copied graphs's ontology data!" :success))))
|
||||
|
||||
(defn ^:export export-graph-data []
|
||||
(defn- export-graph-edn-data []
|
||||
(when-let [^Object worker @state/*db-worker]
|
||||
(p/let [result* (.export-edn worker (state/get-current-repo) (ldb/write-transit-str {:export-type :graph}))
|
||||
(p/let [result* (.export-edn worker
|
||||
(state/get-current-repo)
|
||||
(ldb/write-transit-str {:export-type :graph
|
||||
:graph-options {:include-timestamps? true}}))
|
||||
result (ldb/read-transit-str result*)
|
||||
pull-data (with-out-str (pprint/pprint result))]
|
||||
(.writeText js/navigator.clipboard pull-data)
|
||||
(println pull-data)
|
||||
(notification/show! "Copied graphs's data!" :success))))
|
||||
pull-data)))
|
||||
|
||||
;; Copied from handler.export
|
||||
(defn- file-name [repo extension]
|
||||
(-> (string/replace repo config/local-db-prefix "")
|
||||
(string/replace #"^/+" "")
|
||||
(str "_" (quot (util/time-ms) 1000))
|
||||
(str "." (string/lower-case (name extension)))))
|
||||
|
||||
(defn export-repo-as-db-edn!
|
||||
[repo]
|
||||
(p/let [edn-str (export-graph-edn-data)]
|
||||
(when edn-str
|
||||
(let [data-str (some->> edn-str
|
||||
js/encodeURIComponent
|
||||
(str "data:text/edn;charset=utf-8,"))
|
||||
filename (file-name repo :edn)]
|
||||
(when-let [anchor (gdom/getElement "download-as-db-edn")]
|
||||
(.setAttribute anchor "href" data-str)
|
||||
(.setAttribute anchor "download" filename)
|
||||
(.click anchor))))))
|
||||
|
||||
(defn- import-submit [import-inputs _e]
|
||||
(let [export-map (try (edn/read-string (:import-data @import-inputs)) (catch :default _err ::invalid-import))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
(ns frontend.handler.db-based.import
|
||||
"Handles DB graph imports"
|
||||
(:require [clojure.edn :as edn]
|
||||
[frontend.config :as config]
|
||||
[frontend.db :as db]
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
[frontend.extensions.zip :as zip]
|
||||
[frontend.external.roam-export :as roam-export]
|
||||
[frontend.handler.assets :as assets-handler]
|
||||
;; Loads commands
|
||||
[frontend.handler.db-based.export]
|
||||
[frontend.handler.export.common :as export-common-handler]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.idb :as idb]
|
||||
|
||||
@@ -625,10 +625,6 @@
|
||||
:db-graph? true
|
||||
:fn :frontend.handler.db-based.export/export-graph-ontology-data}
|
||||
|
||||
:misc/export-graph-data {:binding []
|
||||
:db-graph? true
|
||||
:fn :frontend.handler.db-based.export/export-graph-data}
|
||||
|
||||
:misc/import-edn-data {:binding []
|
||||
:db-graph? true
|
||||
:fn :frontend.handler.db-based.export/import-edn-data}
|
||||
@@ -651,8 +647,9 @@
|
||||
[keyword-fn]
|
||||
(fn []
|
||||
(if-let [resolved-fn (some-> (namespace keyword-fn)
|
||||
;; export is reserved word
|
||||
;; handle reserved words
|
||||
(string/replace-first ".export" ".export$")
|
||||
(string/replace-first ".import" ".import$")
|
||||
find-ns-obj
|
||||
(aget (munge (name keyword-fn))))]
|
||||
(resolved-fn)
|
||||
@@ -855,7 +852,6 @@
|
||||
:sidebar/close-top
|
||||
:misc/export-block-data
|
||||
:misc/export-page-data
|
||||
:misc/export-graph-data
|
||||
:misc/export-graph-ontology-data
|
||||
:misc/import-edn-data
|
||||
:dev/show-block-data
|
||||
@@ -1048,7 +1044,6 @@
|
||||
:git/commit
|
||||
:misc/export-block-data
|
||||
:misc/export-page-data
|
||||
:misc/export-graph-data
|
||||
:misc/export-graph-ontology-data
|
||||
:misc/import-edn-data
|
||||
:dev/show-block-data
|
||||
|
||||
@@ -462,6 +462,7 @@
|
||||
:export-opml "Export as OPML"
|
||||
:export-public-pages "Export public pages"
|
||||
:export-json "Export as JSON"
|
||||
:export-db-edn "Export EDN file"
|
||||
:export-sqlite-db "Export SQLite DB"
|
||||
:export-zip "Export both SQLite DB and assets"
|
||||
:export-roam-json "Export as Roam JSON"
|
||||
@@ -795,7 +796,6 @@
|
||||
:git/commit "Create git commit with message"
|
||||
:misc/export-block-data "Export block EDN data"
|
||||
:misc/export-page-data "Export page EDN data"
|
||||
:misc/export-graph-data "Export graph's EDN data"
|
||||
:misc/export-graph-ontology-data "Export graph's tags and properties EDN data"
|
||||
:misc/import-edn-data "Import EDN data"
|
||||
:dev/show-block-data "(Dev) Show block data"
|
||||
|
||||
Reference in New Issue
Block a user