Skip to content

Instantly share code, notes, and snippets.

Created Feb 14, 2017
What would you like to do?
(page "index.html")
(def table-data
[{:airbase "Foob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Snoob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Scoob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Toob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Spoob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Doob" :squadrons #{"I" "II" "III" "IV"}}
{:airbase "Snoop" :squadrons #{"I" "II" "III" "IV"}}]))
(def selected-squadrons (cell #{}))
(defn disconj [xs x]
((if (contains? xs x) disj conj) xs x))
(head (title "Tabular"))
:css {:border "1px solid black"}
(thead (th "Airbase"))
(let [open (cell #{})]
(for-tpl [[i base] (cell= (map-indexed vector table-data))]
:css {:border "1px solid black"}
(a :click #(swap! open disconj @i) :href "#" (cell= (:airbase base)))
(if-tpl (cell= (contains? open i))
(table (tr (for-tpl [squadron (cell= (sort (:squadrons base)))]
(a :href "#"
:click #(swap! selected-squadrons conj [(:airbase @base) @squadron])
(text "+~{squadron}")))))))))))))
(h3 "Selected squadrons"
(for-tpl [[base squadron] selected-squadrons]
(li (text "~{base}/~{squadron}")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment