Sort pages by last modified at

pull/645/head
Tienson Qin 2020-06-04 07:42:41 +08:00
parent 3d317dbdd5
commit c15b0c95b3
4 changed files with 76 additions and 25 deletions

View File

@ -17,7 +17,9 @@
[goog.dom :as gdom]
[goog.object :as gobj]
[frontend.utf8 :as utf8]
[frontend.date :as date]))
[frontend.date :as date]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]))
(defn- get-page-name
[state]
@ -162,14 +164,23 @@
[:h1.title
"All Pages"]
(when current-repo
(let [pages (->> (db/get-pages current-repo)
(remove util/file-page?)
sort)]
(for [page pages]
(let [page-id (util/url-encode page)]
[:div {:key page-id}
[:a {:href (str "/page/" page-id)}
(util/capitalize-all page)]]))))]))
(let [pages (db/get-pages-with-modified-at current-repo)]
[:table
[:thead
[:tr
[:th "Page name"]
[:th "Last modified at"]]]
[:tbody
(for [[page modified-at] pages]
(let [page-id (util/url-encode page)]
[:tr {:key page-id}
[:td [:a.text-gray-700 {:href (str "/page/" page-id)}
(util/capitalize-all page)]]
[:td [:span.text-gray-500.text-sm
(if (zero? modified-at)
"No data"
(date/get-date-time-string
(t/to-default-time-zone (tc/to-date-time modified-at))))]]]))]]))]))
(rum/defcs new < rum/reactive
(rum/local "" ::title)

View File

@ -130,7 +130,6 @@
:db/cardinality :db.cardinality/many}
:page/tags {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
:page/created-at {}
:page/last-modified-at {}
:page/journal? {}
:page/journal-day {}
@ -461,18 +460,34 @@
(->> (q repo [:pages] {}
'[:find ?page-name
:where
[?page :page/name ?page-name]
[?h :heading/page ?page]
[?h :heading/level ?level]
[?page :page/journal? ?journal]
(or
;; journal
(and [(true? ?journal)]
[(> ?level 1)])
[(false? ?journal)])])
[?page :page/name ?page-name]])
(react)
(map first)
distinct))
(map first)))
(defn get-pages-with-modified-at
[repo]
(->> (q repo [:pages] {}
'[:find ?page-name ?modified-at
:where
[?page :page/name ?page-name]
[?page :page/journal? ?journal]
[(get-else $ ?page :page/last-modified-at 0) ?modified-at]
(or
;; journal pages, can't be empty
(and [(true? ?journal)]
[?h :heading/page ?page]
[?h :heading/level ?level]
[(> ?level 1)])
;; non-journals, might be empty pages
(and [(false? ?journal)]
[?h :heading/page]
[?h :heading/level ?level]))])
(react)
(seq)
(sort-by last)
(reverse)
(remove (fn [[page modified-at]]
(util/file-page? page)))))
(defn get-page-alias
[repo page-name]

View File

@ -7,6 +7,8 @@
[frontend.state :as state]
[goog.object :as gobj]
[cljs-bean.core :as bean]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]
["/frontend/git_ext" :as git-ext]))
;; TODO: move to a js worker
@ -215,3 +217,25 @@
:ref (str "refs/heads/" default-branch)
:value oid
:force true})))
;; "git log -1 --pretty=\"format:%cI\""
;; FIXME: Uncaught (in promise) ObjectTypeAssertionFail: Object 0698e8812d6f7b37dc98aea28de2d04714cead80 was anticipated to be a commit but it is a blob. This is probably a bug deep in isomorphic-git!
;; (defn get-last-modified-date
;; [repo-url token path]
;; (let [dir (util/get-repo-dir repo-url)]
;; (p/let [commits (log repo-url token 1)
;; commit (first commits)
;; time (try
;; (p/let [o (js/git.readObject #js {:dir dir
;; :oid (gobj/get commit "oid")
;; :filepath path})
;; oid (gobj/get o "oid")
;; commit (read-commit repo-url oid)]
;; (-> (gobj/get commit "author")
;; (gobj/get "timestamp")))
;; (catch js/Error e
;; nil))]
;; (when time
;; (-> (* time 1000)
;; (tc/to-date-time)
;; (t/to-default-time-zone))))))

View File

@ -825,7 +825,8 @@
(let [file-content (db/get-file file-path)
[new-content value] (new-file-content heading file-content value)
{:keys [headings pages start-pos end-pos]} (block/parse-heading (assoc heading :heading/content value) format)
after-headings (rebuild-after-headings repo file (:end-pos meta) end-pos)]
after-headings (rebuild-after-headings repo file (:end-pos meta) end-pos)
page-modified-time [[:db/add (:db/id page) :page/last-modified-at (tc/to-long (t/now))]]]
(profile
"Save heading: "
(transact-react-and-alter-file!
@ -833,12 +834,12 @@
(concat
pages
headings
after-headings)
after-headings
page-modified-time)
{:key :heading/change
:data headings}
file-path
new-content))
)))]
new-content)))))]
(cond
;; Page was referenced but no related file
(and page (not file))