 
 ;;;;;;;;;;; Bootstrap ;;;;;;;;;;;;
 
-(defn create-form-and-chart [model-path device-item chart-item]
+(defn create-form-and-chart [model-path chart-comp]
   (fn [cursor owner]
     (reify
       om/IRender
       (render [this]
-        (dom/div #js {:className "devices"}
+        (dom/div nil
                  (dom/h3 nil (str "Metering data - " (get-in cursor [:property])))
                  (dom/h4 nil "Select devices to be plotted on the chart:")
-                 (dom/form #js {:className "devices-form"}
-                           (om/build-all device-item
-                                         (get-in cursor model-path)
-                                         {:key :hecuba/name})
-                           (om/build chart-item cursor)))))))
+                 (om/build chart-comp cursor))))))
 
 
-(om/root chart-state (create-form-and-chart [:devices]
-                                                   (device-list-item [:hecuba/name :name])
-                                                   (chart-item [:hecuba/name :name :data]))
+(om/root chart-state (create-form-and-chart [:devices] (chart-component [:hecuba/name :name :data]))
                  (.getElementById js/document "app"))
 
 

(defn- fetch-data [device-id]
  (get mock-data device-id))

;;;;;;;;;; Components ;;;;;;;;;;;;;;;;;

(def chart-state
  (atom {:selected []
         :property "rad003"
         :devices [{:hecuba/name "01"
                    :name "External temperature"}

                    :name "External humidity"}]
         :data []}))

;;;;;;;;;; Chart Component ;;;;;;;;;;

(defn chart-component
  [device-details]
  (fn [cursor opts]
    (reify
      om/IWillMount
      (will-mount [this]
        (.log js/console "I will mount")
        (om/update! cursor update-in [:data] (fn [data] (get mock-data (:selected cursor)))))
      om/IRender
      (render [this]
        (.log js/console "I render")
        (dom/div nil
                 (dom/p nil (apply str (interpose "," (get-in cursor [:selected]))))
                 (dom/form nil
                           (for [device (get cursor :devices)]
                             (let [device-id   (str (:hecuba/name device))
                                   device-name (str (:name device))]
                               (.log js/console "I did mount" device-id device-name)
                               (dom/input #js {:type "checkbox"
                                               :onClick (fn [e]
                                                          (.dir js/console e)
                                                          (om/update! cursor update-in [:selected]
                                                                      conj device-id))}
                                          device-name))))
                 (dom/div #js {:id "chart"})))
      om/IDidUpdate
      (did-update [this prev-props prev-state root-node]
        (.log js/console "I did update")
        (let [n (.getElementById js/document "chart")]
             (while (.hasChildNodes n)
               (.removeChild n (.-lastChild n))))
         (let [Chart        (.-chart dimple)
              svg          (.newSvg dimple "#chart" 400 350)
              measurements []
