            [:li [:a
                  {:onClick (fn [_ _]
                              (history/update-token-ids! history :properties nil)
-                             (fixed-scroll-to-element "projects-div"))}
+                             (fixed-scroll-to-element "properties-div"))}
                  (title-for properties :title-key :addressStreetTwo)]]]
           (om/build table devices {:opts {:histkey :devices}})])))))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; sensors
+(defn sensors-div [data owner]
+  (let [tables (:tables data)]
+    (reify
+      om/IRender
+      (render [_]
+        (let [{:keys [programmes projects properties devices active-components]} tables
+              history (om/get-shared owner :history)]
+          (html
+           [:div {:id "sensors-div"}
+            [:h2 {:id "sensors"} "Sensors"]
+            [:ul {:class "breadcrumb"}
+             [:li [:a
+                   {:onClick (fn [_ _]
+                               (history/update-token-ids! history :devices nil)
+                               (history/update-token-ids! history :properties nil)
+                               (history/update-token-ids! history :projects nil)
+                               (history/update-token-ids! history :programmes nil)
+                               (fixed-scroll-to-element "programmes-div"))}
+                   (title-for programmes)]]
+             [:li [:a
+                   {:onClick (fn [_ _]
+                               (history/update-token-ids! history :devices nil)
+                               (history/update-token-ids! history :properties nil)
+                               (history/update-token-ids! history :projects nil)
+                               (fixed-scroll-to-element "projects-div"))}
+                   (title-for projects)]]
+             [:li [:a
+                   {:onClick (fn [_ _]
+                               (history/update-token-ids! history :devices nil)
+                               (history/update-token-ids! history :properties nil)
+                               (fixed-scroll-to-element "properties-div"))}
+                   (title-for properties :title-key :addressStreetTwo)]]
+             [:li [:a
+                   {:onClick (fn [_ _]
+                               (history/update-token-ids! history :devices nil)
+                               (fixed-scroll-to-element "devices-div"))}
+                   (title-for devices :title-key [:location :name])]]]
+            (om/build sensor/table data {:opts {:histkey :sensors
+                                                :path    :readings}})]))))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Main View
 (defn programmes-tab [data owner]
   (let [{tables :tables} data]
     (reify

  (let [[type _] (str/split selected #"-")]
    type))

(defn programmes-div [tables owner]
  (reify
    om/IRender
    (render [_]
      (let [programmes (-> tables :programmes)]
        (html
         ;; hide div if we've already chosen something
         [:div {:id "programmes-div"}
          [:h1 "Programmes"]
          (om/build programmes-table programmes)])))))

;; our banner is 50px so we need to tweak the scrolling
(defn fixed-scroll-to-element [element]
  (-> (.getElementById js/document element)
                                    .scrollIntoView)
  (.scrollBy js/window 0 -50))

(defn programmes-table [cursor owner]
  (reify
    om/IRender
    (render [_]

                 (om/build projects-div tables)
                 (om/build properties-div tables)
                 (om/build devices-div tables)
                 ;; (om/build device-detail devices)
                 (om/build sensors-div data)
                 ;; (om/build sensor/define-data-set-button data)

                 [:div {:id "chart-div"}
                  [:h2 "Chart"]
                  [:div {:id "date-picker"}
                   (om/build dtpicker/date-picker data {:opts {:histkey :range}})]
                  (om/build chart-feedback-box (get-in data [:chart :message]))
                  [:div {:className "well" :id "chart" :style {:width "100%" :height 600}}
                   (om/build chart/chart-figure (:chart data))]
                  (om/build sensor/selection-dialog (:tables data)
                            {:opts {:id "sensor-selection-dialog"
                                    :handler (fn [e]
                                               (.preventDefault e)
                                               (POST (str "/4/entities/" (:selected @properties) "/datasets")
                                                     {:params          (:sensor-group @sensor-select)
                                                      :handler         #(println "Yah!")
                                                      :error-handler   #(println "Error!")
                                                      :response-format "application/edn"
                                                      :keywords?       true}))}})]]))))))


