浏览代码

Remove :block/marker and :block/priority from tx-data

Tienson Qin 1 年之前
父节点
当前提交
a64f49dc6f

+ 13 - 0
deps/common/src/logseq/common/marker.cljs

@@ -0,0 +1,13 @@
+(ns logseq.common.marker
+  "marker patterns"
+  (:require [clojure.string :as string]))
+
+(defn marker-pattern [format]
+  (re-pattern
+   (str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?")
+        "(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?")))
+
+
+(defn clean-marker
+  [content format]
+  (string/replace-first content (marker-pattern format) ""))

+ 37 - 3
deps/outliner/src/logseq/outliner/core.cljs

@@ -17,7 +17,8 @@
             [logseq.db.frontend.property :as db-property]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [cljs.pprint :as pprint]
             [cljs.pprint :as pprint]
-            [logseq.db.frontend.content :as db-content]))
+            [logseq.db.frontend.content :as db-content]
+            [logseq.common.marker :as common-marker]))
 
 
 (def ^:private block-map
 (def ^:private block-map
   (mu/optional-keys
   (mu/optional-keys
@@ -257,6 +258,36 @@
 ;; -get-id, -get-parent-id, -get-left-id return block-id
 ;; -get-id, -get-parent-id, -get-left-id return block-id
 ;; the :block/parent, :block/left should be datascript lookup ref
 ;; the :block/parent, :block/left should be datascript lookup ref
 
 
+;; TODO: don't parse marker and deprecate typing marker to set status
+(defn- db-marker-handle
+  [conn m]
+  (or
+   (let [marker (:block/marker m)
+         property (db-property/get-property @conn "status")
+         matched-status-id (when marker
+                             (->> (get-in property [:block/schema :values])
+                                 (some (fn [id]
+                                         (let [value-e (d/entity @conn [:block/uuid id])
+                                               value (get-in value-e [:block/schema :value])]
+                                           (when (= (string/lower-case marker) (string/lower-case value))
+                                             id))))))]
+     (cond-> m
+       matched-status-id
+       (update :block/properties assoc (:block/uuid property) matched-status-id)
+
+       matched-status-id
+       (update :block/content (fn [content]
+                                (common-marker/clean-marker content (get m :block/format :markdown))))
+       matched-status-id
+       (update :db/other-tx (fn [tx]
+                              (if-let [task (d/entity @conn [:block/name "task"])]
+                                (conj tx [:db/add (:db/id m) :block/tags (:db/id task)])
+                                tx)))
+
+       true
+       (dissoc :block/marker :block/priority)))
+   m))
+
 (extend-type Block
 (extend-type Block
   otree/INode
   otree/INode
   (-get-id [this conn]
   (-get-id [this conn]
@@ -320,7 +351,7 @@
           block-uuid (:block/uuid (:data this))
           block-uuid (:block/uuid (:data this))
           eid (or db-id (when block-uuid [:block/uuid block-uuid]))
           eid (or db-id (when block-uuid [:block/uuid block-uuid]))
           block-entity (d/entity db eid)
           block-entity (d/entity db eid)
-          m (if (and (:block/content m) db-based?)
+          m' (if (and (:block/content m) db-based?)
               (update m :block/content
               (update m :block/content
                       (fn [content]
                       (fn [content]
                         (db-content/content-without-tags
                         (db-content/content-without-tags
@@ -332,7 +363,10 @@
                                (str db-content/page-ref-special-chars (:block/uuid tag))))
                                (str db-content/page-ref-special-chars (:block/uuid tag))))
                            (:block/tags m))
                            (:block/tags m))
                           (remove nil?)))))
                           (remove nil?)))))
-              m)]
+              m)
+          m (cond->> m'
+              db-based?
+              (db-marker-handle conn))]
 
 
       ;; Ensure block UUID never changes
       ;; Ensure block UUID never changes
       (when (and db-id block-uuid)
       (when (and db-id block-uuid)

+ 3 - 5
src/main/frontend/handler/file_based/status.cljs

@@ -1,12 +1,10 @@
 (ns frontend.handler.file-based.status
 (ns frontend.handler.file-based.status
   "Task (formerly todo) related util fns"
   "Task (formerly todo) related util fns"
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
-            [frontend.util :as util]))
+            [frontend.util :as util]
+            [logseq.common.marker :as common-marker]))
 
 
-(defn marker-pattern [format]
-  (re-pattern
-   (str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?")
-        "(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?")))
+(def marker-pattern common-marker/marker-pattern)
 
 
 (def bare-marker-pattern
 (def bare-marker-pattern
   #"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")
   #"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")