modify stats page to allow display list-specific stats

This commit is contained in:
Gered 2016-08-01 16:24:56 -04:00
parent e4c2a03b72
commit c3722371d3
3 changed files with 54 additions and 46 deletions

View file

@ -21,7 +21,8 @@
(defroute "/card/:id" [id] (page/page [cards/card-details id 0])) (defroute "/card/:id" [id] (page/page [cards/card-details id 0]))
(defroute "/lists" [] (page/page [lists/lists-list])) (defroute "/lists" [] (page/page [lists/lists-list]))
(defroute "/list/:id" [id] (page/page [lists/list-details (parse-int id)])) (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"])) (defroute "*" [] (page/barebones-page [:div "not found"]))
(defn ^:export run (defn ^:export run

View file

@ -185,15 +185,19 @@
:else :else
[:div.context [:div.context
(if (auth/can-modify-data?) [:div.absolute.top-right
[:div.absolute.top-right [:span [bs/Button {:bsStyle "info"
(if-not (:is_public @list) [:span.large-font [bs/Label {:bsStyle "danger"} "Private"] " "]) :href (->url "#/stats/list/" list-id)} "List Statistics"]]
(if (:require_qualities @list) [:span.large-font [bs/Label {:bsStyle "primary"} "Card Qualities"] " "]) " "
[bs/DropdownButton {:title "Actions"} (if (auth/can-modify-data?)
[bs/MenuItem {:on-click #(js/alert "TODO: Copy to Owned")} "Copy to Owned"] [:span
(if (auth/auth-required?) (if-not (:is_public @list) [:span.large-font [bs/Label {:bsStyle "danger"} "Private"] " "])
[bs/MenuItem {:on-click #(change-list-visibility! list-id (not (:is_public @list)))} (if (:is_public @list) "Make Private" "Make Public")]) (if (:require_qualities @list) [:span.large-font [bs/Label {:bsStyle "primary"} "Card Qualities"] " "])
[bs/MenuItem {:on-click #(reset! show-delete-confirm? true)} "Delete"]]]) [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)] [bs/PageHeader (:name @list)]
[confirm-modal [confirm-modal
show-delete-confirm? show-delete-confirm?

View file

@ -239,45 +239,48 @@
:pricing-source nil})) :pricing-source nil}))
(defvc stats-page (defvc stats-page
[] [list-id]
(let [pricing-sources (view-cursor :pricing-sources) (let [pricing-sources (view-cursor :pricing-sources)
list-info (view-cursor :list-info list-id (auth/get-username))
online? (:online? @settings) online? (:online? @settings)
pricing-source (:pricing-source @settings) pricing-source (:pricing-source @settings)]
list-id c/owned-list-id]
(set-active-breadcrumb! :stats) (set-active-breadcrumb! :stats)
(if (and (not (vc/loading? pricing-sources)) (if (and (not (vc/loading? pricing-sources))
(nil? (:pricing-source @settings))) (nil? (:pricing-source @settings)))
(swap! settings assoc :pricing-source (->> @pricing-sources first :source))) (swap! settings assoc :pricing-source (->> @pricing-sources first :source)))
[:div.statistics-container (if (and (not (vc/loading? list-info))
[:div.header (not (vc/loading? pricing-sources)))
[bs/PageHeader "Collection Statistics"] [:div.statistics-container
[:div.settings [:div.header
[bs/Form {:inline true} [bs/PageHeader "Statistics " [:small (if (= c/owned-list-id list-id) "Owned Cards" (:name @list-info))]]
[bs/FormGroup {:bsSize "large"} [:div.settings
[bs/FormControl [bs/Form {:inline true}
{:component-class "select" [bs/FormGroup {:bsSize "large"}
:value (if online? "Online" "Paper") [bs/FormControl
:on-change #(swap! settings assoc :online? (= "Online" (get-field-value %)))} {:component-class "select"
[:option "Paper"] :value (if online? "Online" "Paper")
[:option "Online"]]] :on-change #(swap! settings assoc :online? (= "Online" (get-field-value %)))}
[bs/FormGroup {:bsSize "large"} [:option "Paper"]
[bs/FormControl [:option "Online"]]]
{:component-class "select" [bs/FormGroup {:bsSize "large"}
:value (or (:pricing-source @settings) "") [bs/FormControl
:on-change #(swap! settings assoc :pricing-source (get-field-value %))} {:component-class "select"
(map :value (or (:pricing-source @settings) "")
(fn [{:keys [source]}] :on-change #(swap! settings assoc :pricing-source (get-field-value %))}
^{:key source} [:option {:value (or source "")} source]) (map
@pricing-sources)]]]]] (fn [{:keys [source]}]
[bs/Grid {:fluid true :class "statistics"} ^{:key source} [:option {:value (or source "")} source])
[widget-row @pricing-sources)]]]]]
[bs/Col {:sm 4} [bs/Grid {:fluid true :class "statistics"}
[widget-row [widget-summary-stats online? list-id pricing-source]] [widget-row
[widget-row [widget-rarity-totals online? list-id]] [bs/Col {:sm 4}
[widget-row [widget-most-owned-sets online? list-id]]] [widget-row [widget-summary-stats online? list-id pricing-source]]
[bs/Col {:sm 8} [widget-row [widget-rarity-totals online? list-id]]
[widget-row [widget-color-totals online? list-id]] [widget-row [widget-most-owned-sets online? list-id]]]
[widget-row [widget-basic-type-totals online? list-id]] [bs/Col {:sm 8}
[widget-row [widget-most-valuable-cards online? list-id pricing-source {:width 10}]] [widget-row [widget-color-totals online? list-id]]
[widget-row [widget-most-copies-of-card online? list-id {:width 10}]] [widget-row [widget-basic-type-totals online? list-id]]
[widget-row [widget-most-nonland-copies-of-card online? list-id {:width 10}]]]]]])) [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 ..."])))