mirror of https://github.com/logseq/logseq
Same rendering for agenda headings
parent
2adabbd234
commit
735ceb42a7
|
@ -1,104 +1,22 @@
|
|||
(ns frontend.components.agenda
|
||||
(:require [rum.core :as rum]
|
||||
[frontend.util :as util]
|
||||
[frontend.handler :as handler]
|
||||
[frontend.format.org.block :as block]
|
||||
[frontend.state :as state]
|
||||
[clojure.string :as string]
|
||||
[frontend.format.org-mode :as org]
|
||||
[frontend.components.sidebar :as sidebar]
|
||||
[frontend.db :as db]
|
||||
[frontend.ui :as ui]))
|
||||
|
||||
(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]])])
|
||||
[frontend.components.content :as content]
|
||||
[frontend.components.hiccup :as hiccup]
|
||||
[frontend.db :as db]))
|
||||
|
||||
(rum/defc agenda
|
||||
[]
|
||||
(let [tasks (db/get-agenda)]
|
||||
(sidebar/sidebar
|
||||
[:div#agenda
|
||||
[:h2.mb-3 "Agenda"]
|
||||
[:h1.title "Agenda"]
|
||||
(if (seq tasks)
|
||||
[:div.ml-1
|
||||
(let [tasks (block/sort-tasks tasks)]
|
||||
(for [{:heading/keys [uuid marker title priority level tags children timestamps meta repo file] :as task} tasks]
|
||||
[:div.mb-2
|
||||
{:key (str "task-" uuid)
|
||||
: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))
|
||||
|
||||
]]
|
||||
))]
|
||||
(let [tasks (block/sort-tasks tasks)
|
||||
id "agenda"]
|
||||
(content/content id :org
|
||||
{:hiccup (hiccup/->hiccup tasks {:id id})}))]
|
||||
"Empty")])))
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[frontend.expand :as expand]
|
||||
[frontend.components.editor :as editor]
|
||||
[frontend.components.svg :as svg]
|
||||
[frontend.ui :as ui]
|
||||
[frontend.handler :as handler]
|
||||
[goog.object :as gobj]))
|
||||
|
||||
|
@ -278,7 +279,8 @@
|
|||
heading-id (str "ls-heading-parent-" uuid)
|
||||
collapsed-atom? (get state ::collapsed?)
|
||||
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)]
|
||||
(when-not lock?
|
||||
[:div.ls-heading-parent.flex-1 {:key (str uuid)
|
||||
|
@ -299,6 +301,7 @@
|
|||
:on-mouse-out (fn []
|
||||
(when (has-children? heading-id level)
|
||||
(reset! control-show? false)))}
|
||||
(when-not agenda?
|
||||
[:a.heading-control.pt-1
|
||||
{:id (str "control-" uuid)
|
||||
:class "block no-underline text-gray-700 hover:text-gray-700 transition ease-in-out duration-150 mr-1"
|
||||
|
@ -317,7 +320,7 @@
|
|||
(svg/caret-down)
|
||||
|
||||
:else
|
||||
nil)]
|
||||
nil)])
|
||||
|
||||
(if @edit?
|
||||
(editor/box content {:on-hide (fn [value]
|
||||
|
@ -333,7 +336,8 @@
|
|||
edit-input-id)
|
||||
[:div.flex-1.heading-body
|
||||
{: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)
|
||||
(handler/reset-cursor-range! (gdom/getElement heading-id))
|
||||
(swap! state/state assoc
|
||||
|
@ -348,10 +352,33 @@
|
|||
(rum/with-key (heading-child block)
|
||||
(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
|
||||
[config {:heading/keys [uuid title tags marker level priority anchor meta numbering children]
|
||||
: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))
|
||||
:style {:margin-right 3.5}}
|
||||
(string/upper-case marker)])
|
||||
|
@ -376,7 +403,8 @@
|
|||
:uuid (str uuid)}
|
||||
(remove-nils
|
||||
(concat
|
||||
[level-str
|
||||
[(when-not agenda? level-str)
|
||||
checkbox
|
||||
marker
|
||||
priority]
|
||||
(map-inline title)
|
||||
|
|
|
@ -37,16 +37,6 @@
|
|||
(parse-json config)
|
||||
(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 []
|
||||
protocol/Format
|
||||
(toHtml [this content config]
|
||||
|
|
|
@ -315,6 +315,12 @@
|
|||
#{"A" "BUTTON"}
|
||||
(gobj/get node "tagName")))
|
||||
|
||||
(defn input?
|
||||
[node]
|
||||
(contains?
|
||||
#{"INPUT"}
|
||||
(gobj/get node "tagName")))
|
||||
|
||||
(defn journal?
|
||||
[path]
|
||||
(string/starts-with? path "journals/"))
|
||||
|
|
Loading…
Reference in New Issue