From c3722371d344923031ebd2aa94b1970005530d30 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 1 Aug 2016 16:24:56 -0400 Subject: [PATCH] modify stats page to allow display list-specific stats --- src/mtgcoll/client/core.cljs | 3 +- src/mtgcoll/client/routes/lists.cljs | 22 ++++---- src/mtgcoll/client/routes/stats.cljs | 75 +++++++++++++++------------- 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/mtgcoll/client/core.cljs b/src/mtgcoll/client/core.cljs index 9a28123..59feda5 100644 --- a/src/mtgcoll/client/core.cljs +++ b/src/mtgcoll/client/core.cljs @@ -21,7 +21,8 @@ (defroute "/card/:id" [id] (page/page [cards/card-details id 0])) (defroute "/lists" [] (page/page [lists/lists-list])) (defroute "/list/:id" [id] (page/page [lists/list-details (parse-int id)])) -(defroute "/stats" [] (page/page [stats/stats-page])) +(defroute "/stats/list/:list-id" [list-id] (page/page [stats/stats-page (parse-int list-id)])) +(defroute "/stats" [] (page/page [stats/stats-page 0])) (defroute "*" [] (page/barebones-page [:div "not found"])) (defn ^:export run diff --git a/src/mtgcoll/client/routes/lists.cljs b/src/mtgcoll/client/routes/lists.cljs index dc2c673..eeebce5 100644 --- a/src/mtgcoll/client/routes/lists.cljs +++ b/src/mtgcoll/client/routes/lists.cljs @@ -185,15 +185,19 @@ :else [:div.context - (if (auth/can-modify-data?) - [:div.absolute.top-right - (if-not (:is_public @list) [:span.large-font [bs/Label {:bsStyle "danger"} "Private"] " "]) - (if (:require_qualities @list) [:span.large-font [bs/Label {:bsStyle "primary"} "Card Qualities"] " "]) - [bs/DropdownButton {:title "Actions"} - [bs/MenuItem {:on-click #(js/alert "TODO: Copy to Owned")} "Copy to Owned"] - (if (auth/auth-required?) - [bs/MenuItem {:on-click #(change-list-visibility! list-id (not (:is_public @list)))} (if (:is_public @list) "Make Private" "Make Public")]) - [bs/MenuItem {:on-click #(reset! show-delete-confirm? true)} "Delete"]]]) + [:div.absolute.top-right + [:span [bs/Button {:bsStyle "info" + :href (->url "#/stats/list/" list-id)} "List Statistics"]] + " " + (if (auth/can-modify-data?) + [:span + (if-not (:is_public @list) [:span.large-font [bs/Label {:bsStyle "danger"} "Private"] " "]) + (if (:require_qualities @list) [:span.large-font [bs/Label {:bsStyle "primary"} "Card Qualities"] " "]) + [bs/DropdownButton {:title "Actions"} + [bs/MenuItem {:on-click #(js/alert "TODO: Copy to Owned")} "Copy to Owned"] + (if (auth/auth-required?) + [bs/MenuItem {:on-click #(change-list-visibility! list-id (not (:is_public @list)))} (if (:is_public @list) "Make Private" "Make Public")]) + [bs/MenuItem {:on-click #(reset! show-delete-confirm? true)} "Delete"]]])] [bs/PageHeader (:name @list)] [confirm-modal show-delete-confirm? diff --git a/src/mtgcoll/client/routes/stats.cljs b/src/mtgcoll/client/routes/stats.cljs index f6c1df1..be2f678 100644 --- a/src/mtgcoll/client/routes/stats.cljs +++ b/src/mtgcoll/client/routes/stats.cljs @@ -239,45 +239,48 @@ :pricing-source nil})) (defvc stats-page - [] + [list-id] (let [pricing-sources (view-cursor :pricing-sources) + list-info (view-cursor :list-info list-id (auth/get-username)) online? (:online? @settings) - pricing-source (:pricing-source @settings) - list-id c/owned-list-id] + pricing-source (:pricing-source @settings)] (set-active-breadcrumb! :stats) (if (and (not (vc/loading? pricing-sources)) (nil? (:pricing-source @settings))) (swap! settings assoc :pricing-source (->> @pricing-sources first :source))) - [:div.statistics-container - [:div.header - [bs/PageHeader "Collection Statistics"] - [:div.settings - [bs/Form {:inline true} - [bs/FormGroup {:bsSize "large"} - [bs/FormControl - {:component-class "select" - :value (if online? "Online" "Paper") - :on-change #(swap! settings assoc :online? (= "Online" (get-field-value %)))} - [:option "Paper"] - [:option "Online"]]] - [bs/FormGroup {:bsSize "large"} - [bs/FormControl - {:component-class "select" - :value (or (:pricing-source @settings) "") - :on-change #(swap! settings assoc :pricing-source (get-field-value %))} - (map - (fn [{:keys [source]}] - ^{:key source} [:option {:value (or source "")} source]) - @pricing-sources)]]]]] - [bs/Grid {:fluid true :class "statistics"} - [widget-row - [bs/Col {:sm 4} - [widget-row [widget-summary-stats online? list-id pricing-source]] - [widget-row [widget-rarity-totals online? list-id]] - [widget-row [widget-most-owned-sets online? list-id]]] - [bs/Col {:sm 8} - [widget-row [widget-color-totals online? list-id]] - [widget-row [widget-basic-type-totals online? list-id]] - [widget-row [widget-most-valuable-cards online? list-id pricing-source {:width 10}]] - [widget-row [widget-most-copies-of-card online? list-id {:width 10}]] - [widget-row [widget-most-nonland-copies-of-card online? list-id {:width 10}]]]]]])) + (if (and (not (vc/loading? list-info)) + (not (vc/loading? pricing-sources))) + [:div.statistics-container + [:div.header + [bs/PageHeader "Statistics " [:small (if (= c/owned-list-id list-id) "Owned Cards" (:name @list-info))]] + [:div.settings + [bs/Form {:inline true} + [bs/FormGroup {:bsSize "large"} + [bs/FormControl + {:component-class "select" + :value (if online? "Online" "Paper") + :on-change #(swap! settings assoc :online? (= "Online" (get-field-value %)))} + [:option "Paper"] + [:option "Online"]]] + [bs/FormGroup {:bsSize "large"} + [bs/FormControl + {:component-class "select" + :value (or (:pricing-source @settings) "") + :on-change #(swap! settings assoc :pricing-source (get-field-value %))} + (map + (fn [{:keys [source]}] + ^{:key source} [:option {:value (or source "")} source]) + @pricing-sources)]]]]] + [bs/Grid {:fluid true :class "statistics"} + [widget-row + [bs/Col {:sm 4} + [widget-row [widget-summary-stats online? list-id pricing-source]] + [widget-row [widget-rarity-totals online? list-id]] + [widget-row [widget-most-owned-sets online? list-id]]] + [bs/Col {:sm 8} + [widget-row [widget-color-totals online? list-id]] + [widget-row [widget-basic-type-totals online? list-id]] + [widget-row [widget-most-valuable-cards online? list-id pricing-source {:width 10}]] + [widget-row [widget-most-copies-of-card online? list-id {:width 10}]] + [widget-row [widget-most-nonland-copies-of-card online? list-id {:width 10}]]]]]] + [:div "Loading ..."])))