Files add modified at too

pull/645/head
Tienson Qin 2020-06-04 08:50:24 +08:00
parent 5771b28f14
commit 055dbfd1fd
3 changed files with 34 additions and 15 deletions

View File

@ -12,7 +12,10 @@
[frontend.config :as config]
[frontend.utf8 :as utf8]
[goog.dom :as gdom]
[goog.object :as gobj]))
[goog.object :as gobj]
[frontend.date :as date]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]))
(defn- get-path
[state]
@ -28,11 +31,22 @@
"All files"]
(when-let [current-repo (state/sub :git/current-repo)]
(let [files (db/get-files current-repo)]
(for [file files]
(let [file-id (util/url-encode file)]
[:div {:key file-id}
[:a {:href (str "/file/" file-id)}
file]]))))])
[:table
[:thead
[:tr
[:th "File name"]
[:th "Last modified at"]]]
[:tbody
(for [[file modified-at] files]
(let [file-id (util/url-encode file)]
[:tr {:key file-id}
[:td [:a.text-gray-700 {:href (str "/file/" file-id)}
(util/capitalize-all file)]]
[: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 file < rum/reactive
[state]

View File

@ -120,6 +120,7 @@
;; file
:file/path {:db/unique :db.unique/identity}
:file/last-modified-at {}
;; TODO: calculate memory/disk usage
;; :file/size {}
@ -522,13 +523,14 @@
(defn get-files
[repo]
(->> (q repo [:files] {}
'[:find ?file-path
'[:find ?path ?modified-at
:where
[?file :file/path ?file-path]])
[?file :file/path ?path]
[(get-else $ ?file :file/last-modified-at 0) ?modified-at]])
(react)
(map first)
(distinct)
(sort)))
(seq)
(sort-by last)
(reverse)))
(defn get-files-headings
[repo-url paths]

View File

@ -819,14 +819,17 @@
(when (not= (string/trim content) value) ; heading content changed
(let [file (db/entity (:db/id file))
page (db/entity (:db/id page))
save-heading (fn [file {:heading/keys [uuid content meta page dummy? format] :as heading}]
(let [file-path (:file/path file)
save-heading (fn [file {:heading/keys [uuid content meta page file dummy? format] :as heading}]
(let [file (db/entity (:db/id file))
file-path (:file/path file)
format (format/get-format file-path)]
(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)
page-modified-time [[:db/add (:db/id page) :page/last-modified-at (tc/to-long (t/now))]]]
modified-time (let [modified-at (tc/to-long (t/now))]
[[:db/add (:db/id page) :page/last-modified-at modified-at]
[:db/add (:db/id file) :file/last-modified-at modified-at]])]
(profile
"Save heading: "
(transact-react-and-alter-file!
@ -835,7 +838,7 @@
pages
headings
after-headings
page-modified-time)
modified-time)
{:key :heading/change
:data headings}
file-path