mirror of https://github.com/logseq/logseq
Add timestamp properties when setting a block marker
parent
ddb5bc0b08
commit
2710cbac06
|
@ -1,6 +1,7 @@
|
|||
(ns frontend.commands
|
||||
(:require [frontend.util :as util]
|
||||
[frontend.date :as date]
|
||||
[frontend.text :as text]
|
||||
[frontend.state :as state]
|
||||
[frontend.search :as search]
|
||||
[clojure.string :as string]
|
||||
|
@ -350,7 +351,10 @@
|
|||
new-value (str (subs edit-content 0 pos)
|
||||
(string/replace-first (subs edit-content pos)
|
||||
format/marker-pattern
|
||||
(str marker " ")))]
|
||||
(str marker " ")))
|
||||
new-value (if (string/blank? marker)
|
||||
new-value
|
||||
(text/insert-property new-value marker (util/time-ms)))]
|
||||
(state/set-edit-content! input-id new-value)))))
|
||||
|
||||
(defmethod handle-step :editor/set-priority [[_ priority] format]
|
||||
|
|
|
@ -791,50 +791,63 @@
|
|||
content))
|
||||
content))
|
||||
|
||||
(defn- with-marker-time
|
||||
[block marker]
|
||||
(let [properties (:block/properties block)]
|
||||
(assoc (into {} properties)
|
||||
(string/lower-case marker)
|
||||
(util/time-ms))))
|
||||
|
||||
(defn check
|
||||
[{:block/keys [uuid marker content meta file dummy? repeated?] :as block}]
|
||||
(let [new-content (string/replace-first content marker "DONE")
|
||||
new-content (if repeated?
|
||||
(update-timestamps-content! block content)
|
||||
new-content)]
|
||||
(save-block-if-changed! block new-content)))
|
||||
(save-block-if-changed! block new-content
|
||||
{:custom-properties (with-marker-time block "DONE")})))
|
||||
|
||||
(defn uncheck
|
||||
[{:block/keys [uuid marker content meta file dummy?] :as block}]
|
||||
(let [new-content (string/replace-first content "DONE"
|
||||
(if (= :now (state/get-preferred-workflow))
|
||||
"LATER"
|
||||
"TODO"))]
|
||||
(save-block-if-changed! block new-content)))
|
||||
(let [marker (if (= :now (state/get-preferred-workflow))
|
||||
"LATER"
|
||||
"TODO")
|
||||
new-content (string/replace-first content "DONE" marker)]
|
||||
(save-block-if-changed! block new-content
|
||||
{:custom-properties (with-marker-time block marker)})))
|
||||
|
||||
(defn cycle-todo!
|
||||
[]
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(let [edit-input-id (state/get-edit-input-id)
|
||||
content (state/get-edit-content)
|
||||
new-content (->
|
||||
(cond
|
||||
(util/starts-with? content "TODO")
|
||||
(string/replace-first content "TODO" "DOING")
|
||||
(util/starts-with? content "DOING")
|
||||
(string/replace-first content "DOING" "DONE")
|
||||
(util/starts-with? content "LATER")
|
||||
(string/replace-first content "LATER" "NOW")
|
||||
(util/starts-with? content "NOW")
|
||||
(string/replace-first content "NOW" "DONE")
|
||||
(util/starts-with? content "DONE")
|
||||
(string/replace-first content "DONE" "")
|
||||
:else
|
||||
(str (if (= :now (state/get-preferred-workflow))
|
||||
"LATER "
|
||||
"TODO ") (string/triml content)))
|
||||
(string/triml))]
|
||||
[new-content marker] (cond
|
||||
(util/starts-with? content "TODO")
|
||||
[(string/replace-first content "TODO" "DOING") "DOING"]
|
||||
(util/starts-with? content "DOING")
|
||||
[(string/replace-first content "DOING" "DONE") "DONE"]
|
||||
(util/starts-with? content "LATER")
|
||||
[(string/replace-first content "LATER" "NOW") "NOW"]
|
||||
(util/starts-with? content "NOW")
|
||||
[(string/replace-first content "NOW" "DONE") "DONE"]
|
||||
(util/starts-with? content "DONE")
|
||||
[(string/replace-first content "DONE" "") nil]
|
||||
:else
|
||||
(let [marker (if (= :now (state/get-preferred-workflow))
|
||||
"LATER"
|
||||
"TODO")]
|
||||
[(str marker " " (string/triml content)) marker]))
|
||||
new-content (string/triml new-content)
|
||||
new-content (if marker
|
||||
(text/insert-property new-content (string/lower-case marker) (util/time-ms))
|
||||
new-content)]
|
||||
(state/set-edit-content! edit-input-id new-content))))
|
||||
|
||||
(defn set-marker
|
||||
[{:block/keys [uuid marker content meta file dummy?] :as block} new-marker]
|
||||
[{:block/keys [uuid marker content meta file dummy? properties] :as block} new-marker]
|
||||
(let [new-content (string/replace-first content marker new-marker)]
|
||||
(save-block-if-changed! block new-content)))
|
||||
(save-block-if-changed! block new-content
|
||||
(with-marker-time block marker))))
|
||||
|
||||
(defn set-priority
|
||||
[{:block/keys [uuid marker priority content meta file dummy?] :as block} new-priority]
|
||||
|
|
|
@ -85,3 +85,38 @@
|
|||
content
|
||||
(-> (remove-properties! content)
|
||||
(rejoin-properties properties))))
|
||||
|
||||
(defn insert-property
|
||||
[content key value]
|
||||
(when (and (not (string/blank? key))
|
||||
(not (string/blank? value)))
|
||||
(let [key (string/lower-case key)
|
||||
[title body] (util/safe-split-first "\n" content)]
|
||||
(if-not (contains-properties? content)
|
||||
(let [properties (build-properties-str {key value})]
|
||||
(str title "\n" properties body))
|
||||
(let [lines (string/split-lines content)
|
||||
[title-lines properties-and-body] (split-with (fn [l] (not (string/starts-with? (string/upper-case (string/triml l)) ":PROPERTIES:"))) lines)
|
||||
properties? (fn [l]
|
||||
(or
|
||||
(string/starts-with? (string/triml l) ":") ; kv
|
||||
(string/starts-with? (string/upper-case (string/triml l)) ":end:")))
|
||||
properties (take-while properties? properties-and-body)
|
||||
exists? (atom false)
|
||||
new-line (util/format ":%s: %s" key value)
|
||||
new-properties (doall
|
||||
(map (fn [l]
|
||||
(if (string/starts-with? (string/triml l) (str ":" key ":"))
|
||||
(do
|
||||
(reset! exists? true)
|
||||
(util/format ":%s: %s" key value))
|
||||
l)) properties))
|
||||
new-properties (if @exists?
|
||||
new-properties
|
||||
(concat
|
||||
(drop-last new-properties)
|
||||
[(util/format ":%s: %s" key value)
|
||||
(last new-properties)]))
|
||||
body (drop-while properties? properties-and-body)]
|
||||
(->> (concat title-lines new-properties body)
|
||||
(string/join "\n")))))))
|
||||
|
|
Loading…
Reference in New Issue