        (map :environment)
        distinct))
 
-(defn systems-by-environment [environment-names host-status-pairs]
+(defn systems-by-environment [environment-names host-status-pairs dont-collapse]
   (let [the-environments (utils/prefer-order-of environment-names
                                                 (environments host-status-pairs)
                                                 str/lower-case)]
     (zipmap the-environments
-            (map #(hosts-for-environment host-status-pairs %) the-environments))))
+            (map #(hosts-for-environment host-status-pairs % dont-collapse) the-environments))))
 
 
 (defn- patchwork-as-html [patchwork params]

            [hiccup.core :refer [h html]]))

(defn- collapse-all-green-hosts [hosts]
  (let [sorted-hosts (sort-by (fn [[{index :index} _]] index) hosts)]
    (if (every? (fn [[_ {color :color}]] (= :green color)) sorted-hosts)
      (take 1 sorted-hosts)
      sorted-hosts)))

(defn- hosts-for-environment [host-list environment]
  (->> host-list
       (filter (fn [[{host-environment :environment} _]]
                 (= environment host-environment)))
       (group-by (fn [[{system :system} _]] system))
       (mapcat (fn [[_ hosts]]
                 (collapse-all-green-hosts hosts)))
       (sort-by (fn [[{system :system} _]] system))))

(defn- environments [host-status-pairs]
  (->> host-status-pairs

               html))

(defn render [host-status-pairs page-template environment-names params]
  (let [collapse  (= (get params "collapse") "true")
        patchwork (systems-by-environment environment-names host-status-pairs collapse)]
    (in-template (patchwork-as-html patchwork params)
                 page-template)))
