                 (dom/p nil (str "Latitude: " latitude))
                 (dom/p nil (str "Longitude: " longitude)))))))
 
+(defn row-for [{:keys [selected data]}]
+  (find-first #(= (:id %) selected) data))
+
 (defn title-for [cursor & {:keys [title-key] :or {title-key :name}}]
-  (some->> (get-in (row-for cursor) (if (vector? title-key) title-key (vector title-key)))
-           (str " - ")))
+  (let [row (row-for cursor)]
+    (get-in row (if (vector? title-key) title-key (vector title-key)))))
+
+(defn title-for-sensor [{:keys [selected]}]
+  (let [[type _] (str/split selected #"-")]
+    type))
 
 (defn programmes-table [cursor owner]
   (reify


        ;; TODO sort out duplication here, wrap (on/build table ...) calls probably.
        ;;
        (let [{:keys [programmes projects properties devices sensor-select]} tables]
          ;; (println "Tables: " tables)
          (html [:div
                 ;;(om/build clear-tables data)
                 [:h1 {:id "programmes"} (:title data)]
                 (om/build programmes-table programmes)

                 [:h2 {:id "projects"} "Projects" [:small (title-for programmes)]]
                 (om/build table projects {:opts {:histkey :projects}})

                 [:h2  {:id "properties"} "Properties" [:small (title-for programmes) (title-for projects)]]
                 (om/build table properties {:opts {:histkey :properties}})

                 [:h2 {:id "devices"} "Devices" [:small (title-for programmes) (title-for projects) (title-for properties :title-key :addressStreetTwo)]]
                 (om/build table devices {:opts {:histkey :devices}})
                 
                 (om/build device-detail devices)

                 [:h2 {:id "sensors"} "Sensors" [:small (title-for programmes) (title-for projects) (title-for properties :title-key :addressStreetTwo) (title-for devices :title-key [:location :name])]]
                 (om/build sensor/table data {:opts {:histkey :sensors
                                                     :path    :readings}})
                 (om/build sensor/define-data-set-button data)

                 [: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]))


(defn update-when [x pred f & args]
  (if pred (apply f x args) x))

(defn uri-for-selection-change
  "Returns the uri to load because of change of selection. Returns nil
