Skip to content

Commit

Permalink
Shows the time spent for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Oct 22, 2020
1 parent 2710cba commit 0d26419
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
26 changes: 22 additions & 4 deletions web/src/main/frontend/components/hiccup.cljs
Expand Up @@ -943,7 +943,8 @@

(rum/defc properties-cp
[block]
(let [properties (apply dissoc (:block/properties block) text/hidden-properties)]
(let [properties (apply dissoc (:block/properties block) text/hidden-properties)
properties (apply dissoc properties config/markers)]
(when (seq properties)
[:div.text-sm.opacity-80.my-1.bg-base-4.p-2
(for [[k v] properties]
Expand Down Expand Up @@ -987,7 +988,7 @@
(datetime-comp/date-picker nil nil ts)]))]))

(rum/defc block-content < rum/reactive
[config {:block/keys [uuid title level body meta content dummy? page format repo children pre-block? properties collapsed? idx block-refs-count scheduled scheduled-ast deadline deadline-ast repeated?] :as block} edit-input-id block-id slide?]
[config {:block/keys [uuid title level body meta content marker dummy? page format repo children pre-block? properties collapsed? idx block-refs-count scheduled scheduled-ast deadline deadline-ast repeated?] :as block} edit-input-id block-id slide?]
(let [dragging? (rum/react *dragging?)
attrs {:blockid (str uuid)
;; FIXME: Click to copy a selection instead of click first and then copy
Expand Down Expand Up @@ -1031,7 +1032,7 @@
(reset! *dragging? false)
(reset! *dragging-block nil)
(editor-handler/unhighlight-block!))}]
[:div.flex.overflow-x-auto.overflow-y-hidden
[:div.flex.overflow-x-auto.overflow-y-hidden.relative
[:div.flex-1.flex-col.relative.block-content
(cond-> {:id (str "block-content-" uuid)
:style {:cursor "text"
Expand Down Expand Up @@ -1076,7 +1077,24 @@
(:db/id block)
:block-ref
{:block block}))}
block-refs-count]])]))
block-refs-count]])

(when (= marker "DONE")
(let [start-time (or
(get properties "now")
(get properties "doing")
(get properties "in-progress")
(get properties "later")
(get properties "todo"))
finish-time (get properties "done")]
(when (and start-time finish-time (> finish-time start-time))
[:div.text-sm.absolute.spent-time {:style {:top 0
:right 0
:z-index 4
:background "#002B36"}
:title (str (date/int->local-time start-time) " ~ " (date/int->local-time finish-time))}
[:span.opacity-70
(utils/timeConversion (- finish-time start-time))]])))]))

(rum/defc block-content-or-editor < rum/reactive
[config {:block/keys [uuid title level body meta content dummy? page format repo children pre-block? collapsed? idx] :as block} edit-input-id block-id slide?]
Expand Down
4 changes: 4 additions & 0 deletions web/src/main/frontend/config.cljs
Expand Up @@ -258,3 +258,7 @@
(def config-default-content
"
{:journal-basis \"daily\" \n\n :project {\n ;; Selected public notes can be published to https://logseq.com/your-project-or-your-username.\n :name \"\"\n :alias \"\"\n ;; your twitter handle\n :twitter \"\"\n ;; description supports both hiccup and html\n :description \"\"}\n\n ;; Currently, we support either \"Markdown\" or \"Org\".\n ;; This can overwrite your global preference so that\n ;; maybe your personal preferred format is Org but you'd\n ;; need to use Markdown for some projects.\n ;; :preferred-format \"\"\n\n ;; Git settings\n :git-pull-secs 60\n :git-push-secs 10\n :git-auto-push true\n\n ;; The app will ignore those directories or files.\n ;; E.g. \"/archived\" \"/test.md\"\n :hidden []\n\n ;; When creating the new journal page, the app will use your template content here.\n ;; Example for Markdown users: \"## [[Work]]\\n###\\n## [[Family]]\\n###\\n\n ;; Example for Org mode users: \"** [[Work]]\\n***\\n** [[Family]]\\n***\\n\n :default-templates\n {:journals \"\"}\n\n ;; The app will show those queries in today's journal page,\n ;; the \"NOW\" query asks the tasks which need to be finished \"now\",\n ;; the \"NEXT\" query asks the future tasks.\n :default-queries\n {:journals\n [{:title \"🔨 NOW\"\n :query [:find (pull ?h [*])\n :in $ ?start ?today\n :where\n [?h :block/marker ?marker]\n [?h :block/page ?p]\n [?p :page/journal? true]\n [?p :page/journal-day ?d]\n [(>= ?d ?start)]\n [(<= ?d ?today)]\n [(contains? #{\"NOW\" \"DOING\"} ?marker)]]\n :inputs [:14d :today]\n :result-transform (fn [result]\n (sort-by (fn [h]\n (get h :block/priority \"Z\")) result))\n :collapsed? false}\n {:title \"📅 NEXT\"\n :query [:find (pull ?h [*])\n :in $ ?start ?next\n :where\n [?h :block/marker ?marker]\n [?h :block/ref-pages ?p]\n [?p :page/journal? true]\n [?p :page/journal-day ?d]\n [(> ?d ?start)]\n [(< ?d ?next)]\n [(contains? #{\"NOW\" \"LATER\" \"TODO\"} ?marker)]]\n :inputs [:today :7d-after]\n :collapsed? false}]}\n\n ;; Add your own commands to speedup.\n ;; E.g. [[\"js\" \"Javascript\"]]\n :commands\n []\n\n ;; Macros replace texts and will make you more productive.\n ;; For example:\n ;; Add this to the macros below:\n ;; {\"poem\" \"Rose is $1, violet's $2. Life's ordered: Org assists you.\"}\n ;; input \"{{{poem(red,blue)}}}\"\n ;; becomes\n ;; Rose is red, violet's blue. Life's ordered: Org assists you.\n :macros {}}\n")
(def markers
#{"now" "later" "todo" "doing" "done" "wait" "waiting"
"canceled" "cancelled" "started" "in-progress"})
4 changes: 4 additions & 0 deletions web/src/main/frontend/date.cljs
Expand Up @@ -184,6 +184,10 @@
[journal-title]
(journal-title-> journal-title format))

