From fc674968939fc571b5308891039e1406ee37bfc7 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 29 Jun 2016 10:38:33 -0400 Subject: [PATCH] add rarity search filter --- src/mtgcoll/client/components/search.cljs | 23 +++++++++++++++++++++++ src/mtgcoll/views/functions/cards.clj | 1 + 2 files changed, 24 insertions(+) diff --git a/src/mtgcoll/client/components/search.cljs b/src/mtgcoll/client/components/search.cljs index 1f6c160..8a2a9bd 100644 --- a/src/mtgcoll/client/components/search.cljs +++ b/src/mtgcoll/client/components/search.cljs @@ -71,6 +71,26 @@ check-label])) 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 [value on-change invalid? on-enter field-def] (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} :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 :=]} + :rarity {:label "Rarity" :type :dropdown :comparisons [:=] :choices ["Basic Land" "Common" "Mythic Rare" "Rare" "Special" "Uncommon"]} :text {:label "Card Text" :type :text :comparisons [:like :=]} :artist {:label "Artist" :type :text :comparisons [:like :=]} :number {:label "Card Number" :type :text :comparisons [:=]} @@ -127,6 +148,7 @@ :boolean false :numeric 0 :text "" + :dropdown "" :checkbox #{}) :invalid? false :validation-fn (:validation-fn field-def) @@ -134,6 +156,7 @@ :component (or (:component field-def) (case field-type :boolean boolean-search-field-element + :dropdown dropdown-search-field-element generic-search-field-element))} (if filter-id {:filter-id filter-id}))))) diff --git a/src/mtgcoll/views/functions/cards.clj b/src/mtgcoll/views/functions/cards.clj index 4e70e98..64f8aeb 100644 --- a/src/mtgcoll/views/functions/cards.clj +++ b/src/mtgcoll/views/functions/cards.clj @@ -156,6 +156,7 @@ := [:= :color_identity (string/join "," colors)] :like [:like :color_identity (str "%" (string/join "%" colors) "%")]))) :type (text-comparison-fn [:type]) + :rarity (text-comparison-fn [:rarity] true) :text (text-comparison-fn [:text]) :artist (text-comparison-fn [:artist]) :number (text-comparison-fn [:number] true)