add foil tracking to card collection
This commit is contained in:
parent
0879a24e9f
commit
a957440f3b
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE collection DROP COLUMN IF EXISTS foil;
|
||||||
|
|
||||||
|
ALTER TABLE collection DROP CONSTRAINT IF EXISTS collection_card_id_quality_foil_key;
|
||||||
|
ALTER TABLE collection ADD CONSTRAINT collection_card_id_quality_key UNIQUE (card_id, quality);
|
|
@ -0,0 +1,6 @@
|
||||||
|
ALTER TABLE collection ADD COLUMN foil BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
|
||||||
|
CREATE INDEX collection_foil_idx ON collection (foil);
|
||||||
|
|
||||||
|
ALTER TABLE collection DROP CONSTRAINT IF EXISTS collection_card_id_quality_key;
|
||||||
|
ALTER TABLE collection ADD CONSTRAINT collection_card_id_quality_foil_key UNIQUE (card_id, quality, foil);
|
|
@ -56,7 +56,7 @@ div.card-title > h1 > small {
|
||||||
}
|
}
|
||||||
|
|
||||||
.inventory-container {
|
.inventory-container {
|
||||||
width: 300px;
|
width: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inventory-container .row:hover {
|
.inventory-container .row:hover {
|
||||||
|
|
|
@ -12,15 +12,15 @@
|
||||||
["online" "near mint" "lightly played" "moderately played" "heavily played" "damaged"])
|
["online" "near mint" "lightly played" "moderately played" "heavily played" "damaged"])
|
||||||
|
|
||||||
(defn on-add-card
|
(defn on-add-card
|
||||||
[card-id quality]
|
[card-id quality foil?]
|
||||||
(ajax/POST (->url "/collection/add")
|
(ajax/POST (->url "/collection/add")
|
||||||
:params {:card-id card-id :quality quality}
|
: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 on-remove-card
|
(defn on-remove-card
|
||||||
[card-id quality]
|
[card-id quality foil?]
|
||||||
(ajax/POST (->url "/collection/remove")
|
(ajax/POST (->url "/collection/remove")
|
||||||
:params {:card-id card-id :quality quality}
|
: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.")))
|
||||||
|
|
||||||
(defvc inventory-management
|
(defvc inventory-management
|
||||||
|
@ -28,26 +28,47 @@
|
||||||
(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)]
|
||||||
[bs/Grid {:fluid true :class "inventory-container"}
|
[bs/Grid {:fluid true :class "inventory-container"}
|
||||||
|
[bs/Row
|
||||||
|
[bs/Col {:sm 4} ""]
|
||||||
|
[bs/Col {:sm 4 :class "text-center"} [:strong "Normal"]]
|
||||||
|
[bs/Col {:sm 4 :class "text-center"} [:strong "Foil"]]]
|
||||||
(map-indexed
|
(map-indexed
|
||||||
(fn [idx quality]
|
(fn [idx quality]
|
||||||
(let [inventory (first (get inventory quality))
|
(let [inventory (get inventory quality)
|
||||||
quantity (or (:quantity inventory) 0)]
|
quantities (group-by :foil inventory)
|
||||||
|
foil-quantity (or (:quantity (first (get quantities true))) 0)
|
||||||
|
non-foil-quantity (or (:quantity (first (get quantities false))) 0)]
|
||||||
^{:key idx}
|
^{:key idx}
|
||||||
[bs/Row
|
[bs/Row
|
||||||
{:class (if (> quantity 0) "bg-warning")}
|
{:class (if (or (> foil-quantity 0)
|
||||||
[bs/Col {:sm 6 :class "text-right"}
|
(> non-foil-quantity 0))
|
||||||
|
"bg-warning")}
|
||||||
|
[bs/Col {:sm 4 :class "text-right"}
|
||||||
[bs/FormControl.Static
|
[bs/FormControl.Static
|
||||||
(str (string/capitalize quality) ": ")]]
|
(str (string/capitalize quality) ": ")]]
|
||||||
[bs/Col {:sm 2}
|
;; non-foil
|
||||||
|
[bs/Col {:sm 1}
|
||||||
[bs/FormControl.Static
|
[bs/FormControl.Static
|
||||||
[:strong quantity]]]
|
[:strong non-foil-quantity]]]
|
||||||
[bs/Col {:sm 4}
|
[bs/Col {:sm 3}
|
||||||
[bs/ButtonGroup {:justified true}
|
[bs/ButtonGroup {:justified true}
|
||||||
[bs/ButtonGroup
|
[bs/ButtonGroup
|
||||||
[bs/Button {:bsStyle "success" :on-click #(on-add-card card-id quality)}
|
[bs/Button {:bsStyle "success" :on-click #(on-add-card card-id quality false)}
|
||||||
[bs/Glyphicon {:glyph "plus"}]]]
|
[bs/Glyphicon {:glyph "plus"}]]]
|
||||||
[bs/ButtonGroup
|
[bs/ButtonGroup
|
||||||
[bs/Button {:bsStyle "danger" :disabled (= 0 quantity) :on-click #(on-remove-card card-id quality)}
|
[bs/Button {:bsStyle "danger" :disabled (= 0 non-foil-quantity) :on-click #(on-remove-card card-id quality false)}
|
||||||
|
[bs/Glyphicon {:glyph "minus"}]]]]]
|
||||||
|
;; foil
|
||||||
|
[bs/Col {:sm 1}
|
||||||
|
[bs/FormControl.Static
|
||||||
|
[:strong foil-quantity]]]
|
||||||
|
[bs/Col {:sm 3}
|
||||||
|
[bs/ButtonGroup {:justified true}
|
||||||
|
[bs/ButtonGroup
|
||||||
|
[bs/Button {:bsStyle "success" :on-click #(on-add-card card-id quality true)}
|
||||||
|
[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"}]]]]]]))
|
[bs/Glyphicon {:glyph "minus"}]]]]]]))
|
||||||
qualities)]))
|
qualities)]))
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
[mtgcoll.views.core :refer [view-system]]))
|
[mtgcoll.views.core :refer [view-system]]))
|
||||||
|
|
||||||
(defn update-collection!
|
(defn update-collection!
|
||||||
[card-id quality quantity-change]
|
[card-id quality foil? quantity-change]
|
||||||
;; written assuming postgresql server is _not_ 9.5+ (so, without access to UPSERT functionality)
|
;; written assuming postgresql server is _not_ 9.5+ (so, without access to UPSERT functionality)
|
||||||
(with-view-transaction
|
(with-view-transaction
|
||||||
view-system
|
view-system
|
||||||
|
@ -15,22 +15,23 @@
|
||||||
["update collection
|
["update collection
|
||||||
set quantity = quantity + ?
|
set quantity = quantity + ?
|
||||||
where card_id = ? and
|
where card_id = ? and
|
||||||
quality = ?"
|
quality = ? and
|
||||||
quantity-change card-id quality]))]
|
foil = ?"
|
||||||
|
quantity-change card-id quality foil?]))]
|
||||||
(if (= 0 num-updates)
|
(if (= 0 num-updates)
|
||||||
(first
|
(first
|
||||||
(vexec! view-system dt
|
(vexec! view-system dt
|
||||||
["insert into collection
|
["insert into collection
|
||||||
(card_id, quality, quantity)
|
(card_id, quality, quantity, foil)
|
||||||
values
|
values
|
||||||
(?, ?, ?)"
|
(?, ?, ?, ?)"
|
||||||
card-id quality quantity-change]))
|
card-id quality quantity-change foil?]))
|
||||||
num-updates))))
|
num-updates))))
|
||||||
|
|
||||||
(defn add-to-collection!
|
(defn add-to-collection!
|
||||||
[card-id quality]
|
[card-id quality foil?]
|
||||||
(update-collection! card-id quality 1))
|
(update-collection! card-id quality foil? 1))
|
||||||
|
|
||||||
(defn remove-from-collection!
|
(defn remove-from-collection!
|
||||||
[card-id quality]
|
[card-id quality foil?]
|
||||||
(update-collection! card-id quality -1))
|
(update-collection! card-id quality foil? -1))
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(def collection-routes
|
(def collection-routes
|
||||||
(routes
|
(routes
|
||||||
(POST "/collection/add" [card-id quality]
|
(POST "/collection/add" [card-id quality foil]
|
||||||
(collection/add-to-collection! card-id quality)
|
(collection/add-to-collection! card-id quality foil)
|
||||||
(response/json {:status "ok"}))
|
(response/json {:status "ok"}))
|
||||||
|
|
||||||
(POST "/collection/remove" [card-id quality]
|
(POST "/collection/remove" [card-id quality foil]
|
||||||
(collection/remove-from-collection! card-id quality)
|
(collection/remove-from-collection! card-id quality foil)
|
||||||
(response/json {:status "ok"}))))
|
(response/json {:status "ok"}))))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(defn owned-card
|
(defn owned-card
|
||||||
[card-id]
|
[card-id]
|
||||||
["select quality, quantity
|
["select quality, quantity, foil
|
||||||
from collection
|
from collection
|
||||||
where card_id = ?"
|
where card_id = ?"
|
||||||
card-id])
|
card-id])
|
||||||
|
|
Loading…
Reference in a new issue