(defn int->local-time
[n]
(get-date-time-string (t/to-default-time-zone (tc/from-long n))))

(comment
(def default-formatter (tf/formatter "MMM do, yyyy"))
(def zh-formatter (tf/formatter "YYYY年MM月dd日"))
Expand Down
5 changes: 5 additions & 0 deletions web/src/main/frontend/db.cljs
Expand Up @@ -2461,6 +2461,11 @@
datoms (d/datoms filtered-db :eavt)]
@(d/conn-from-datoms datoms db-schema/schema)))))

;; shortcut for query a block with string ref
(defn qb
[string-id]
(pull [:block/uuid (medley/uuid string-id)]))

(comment
(defn debug!
[]
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/frontend/format.cljs
Expand Up @@ -62,4 +62,4 @@
(protocol/loaded? record)))

(def marker-pattern
#"^(NOW|LATER|TODO|DOING|DONE|WAIT|WAITING|CANCELED|STARTED|IN-PROGRESS)?\s?")
#"^(NOW|LATER|TODO|DOING|DONE|WAIT|WAITING|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
23 changes: 15 additions & 8 deletions web/src/main/frontend/format/block.cljs
Expand Up @@ -9,7 +9,8 @@
[datascript.core :as d]
[clojure.set :as set]
[frontend.date :as date]
[frontend.format.mldoc :as mldoc]))
[frontend.format.mldoc :as mldoc]
[medley.core :as medley]))

(defn heading-block?
[block]
Expand Down Expand Up @@ -98,13 +99,19 @@

(defn extract-properties
[[_ properties] start-pos end-pos]
{:properties (->> (into {} properties)
(medley/map-keys (fn [k]
(and k (string/trim (string/lower-case k)))))
(medley/map-vals (fn [v]
(and v (string/trim v)))))
:start-pos start-pos
:end-pos end-pos})
(let [properties (->> (into {} properties)
(medley/map-kv (fn [k v]
(let [k' (and k (string/trim (string/lower-case k)))
v' (and v (string/trim v))
v' (if (and k' v'
(contains? config/markers k')
(util/safe-parse-int v'))
(util/safe-parse-int v')
v')]
[k' v']))))]
{:properties properties
:start-pos start-pos
:end-pos end-pos}))

(defn- paragraph-timestamp-block?
[block]
Expand Down
7 changes: 7 additions & 0 deletions web/src/main/frontend/util.cljs
Expand Up @@ -184,6 +184,13 @@
(js/parseInt x)
x))

(defn safe-parse-int
[x]
(let [result (parse-int x)]
(if (js/isNaN result)
nil
result)))

(defn debounce
"Returns a function that will call f only after threshold has passed without new calls
to the function. Calls prep-fn on the args in a sync way, which can be used for things like
Expand Down
18 changes: 18 additions & 0 deletions web/src/main/frontend/utils.js
Expand Up @@ -36,3 +36,21 @@ export var focus = function( elem ) {
document.hasFocus() &&
!!( elem.type || elem.href || ~elem.tabIndex );
}

// copied from https://stackoverflow.com/a/32180863
export var timeConversion = function (millisec) {
var seconds = (millisec / 1000).toFixed(1);
var minutes = (millisec / (1000 * 60)).toFixed(1);
var hours = (millisec / (1000 * 60 * 60)).toFixed(1);
var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(1);

if (seconds < 60) {
return seconds + "s";
} else if (minutes < 60) {
return minutes + "m";
} else if (hours < 24) {
return hours + "h";
} else {
return days + "d"
}
}

0 comments on commit 0d26419

Please sign in to comment.