From bb801f09a2d9e965f807727dcf70a48e707b759f Mon Sep 17 00:00:00 2001 From: Uday Verma Date: Sun, 6 Jul 2014 10:44:54 -0500 Subject: [PATCH] Show waiting status of downloads in progress --- src-cljs/dakait/components.cljs | 15 +++++++++------ src-cljs/dakait/start.cljs | 7 +++++-- src/dakait/downloader.clj | 10 ++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src-cljs/dakait/components.cljs b/src-cljs/dakait/components.cljs index 1b63097..a34cc07 100644 --- a/src-cljs/dakait/components.cljs +++ b/src-cljs/dakait/components.cljs @@ -6,8 +6,10 @@ [jayq.util :only [log]]) (:require [cljs.core.async :as async :refer [>!]] [om.core :as om :include-macros true] - [om.dom :as dom :include-macros true]) - (:require-macros [cljs.core.async.macros :refer [go]])) + [om.dom :as dom :include-macros true] + [cljs.core.match]) + (:require-macros [cljs.core.async.macros :refer [go]] + [cljs.core.match.macros :refer [match]])) (defn current-path "Manages the current path display" @@ -47,9 +49,10 @@ tag-item (let [tag (:tag l) dl (:download l) color (if tag (:color tag) "#999") - dlinfo (if dl - (str (:percent-complete dl) ", " (:rate dl) ", eta: " (:eta dl)) - "")] + dlinfo (match dl + {:available st} (str (:percent-complete st) ", " (:rate st) ", eta: " (:eta st)) + {:waiting _} "Waiting..." + :else "")] (dom/div #js {:className "col-sm-6 list-item-tag" :style #js {:color color}} (when tag (dom/span #js {:className "tag-info"} (:name tag))) @@ -72,7 +75,7 @@ :type "button" :disabled (:recent l) :onClick (tag-handler (:name l)) } "Tag"))) - (when-let [pc (:percent-complete (:download l))] + (when-let [pc (get-in l [:download :available :percent-complete])] (dom/div #js {:className "thin-progress"} (dom/div #js {:className "thin-progress-bar" :style #js {:width pc}})))))) diff --git a/src-cljs/dakait/start.cljs b/src-cljs/dakait/start.cljs index 330c50a..ebc911c 100644 --- a/src-cljs/dakait/start.cljs +++ b/src-cljs/dakait/start.cljs @@ -118,9 +118,12 @@ l)) attach-dl (fn [l] (if-let [dl (get dls (:name l))] - (do - (assoc l :download (:download-status dl))) + (let [ds (if (:download-status dl) + {:available (:download-status dl)} + {:waiting nil})] + (assoc l :download ds)) l))] + (.log js/console "got downloads" (pr-str dls)) (->> listing ;; Associate tag information (map #(->> % diff --git a/src/dakait/downloader.clj b/src/dakait/downloader.clj index 075dd2c..594f9a5 100644 --- a/src/dakait/downloader.clj +++ b/src/dakait/downloader.clj @@ -146,10 +146,12 @@ (defn downloads-in-progress "Gets all active downloads" [] - (map (fn [[fut src dest & rest]] - {:from src - :to dest - :download-status (get @download-states src)}) @active-downloads)) + (let [ad @active-downloads + ds @download-states] + (map (fn [[fut src dest & rest]] + {:from src + :to dest + :download-status (ds src)}) ad))) (defn downloads-pending "Get all the pending downloads as a seq"