mirror of https://github.com/logseq/logseq
Same rendering for agenda headings
parent
2adabbd234
commit
735ceb42a7
|
@ -1,104 +1,22 @@
|
||||||
(ns frontend.components.agenda
|
(ns frontend.components.agenda
|
||||||
(:require [rum.core :as rum]
|
(:require [rum.core :as rum]
|
||||||
[frontend.util :as util]
|
|
||||||
[frontend.handler :as handler]
|
|
||||||
[frontend.format.org.block :as block]
|
[frontend.format.org.block :as block]
|
||||||
[frontend.state :as state]
|
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[frontend.format.org-mode :as org]
|
|
||||||
[frontend.components.sidebar :as sidebar]
|
[frontend.components.sidebar :as sidebar]
|
||||||
[frontend.db :as db]
|
[frontend.components.content :as content]
|
||||||
[frontend.ui :as ui]))
|
[frontend.components.hiccup :as hiccup]
|
||||||
|
[frontend.db :as db]))
|
||||||
(rum/defc timestamps-cp
|
|
||||||
[timestamps]
|
|
||||||
[:ul
|
|
||||||
(for [[type {:keys [date time]}] timestamps]
|
|
||||||
(let [{:keys [year month day]} date
|
|
||||||
{:keys [hour min]} time]
|
|
||||||
[:li {:key type}
|
|
||||||
[:span {:style {:margin-right 6}} type]
|
|
||||||
[:span (if time
|
|
||||||
(str year "-" month "-" day " " hour ":" min)
|
|
||||||
(str year "-" month "-" day))]]))])
|
|
||||||
|
|
||||||
(rum/defc title-cp
|
|
||||||
[title]
|
|
||||||
(let [title-json (js/JSON.stringify (clj->js title))
|
|
||||||
html (org/inline-list->html title-json)]
|
|
||||||
(util/raw-html html)))
|
|
||||||
|
|
||||||
(rum/defc children-cp
|
|
||||||
[children]
|
|
||||||
(let [children-json (js/JSON.stringify (clj->js children))
|
|
||||||
html (org/json->html children-json)]
|
|
||||||
(util/raw-html html)))
|
|
||||||
|
|
||||||
(rum/defc marker-cp
|
|
||||||
[marker]
|
|
||||||
(if marker
|
|
||||||
[:span {:class (str "marker-" (string/lower-case marker))
|
|
||||||
:style {:margin-left 8}}
|
|
||||||
(if (contains? #{"DOING" "IN-PROGRESS"} marker)
|
|
||||||
(str " (" marker ")"))]))
|
|
||||||
|
|
||||||
(rum/defc tags-cp
|
|
||||||
[tags]
|
|
||||||
[:span
|
|
||||||
(for [{:keys [tag/name]} tags]
|
|
||||||
[:span.tag {:key name}
|
|
||||||
[:span
|
|
||||||
name]])])
|
|
||||||
|
|
||||||
(rum/defc agenda
|
(rum/defc agenda
|
||||||
[]
|
[]
|
||||||
(let [tasks (db/get-agenda)]
|
(let [tasks (db/get-agenda)]
|
||||||
(sidebar/sidebar
|
(sidebar/sidebar
|
||||||
[:div#agenda
|
[:div#agenda
|
||||||
[:h2.mb-3 "Agenda"]
|
[:h1.title "Agenda"]
|
||||||
(if (seq tasks)
|
(if (seq tasks)
|
||||||
[:div.ml-1
|
[:div.ml-1
|
||||||
(let [tasks (block/sort-tasks tasks)]
|
(let [tasks (block/sort-tasks tasks)
|
||||||
(for [{:heading/keys [uuid marker title priority level tags children timestamps meta repo file] :as task} tasks]
|
id "agenda"]
|
||||||
[:div.mb-2
|
(content/content id :org
|
||||||
{:key (str "task-" uuid)
|
{:hiccup (hiccup/->hiccup tasks {:id id})}))]
|
||||||
:style {:padding-left 8
|
|
||||||
:padding-right 8}}
|
|
||||||
[:div
|
|
||||||
[:div.flex.flex-row {:style {:align-items "center"}}
|
|
||||||
(case marker
|
|
||||||
(list "DOING" "IN-PROGRESS" "TODO")
|
|
||||||
(ui/checkbox {:on-change (fn [_]
|
|
||||||
;; FIXME: Log timestamp
|
|
||||||
(handler/check task))})
|
|
||||||
|
|
||||||
"WAIT"
|
|
||||||
[:span {:style {:font-weight "bold"}}
|
|
||||||
"WAIT"]
|
|
||||||
|
|
||||||
"DONE"
|
|
||||||
(ui/checkbox {:checked true
|
|
||||||
:on-change (fn [_]
|
|
||||||
;; FIXME: Log timestamp
|
|
||||||
(handler/uncheck task)
|
|
||||||
)})
|
|
||||||
|
|
||||||
nil)
|
|
||||||
[:div.flex.flex-row.ml-2
|
|
||||||
(if priority
|
|
||||||
[:span.priority.mr-1
|
|
||||||
(str "#[" priority "]")])
|
|
||||||
(title-cp title)
|
|
||||||
(marker-cp marker)
|
|
||||||
(when (seq tags)
|
|
||||||
(tags-cp tags))]]
|
|
||||||
(when (seq timestamps)
|
|
||||||
(timestamps-cp timestamps))
|
|
||||||
|
|
||||||
;; FIXME: parse error
|
|
||||||
;; (when (seq children)
|
|
||||||
;; (children-cp children))
|
|
||||||
|
|
||||||
]]
|
|
||||||
))]
|
|
||||||
"Empty")])))
|
"Empty")])))
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[frontend.expand :as expand]
|
[frontend.expand :as expand]
|
||||||
[frontend.components.editor :as editor]
|
[frontend.components.editor :as editor]
|
||||||
[frontend.components.svg :as svg]
|
[frontend.components.svg :as svg]
|
||||||
|
[frontend.ui :as ui]
|
||||||
[frontend.handler :as handler]
|
[frontend.handler :as handler]
|
||||||
[goog.object :as gobj]))
|
[goog.object :as gobj]))
|
||||||
|
|
||||||
|
@ -278,7 +279,8 @@
|
||||||
heading-id (str "ls-heading-parent-" uuid)
|
heading-id (str "ls-heading-parent-" uuid)
|
||||||
collapsed-atom? (get state ::collapsed?)
|
collapsed-atom? (get state ::collapsed?)
|
||||||
toggle-collapsed? (state/sub [:ui/collapsed-headings heading-id])
|
toggle-collapsed? (state/sub [:ui/collapsed-headings heading-id])
|
||||||
collapsed? (or toggle-collapsed? @collapsed-atom?)]
|
collapsed? (or toggle-collapsed? @collapsed-atom?)
|
||||||
|
agenda? (= (:id config) "agenda")]
|
||||||
(let [edit-input-id (str "edit-box-" uuid)]
|
(let [edit-input-id (str "edit-box-" uuid)]
|
||||||
(when-not lock?
|
(when-not lock?
|
||||||
[:div.ls-heading-parent.flex-1 {:key (str uuid)
|
[:div.ls-heading-parent.flex-1 {:key (str uuid)
|
||||||
|
@ -299,25 +301,26 @@
|
||||||
:on-mouse-out (fn []
|
:on-mouse-out (fn []
|
||||||
(when (has-children? heading-id level)
|
(when (has-children? heading-id level)
|
||||||
(reset! control-show? false)))}
|
(reset! control-show? false)))}
|
||||||
[:a.heading-control.pt-1
|
(when-not agenda?
|
||||||
{:id (str "control-" uuid)
|
[:a.heading-control.pt-1
|
||||||
:class "block no-underline text-gray-700 hover:text-gray-700 transition ease-in-out duration-150 mr-1"
|
{:id (str "control-" uuid)
|
||||||
:on-click (fn []
|
:class "block no-underline text-gray-700 hover:text-gray-700 transition ease-in-out duration-150 mr-1"
|
||||||
(let [id (str "ls-heading-parent-" uuid)]
|
:on-click (fn []
|
||||||
(if collapsed?
|
(let [id (str "ls-heading-parent-" uuid)]
|
||||||
(expand/expand! (:id config) id)
|
(if collapsed?
|
||||||
(expand/collapse! (:id config) id))
|
(expand/expand! (:id config) id)
|
||||||
(reset! collapsed-atom? (not collapsed?))))}
|
(expand/collapse! (:id config) id))
|
||||||
(cond
|
(reset! collapsed-atom? (not collapsed?))))}
|
||||||
collapsed?
|
(cond
|
||||||
(svg/caret-right)
|
collapsed?
|
||||||
|
(svg/caret-right)
|
||||||
|
|
||||||
(and @control-show?
|
(and @control-show?
|
||||||
(has-children? heading-id level))
|
(has-children? heading-id level))
|
||||||
(svg/caret-down)
|
(svg/caret-down)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
nil)]
|
nil)])
|
||||||
|
|
||||||
(if @edit?
|
(if @edit?
|
||||||
(editor/box content {:on-hide (fn [value]
|
(editor/box content {:on-hide (fn [value]
|
||||||
|
@ -333,7 +336,8 @@
|
||||||
edit-input-id)
|
edit-input-id)
|
||||||
[:div.flex-1.heading-body
|
[:div.flex-1.heading-body
|
||||||
{:on-click (fn [e]
|
{:on-click (fn [e]
|
||||||
(when-not (util/link? (gobj/get e "target"))
|
(when-not (or (util/link? (gobj/get e "target"))
|
||||||
|
(util/input? (gobj/get e "target")))
|
||||||
(reset! edit? true)
|
(reset! edit? true)
|
||||||
(handler/reset-cursor-range! (gdom/getElement heading-id))
|
(handler/reset-cursor-range! (gdom/getElement heading-id))
|
||||||
(swap! state/state assoc
|
(swap! state/state assoc
|
||||||
|
@ -348,10 +352,33 @@
|
||||||
(rum/with-key (heading-child block)
|
(rum/with-key (heading-child block)
|
||||||
(cljs.core/random-uuid)))))])]]))))
|
(cljs.core/random-uuid)))))])]]))))
|
||||||
|
|
||||||
|
(rum/defc heading-checkbox
|
||||||
|
[heading class]
|
||||||
|
(case (:heading/marker heading)
|
||||||
|
(list "DOING" "IN-PROGRESS" "TODO" "WAIT")
|
||||||
|
(ui/checkbox {:class class
|
||||||
|
:style {:margin-top -2}
|
||||||
|
:on-change (fn [_e]
|
||||||
|
;; FIXME: Log timestamp
|
||||||
|
(handler/check heading))})
|
||||||
|
|
||||||
|
"DONE"
|
||||||
|
(ui/checkbox {:checked true
|
||||||
|
:class class
|
||||||
|
:style {:margin-top -2}
|
||||||
|
:on-change (fn [_e]
|
||||||
|
;; FIXME: Log timestamp
|
||||||
|
(handler/uncheck heading))})
|
||||||
|
|
||||||
|
nil))
|
||||||
|
|
||||||
(defn heading
|
(defn heading
|
||||||
[config {:heading/keys [uuid title tags marker level priority anchor meta numbering children]
|
[config {:heading/keys [uuid title tags marker level priority anchor meta numbering children]
|
||||||
:as t}]
|
:as t}]
|
||||||
(let [marker (if marker
|
(let [agenda? (= (:id config) "agenda")
|
||||||
|
checkbox (heading-checkbox t
|
||||||
|
(str "mr-1 cursor" (when-not agenda? " ml-1")))
|
||||||
|
marker (if (contains? #{"DOING" "IN-PROGRESS" "WAIT"} marker)
|
||||||
[:span {:class (str "task-status " (string/lower-case marker))
|
[:span {:class (str "task-status " (string/lower-case marker))
|
||||||
:style {:margin-right 3.5}}
|
:style {:margin-right 3.5}}
|
||||||
(string/upper-case marker)])
|
(string/upper-case marker)])
|
||||||
|
@ -376,7 +403,8 @@
|
||||||
:uuid (str uuid)}
|
:uuid (str uuid)}
|
||||||
(remove-nils
|
(remove-nils
|
||||||
(concat
|
(concat
|
||||||
[level-str
|
[(when-not agenda? level-str)
|
||||||
|
checkbox
|
||||||
marker
|
marker
|
||||||
priority]
|
priority]
|
||||||
(map-inline title)
|
(map-inline title)
|
||||||
|
|
|
@ -37,16 +37,6 @@
|
||||||
(parse-json config)
|
(parse-json config)
|
||||||
(util/json->clj)))))
|
(util/json->clj)))))
|
||||||
|
|
||||||
(defn inline-list->html
|
|
||||||
[json]
|
|
||||||
(when (loaded?)
|
|
||||||
(.inlineListToHtmlStr js/window.MldocOrg json)))
|
|
||||||
|
|
||||||
(defn json->html
|
|
||||||
[json]
|
|
||||||
(when (loaded?)
|
|
||||||
(.jsonToHtmlStr js/window.MldocOrg json default-config)))
|
|
||||||
|
|
||||||
(defrecord OrgMode []
|
(defrecord OrgMode []
|
||||||
protocol/Format
|
protocol/Format
|
||||||
(toHtml [this content config]
|
(toHtml [this content config]
|
||||||
|
|
|
@ -315,6 +315,12 @@
|
||||||
#{"A" "BUTTON"}
|
#{"A" "BUTTON"}
|
||||||
(gobj/get node "tagName")))
|
(gobj/get node "tagName")))
|
||||||
|
|
||||||
|
(defn input?
|
||||||
|
[node]
|
||||||
|
(contains?
|
||||||
|
#{"INPUT"}
|
||||||
|
(gobj/get node "tagName")))
|
||||||
|
|
||||||
(defn journal?
|
(defn journal?
|
||||||
[path]
|
[path]
|
||||||
(string/starts-with? path "journals/"))
|
(string/starts-with? path "journals/"))
|
||||||
|
|
Loading…
Reference in New Issue