don't show inventory management ui if user is not authorized

but can show it if user authorization is not required, as indicated by
the app's config.edn
This commit is contained in:
Gered 2016-06-29 18:29:28 -04:00
parent 2c89c13a64
commit a7f1d5aa17

View file

@ -6,6 +6,7 @@
[webtools.reagent.bootstrap :as bs] [webtools.reagent.bootstrap :as bs]
[webtools.cljs.ajax :as ajax] [webtools.cljs.ajax :as ajax]
[webtools.cljs.utils :refer [->url]] [webtools.cljs.utils :refer [->url]]
[mtgcoll.client.auth :as auth]
[mtgcoll.client.page :refer [set-error!]])) [mtgcoll.client.page :refer [set-error!]]))
(def qualities (def qualities
@ -23,19 +24,29 @@
:params {:card-id card-id :quality quality :foil foil?} :params {:card-id card-id :quality quality :foil foil?}
:on-error #(set-error! "Server error while adding card to inventory."))) :on-error #(set-error! "Server error while adding card to inventory.")))
(defn can-modify-inventory?
[]
(or (not (auth/auth-required?))
(auth/authenticated?)))
(defvc inventory-management (defvc inventory-management
[card-id] [card-id]
(let [inventory (view-cursor :owned-card card-id) (let [inventory (view-cursor :owned-card card-id)
inventory (group-by :quality @inventory)] inventory (group-by :quality @inventory)
colspan (if (can-modify-inventory?) 2 1)
quantity-class (if (can-modify-inventory?)
"quantity col-sm-1"
"quantity col-sm-4")]
[bs/Grid {:fluid true :class "inventory-container"} [bs/Grid {:fluid true :class "inventory-container"}
[bs/Table [bs/Table
{:condensed true :hover true :bordered true} {:condensed true :hover true :bordered true}
[:thead [:thead
[:tr [:tr
[:th ""] [:th ""]
[:th {:col-span 2} [:span.text-center "Normal"]] [:th.text-center {:col-span colspan} "Normal"]
[:th {:col-span 2} [:span.text-center "Foil"]]]] [:th.text-center {:col-span colspan} "Foil"]]]
[:tbody [:tbody
(doall
(map-indexed (map-indexed
(fn [idx quality] (fn [idx quality]
(let [inventory (get inventory quality) (let [inventory (get inventory quality)
@ -52,9 +63,12 @@
[bs/FormControl.Static [bs/FormControl.Static
(str (string/capitalize quality) ": ")]]] (str (string/capitalize quality) ": ")]]]
;; non-foil ;; non-foil
[:td.quantity.col-sm-1 [:td {:class quantity-class}
[bs/FormControl.Static [bs/FormControl.Static
[:strong non-foil-quantity]]] (if (> non-foil-quantity 0)
[:strong non-foil-quantity]
[:span.text-muted 0])]]
(if (can-modify-inventory?)
[:td.col-sm-3 [:td.col-sm-3
[bs/ButtonGroup {:justified true} [bs/ButtonGroup {:justified true}
[bs/ButtonGroup [bs/ButtonGroup
@ -62,11 +76,14 @@
[bs/Glyphicon {:glyph "plus"}]]] [bs/Glyphicon {:glyph "plus"}]]]
[bs/ButtonGroup [bs/ButtonGroup
[bs/Button {:bsStyle "danger" :disabled (= 0 non-foil-quantity) :on-click #(on-remove-card card-id quality false)} [bs/Button {:bsStyle "danger" :disabled (= 0 non-foil-quantity) :on-click #(on-remove-card card-id quality false)}
[bs/Glyphicon {:glyph "minus"}]]]]] [bs/Glyphicon {:glyph "minus"}]]]]])
;; foil ;; foil
[:td.quantity.col-sm-1 [:td {:class quantity-class}
[bs/FormControl.Static [bs/FormControl.Static
[:strong foil-quantity]]] (if (> foil-quantity 0)
[:strong foil-quantity]
[:span.text-muted 0])]]
(if (can-modify-inventory?)
[:td.col-sm-3 [:td.col-sm-3
[bs/ButtonGroup {:justified true} [bs/ButtonGroup {:justified true}
[bs/ButtonGroup [bs/ButtonGroup
@ -74,8 +91,8 @@
[bs/Glyphicon {:glyph "plus"}]]] [bs/Glyphicon {:glyph "plus"}]]]
[bs/ButtonGroup [bs/ButtonGroup
[bs/Button {:bsStyle "danger" :disabled (= 0 foil-quantity) :on-click #(on-remove-card card-id quality true)} [bs/Button {:bsStyle "danger" :disabled (= 0 foil-quantity) :on-click #(on-remove-card card-id quality true)}
[bs/Glyphicon {:glyph "minus"}]]]]]])) [bs/Glyphicon {:glyph "minus"}]]]]])]))
qualities)]]])) qualities))]]]))
(defn inventory (defn inventory
[card-id & [{:keys [num-owned owned? button-size button-style] :as opts}]] [card-id & [{:keys [num-owned owned? button-size button-style] :as opts}]]