From 055dbfd1fdff3ea44699d5c02ae5c05d5f2b7083 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 4 Jun 2020 08:50:24 +0800 Subject: [PATCH] Files add modified at too --- web/src/main/frontend/components/file.cljs | 26 +++++++++++++++++----- web/src/main/frontend/db.cljs | 12 +++++----- web/src/main/frontend/handler.cljs | 11 +++++---- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/web/src/main/frontend/components/file.cljs b/web/src/main/frontend/components/file.cljs index b5ce32735..2e0031313 100644 --- a/web/src/main/frontend/components/file.cljs +++ b/web/src/main/frontend/components/file.cljs @@ -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] diff --git a/web/src/main/frontend/db.cljs b/web/src/main/frontend/db.cljs index 369c9583e..00320da56 100644 --- a/web/src/main/frontend/db.cljs +++ b/web/src/main/frontend/db.cljs @@ -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] diff --git a/web/src/main/frontend/handler.cljs b/web/src/main/frontend/handler.cljs index e5723c820..f530fe48c 100644 --- a/web/src/main/frontend/handler.cljs +++ b/web/src/main/frontend/handler.cljs @@ -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