 (defn input [label]
   [:input#match-val.query-input.form-control {:type "text" :placeholder label}])
 
-(defn wg4 [el & extras]
-  [:div.col-sm-4 el])
+(defn label [label target]
+  [:label.col-sm-2.control-label {:for target} label])
 
-(defn wg3 [el & extras]
-  [:div.col-sm-3 el])
+(defn group [el & extras]
+  [:div.form-group el extras])
 
-(defn wg2 [el & extras]
-  [:div.col-sm-2 el])
-
-(defn wg10 [el & extras]
-  [:div.col-sm-10 el])
-
-(defn wg5 [el & extras]
-  [:div.col-sm-5 el])
-
-(defn el-header [txt]
-  [:h3 {:style "float: none; margin-left: auto; margin-right: auto;"} txt])
+(defn ctl [el cols]
+  [:div {:class (nth bs-columns cols)} el])
 
 (defn query-builder [db coll segments]
   (html

(def reduce-operators ["count","min","max","sum","avg","stdev"])
(def date-periods ["all time","last year","last 6 months","last 30 days","last 7 days","last day","last hour"])
(def graph-types ["spline","column","line","area","bar","areaspline","scatter"])

(defn dropdown-item [item]
  [:option {:value item} item])

              [:h3.panel-title "Builder"]]

            [:div.panel-body

              [:form.form-horizontal {:role "form"}

                (group
                  (label "Over the range" "date-period")
                  (ctl (dropdown date-periods "date-period") 4)
                  (label "Group time by" "group-times")
                  (clt (dropdown group-times "group-times") 4))

                (group
                  (label "Match where" "match-entities")
                  (clt (dropdown segments "none" "match-entities") 4)
                  (clt (dropdown match-operators "none" "match-ops") 2)
                  (clt (input "value") 4))

                (group
                  (label "Group results by" "group-entities")
                  (clt (dropdown segments "none" "group-entities") 10))

                (group
                  (label "Aggregate" "reduce-entities")
                  (clt (dropdown segments "reduce-entities") 4)
                  (label "Over the statistic" "reduce-ops")
                  (clt (dropown reduce-operators "reduce-ops") 4))

                (group
                  (label "Display results as" "graph-type")
                  (clt (dropdown graph-types "graph-type") 10))

                [:div.form-group
                  [:div.col-sm-10.col-sm-offset-2
