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:
parent
2c89c13a64
commit
a7f1d5aa17
|
@ -6,6 +6,7 @@
|
|||
[webtools.reagent.bootstrap :as bs]
|
||||
[webtools.cljs.ajax :as ajax]
|
||||
[webtools.cljs.utils :refer [->url]]
|
||||
[mtgcoll.client.auth :as auth]
|
||||
[mtgcoll.client.page :refer [set-error!]]))
|
||||
|
||||
(def qualities
|
||||
|
@ -23,19 +24,29 @@
|
|||
:params {:card-id card-id :quality quality :foil foil?}
|
||||
: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
|
||||
[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/Table
|
||||
{:condensed true :hover true :bordered true}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th ""]
|
||||
[:th {:col-span 2} [:span.text-center "Normal"]]
|
||||
[:th {:col-span 2} [:span.text-center "Foil"]]]]
|
||||
[:th.text-center {:col-span colspan} "Normal"]
|
||||
[:th.text-center {:col-span colspan} "Foil"]]]
|
||||
[:tbody
|
||||
(doall
|
||||
(map-indexed
|
||||
(fn [idx quality]
|
||||
(let [inventory (get inventory quality)
|
||||
|
@ -52,9 +63,12 @@
|
|||
[bs/FormControl.Static
|
||||
(str (string/capitalize quality) ": ")]]]
|
||||
;; non-foil
|
||||
[:td.quantity.col-sm-1
|
||||
[:td {:class quantity-class}
|
||||
[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
|
||||
[bs/ButtonGroup {:justified true}
|
||||
[bs/ButtonGroup
|
||||
|
@ -62,11 +76,14 @@
|
|||
[bs/Glyphicon {:glyph "plus"}]]]
|
||||
[bs/ButtonGroup
|
||||
[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
|
||||
[:td.quantity.col-sm-1
|
||||
[:td {:class quantity-class}
|
||||
[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
|
||||
[bs/ButtonGroup {:justified true}
|
||||
[bs/ButtonGroup
|
||||
|
@ -74,8 +91,8 @@
|
|||
[bs/Glyphicon {:glyph "plus"}]]]
|
||||
[bs/ButtonGroup
|
||||
[bs/Button {:bsStyle "danger" :disabled (= 0 foil-quantity) :on-click #(on-remove-card card-id quality true)}
|
||||
[bs/Glyphicon {:glyph "minus"}]]]]]]))
|
||||
qualities)]]]))
|
||||
[bs/Glyphicon {:glyph "minus"}]]]]])]))
|
||||
qualities))]]]))
|
||||
|
||||
(defn inventory
|
||||
[card-id & [{:keys [num-owned owned? button-size button-style] :as opts}]]
|
||||
|
|
Loading…
Reference in a new issue