add rarity search filter

This commit is contained in:
Gered 2016-06-29 10:38:33 -04:00
parent 8945c524be
commit fc67496893
2 changed files with 24 additions and 0 deletions

View file

@ -71,6 +71,26 @@
check-label])) check-label]))
choices)]) choices)])
(defn dropdown-search-field-element
[value on-change invalid? on-enter {:keys [choices] :as field-def}]
[bs/FormGroup
(if invalid? {:validation-state "error"})
[bs/FormControl
{:component-class "select"
:value value
:on-change #(on-change (get-field-value %))
:on-key-up (fn [e]
(if (= 13 (.-keyCode e))
(if on-enter (on-enter))))}
(->> choices
(map
(fn [choice]
(let [[choice-label choice-value] (if (vector? choice) choice [choice choice])]
^{:key choice-value}
[:option {:value choice-value} choice-label])))
(cons ^{:key ""} [:option ""]))]
(if invalid? [bs/FormControl.Feedback])])
(defvc set-search-field-element (defvc set-search-field-element
[value on-change invalid? on-enter field-def] [value on-change invalid? on-enter field-def]
(let [sets (view-cursor :simple-sets-list)] (let [sets (view-cursor :simple-sets-list)]
@ -103,6 +123,7 @@
:colors {:label "Colors" :type :checkbox :comparisons [:like :=] :choices ["Black" "Blue" "Green" "Red" "White"] :component checkboxes-search-field-element} :colors {:label "Colors" :type :checkbox :comparisons [:like :=] :choices ["Black" "Blue" "Green" "Red" "White"] :component checkboxes-search-field-element}
:color-identity {:label "Color Identity" :type :checkbox :comparisons [:like :=] :choices [["Black" "B"] ["Blue" "U"] ["Green" "G"] ["Red" "R"] ["White" "W"]] :component checkboxes-search-field-element} :color-identity {:label "Color Identity" :type :checkbox :comparisons [:like :=] :choices [["Black" "B"] ["Blue" "U"] ["Green" "G"] ["Red" "R"] ["White" "W"]] :component checkboxes-search-field-element}
:type {:label "Type" :type :text :comparisons [:like :=]} :type {:label "Type" :type :text :comparisons [:like :=]}
:rarity {:label "Rarity" :type :dropdown :comparisons [:=] :choices ["Basic Land" "Common" "Mythic Rare" "Rare" "Special" "Uncommon"]}
:text {:label "Card Text" :type :text :comparisons [:like :=]} :text {:label "Card Text" :type :text :comparisons [:like :=]}
:artist {:label "Artist" :type :text :comparisons [:like :=]} :artist {:label "Artist" :type :text :comparisons [:like :=]}
:number {:label "Card Number" :type :text :comparisons [:=]} :number {:label "Card Number" :type :text :comparisons [:=]}
@ -127,6 +148,7 @@
:boolean false :boolean false
:numeric 0 :numeric 0
:text "" :text ""
:dropdown ""
:checkbox #{}) :checkbox #{})
:invalid? false :invalid? false
:validation-fn (:validation-fn field-def) :validation-fn (:validation-fn field-def)
@ -134,6 +156,7 @@
:component (or (:component field-def) :component (or (:component field-def)
(case field-type (case field-type
:boolean boolean-search-field-element :boolean boolean-search-field-element
:dropdown dropdown-search-field-element
generic-search-field-element))} generic-search-field-element))}
(if filter-id (if filter-id
{:filter-id filter-id}))))) {:filter-id filter-id})))))

View file

@ -156,6 +156,7 @@
:= [:= :color_identity (string/join "," colors)] := [:= :color_identity (string/join "," colors)]
:like [:like :color_identity (str "%" (string/join "%" colors) "%")]))) :like [:like :color_identity (str "%" (string/join "%" colors) "%")])))
:type (text-comparison-fn [:type]) :type (text-comparison-fn [:type])
:rarity (text-comparison-fn [:rarity] true)
:text (text-comparison-fn [:text]) :text (text-comparison-fn [:text])
:artist (text-comparison-fn [:artist]) :artist (text-comparison-fn [:artist])
:number (text-comparison-fn [:number] true) :number (text-comparison-fn [:number] true)