Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created Feb 14, 2017
Embed
What would you like to do?
(page "index.html")
(def table-data
(cell
[{: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))
(html
(head (title "Tabular"))
(body
(table
:css {:border "1px solid black"}
(thead (th "Airbase"))
(tbody
(let [open (cell #{})]
(for-tpl [[i base] (cell= (map-indexed vector table-data))]
(tr
(td
:css {:border "1px solid black"}
(a :click #(swap! open disconj @i) :href "#" (cell= (:airbase base)))
(br)
(if-tpl (cell= (contains? open i))
(table (tr (for-tpl [squadron (cell= (sort (:squadrons base)))]
(td
(a :href "#"
:click #(swap! selected-squadrons conj [(:airbase @base) @squadron])
(text "+~{squadron}")))))))))))))
(h3 "Selected squadrons"
(ul
(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