Add "schedule and deadline" part

pull/645/head
Tienson Qin 2020-10-19 15:59:49 +08:00
parent ea3feb5ce8
commit 6c2403f3a3
4 changed files with 84 additions and 16 deletions

View File

@ -9,12 +9,13 @@
[frontend.format :as format]
[frontend.components.content :as content]
[frontend.config :as config]
[frontend.db :as db]
[frontend.date :as date]
[frontend.components.svg :as svg]
[frontend.components.editor :as editor]
[frontend.handler.page :as page-handler]
[frontend.db-mixins :as db-mixins]
[clojure.set :as set]))
[clojure.set :as set]
[clojure.string :as string]))
(rum/defc references < rum/reactive db-mixins/query
[page-name marker? priority?]
@ -23,6 +24,7 @@
block-id (and block? (uuid page-name))
page-name (string/lower-case page-name)
encoded-page-name (util/url-encode page-name)
journal? (date/valid-journal-title? (string/capitalize page-name))
ref-blocks (cond
priority?
(db/get-blocks-by-priority (state/get-current-repo) page-name)
@ -33,10 +35,28 @@
(db/get-block-referenced-blocks block-id)
:else
(db/get-page-referenced-blocks page-name))
scheduled-or-deadlines (if journal?
(db/get-date-scheduled-or-deadlines (string/capitalize page-name))
nil)
n-ref (count ref-blocks)]
(when (> n-ref 0)
[:div.references.mt-6.flex-1.flex-row
[:div.content
(when (seq scheduled-or-deadlines)
(ui/foldable
[:h2.font-bold.opacity-50 (let []
"Scheduled AND Deadline")]
[:div.references-blocks.mb-6
(let [ref-hiccup (hiccup/->hiccup scheduled-or-deadlines
{:id (str encoded-page-name "-agenda")
:start-level 2
:ref? true
:group-by-page? true
:editor-box editor/box}
{})]
(content/content encoded-page-name
{:hiccup ref-hiccup}))]))
(ui/foldable
[:h2.font-bold.opacity-50 (let []
(str n-ref " Linked References"))]

View File

@ -1733,6 +1733,26 @@
sort-blocks
group-by-page)))))
(defn get-date-scheduled-or-deadlines
[journal-title]
(when-let [date (date/journal-title->int journal-title)]
(when-let [repo (state/get-current-repo)]
(when-let [conn (get-conn repo)]
(->> (d/q
'[:find (pull ?block [*])
:in $ ?day
:where
(or
[?block :block/scheduled ?day]
[?block :block/deadline ?day])]
conn
date)
seq-flatten
sort-blocks
group-by-page
(remove (fn [[page _blocks]]
(= journal-title (:page/original-name page)))))))))
(defn get-files-that-referenced-page
[page-id]
(when-let [repo (state/get-current-repo)]

View File

@ -83,16 +83,21 @@
;; :start-pos :end-pos
:block/meta {}
:block/properties {}
;; TODO: To make this really working, every block needs a persisting `CUSTOM-ID`, which I'd like to avoid for now.
;; Any suggestions?
:block/created-at {}
:block/last-modified-at {}
:block/body {}
:block/pre-block? {}
:block/collapsed? {}
:block/children {:db/cardinality :db.cardinality/many
:db/unique :db.unique/identity}
:block/scheduled {}
:block/scheduled-ast {}
:block/deadline {}
:block/deadline-ast {}
:block/repeated? {}
;; TODO: To make this really working, every block needs a persisting `CUSTOM-ID`, which I'd like to avoid for now.
;; Any suggestions?
:block/created-at {}
:block/last-modified-at {}
;; For pages
:tag/name {:db/unique :db.unique/identity}

View File

@ -111,12 +111,34 @@
(and (paragraph-block? block)
(timestamp-block? (first (second block)))))
(defn extract-timestamp
(defn extract-timestamps
[block]
(-> block
second
first
second))
(some->>
(second block)
(filter timestamp-block?)
(map last)
(into {})))
;; {"Deadline" {:date {:year 2020, :month 10, :day 20}, :wday "Tue", :time {:hour 8, :min 0}, :repetition [["DoublePlus"] ["Day"] 1], :active true}}
(defn timestamps->scheduled-and-deadline
[timestamps]
(let [timestamps (medley/map-keys (comp keyword string/lower-case) timestamps)
m (some->> (select-keys timestamps [:scheduled :deadline])
(map (fn [[k v]]
(let [{:keys [date repetition]} v
{:keys [year month day]} date
day (js/parseInt (str year month day))]
(cond->
(case k
:scheduled
{:scheduled day
:scheduled-ast v}
:deadline
{:deadline day
:deadline-ast v})
repetition
(assoc :repeated? true))))))]
(apply merge m)))
(defn with-page-refs
[{:keys [title body tags] :as block}]
@ -200,8 +222,8 @@
level (:level (second block))]
(cond
(paragraph-timestamp-block? block)
(let [timestamp (extract-timestamp block)
timestamps' (conj timestamps timestamp)]
(let [timestamps (extract-timestamps block)
timestamps' (merge timestamps timestamps)]
(recur block-refs headings block-body (rest blocks) timestamps' properties last-pos last-level children))
(properties-block? block)
@ -231,12 +253,13 @@
block (-> (assoc block
:uuid id
:body (vec (reverse block-body))
:timestamps timestamps
:properties (:properties properties)
:properties-meta (dissoc properties :properties)
:children (or current-block-children []))
(assoc-in [:meta :start-pos] start_pos)
(assoc-in [:meta :end-pos] last-pos))
block (if (seq timestamps)
(merge block (timestamps->scheduled-and-deadline timestamps))
block)
block (collect-block-tags block)
block (with-page-refs block)
block (with-block-refs block)