diff --git a/project.clj b/project.clj index 62993d6..7e4fab1 100644 --- a/project.clj +++ b/project.clj @@ -7,19 +7,19 @@ [org.clojure/core.async "0.1.267.0-0d7780-alpha"] [org.clojure/core.match "0.2.1"] [org.clojure/tools.cli "0.3.1"] - [compojure "1.1.6"] - [clj-ssh "0.5.7"] + [compojure "1.1.8"] + [clj-ssh "0.5.9"] [ring/ring-devel "1.2.2"] [ring/ring-core "1.2.2"] [http-kit "2.1.18"] [org.clojure/clojurescript "0.0-2202"] [org.clojure/data.json "0.2.4"] - [de.ubercode.clostache/clostache "1.3.1"] + [de.ubercode.clostache/clostache "1.4.0"] [org.clojure/tools.logging "0.2.6"] [javax.jmdns/jmdns "3.4.1"] [me.raynes/conch "0.5.1"] - [om "0.5.3"] - [jayq "2.5.0"]] + [om "0.6.2"] + [jayq "2.5.1"]] :plugins [[lein-cljsbuild "1.0.3"] [lein-ancient "0.5.5"]] diff --git a/src-cljs/dakait/components.cljs b/src-cljs/dakait/components.cljs index e5ba2ae..1b63097 100644 --- a/src-cljs/dakait/components.cljs +++ b/src-cljs/dakait/components.cljs @@ -1,5 +1,5 @@ (ns dakait.components - (:use [dakait.util :only [format-file-size format-date]] + (:use [dakait.util :only [format-file-size format-date duration-since]] [clojure.string :only [join split]] [jayq.core :only [$ html append css text ajax on bind hide show attr add-class remove-class]] [dakait.net :only [http-post]] @@ -70,6 +70,7 @@ (dom/div #js {:className "col-sm-2 tag-button-container"} (dom/button #js {:className "btn btn-default btn-lg tag-item-action" :type "button" + :disabled (:recent l) :onClick (tag-handler (:name l)) } "Tag"))) (when-let [pc (:percent-complete (:download l))] (dom/div #js {:className "thin-progress"} diff --git a/src-cljs/dakait/start.cljs b/src-cljs/dakait/start.cljs index 5458273..dae09d1 100644 --- a/src-cljs/dakait/start.cljs +++ b/src-cljs/dakait/start.cljs @@ -1,6 +1,7 @@ (ns dakait.index (:use [dakait.components :only [current-path listing sort-order download-activity-monitor tags-modal content-pusher-modal]] + [dakait.util :only [duration-since]] [dakait.net :only [get-json http-delete http-post]] [dakait.downloads :only [start-listening-for-downloads]] [clojure.string :only [join split]] @@ -126,6 +127,31 @@ attach-tag attach-dl))))) +(def path-refresh-timeout (atom nil)) +(def path-refresh-was-canceled (atom false)) + +(defn path-refresh + "Continously query the given path at regular intervals, should be cancellable" + [path f] + (let [to (js/setTimeout (fn [] + (log "Refreshing path...") + (get-file-listing path + (fn [list] + (when-not @path-refresh-was-canceled + (f list) + (path-refresh path f))))) + 2000)] + (reset! path-refresh-was-canceled false) + (reset! path-refresh-timeout to))) + +(defn cancel-path-refresh + "Cancel an active path refresh loop" + [] + (when @path-refresh-timeout + (js/clearTimeout @path-refresh-timeout) + (reset! path-refresh-timeout nil) + (reset! path-refresh-was-canceled true) + (log "Path refresh was cancelled!"))) (defn full-page "Full page om component" @@ -158,11 +184,15 @@ (go (loop [] (let [path ( (:listing app) (merge-listing (:tags app) (:downloads app) (:current-path app)) - (sort-list)) + sort-list) :current-path (:current-path app)} {:opts {:path-chan (:path-chan state) :modal-chan (:modal-chan state)}}) diff --git a/src-cljs/dakait/util.cljs b/src-cljs/dakait/util.cljs index dfec382..94b8dde 100644 --- a/src-cljs/dakait/util.cljs +++ b/src-cljs/dakait/util.cljs @@ -28,3 +28,9 @@ (< diffInHours 48) "A day ago" (< diffInHours 168) (str (quot diffInHours 24) " days ago") :else (.toDateString (js/Date. dt))))) + +(defn duration-since + "Given a time stamp (time in seconds since epoch), returns how much time in seconds has passed since" + [n] + (let [now (quot (.getTime (js/Date.)) 1000)] + (- now n))) diff --git a/src/dakait/files.clj b/src/dakait/files.clj index c126df7..5f37131 100644 --- a/src/dakait/files.clj +++ b/src/dakait/files.clj @@ -82,11 +82,13 @@ (defn all-remote-files [path] (let [query-path (join-path (config :base-path) path) + now (quot (.getTime (java.util.Date.)) 1000) entries (list-remote-files query-path) not-hidden? (fn [e] (not= (.charAt (.getFilename e) 0) \.)) file-type (fn [e] (if (.isDir (.getAttrs e)) "dir" "file")) file-size (fn [e] (.getSize (.getAttrs e))) last-modified (fn [e] (-> e (.getAttrs) (.getMTime))) + recent? (fn [e] (< (- now (last-modified e)) 10)) ] (info "query path: " query-path) (->> entries @@ -94,5 +96,6 @@ (map (fn [e] { :name (.getFilename e) :type (file-type e) :modified (last-modified e) + :recent (recent? e) :size (file-size e)})))))