Skip to content

Instantly share code, notes, and snippets.

@sritchie sritchie/finisherrow.clj
Last active Aug 29, 2015

Embed
What would you like to do?
(defn header-row []
(kioo/component "public/html/timing.html"
[:table.finishers :thead]
{[:td.event-column] (kioo/substitute nil)}))
(defn finisher-rows []
(kioo/component "public/html/timing.html"
[:table.finishers]
{[:thead] (kioo/content header-row)
[:tbody] (kioo/content
(let [{:keys [stopwatch focus-cell]} @timingapp]
(reverse
(map-indexed (fn [idx result]
(finisher-row {:result result
:rank idx
:focus-rank focus-cell}))
(:results stopwatch)))))}))
(defn finisher-row
"The rank is displayed as 1-based, but treated everywhere else as
zero based."
[{:keys [result rank focus-rank]}]
(let [racer-text (atom (:id result))
time-text (atom (:time result))]
(kioo/component "public/html/timing.html"
[:tr.finisher]
{[:td.rank] (kioo/content (str (inc rank) "."))
[:input.timing-boat-number] (kioo/do->
(if (= rank focus-rank)
(kioo/set-attr :autoFocus true)
identity)
(kioo/set-attr :name (str "racer-number" rank)
:data-rank rank
:data-event-number (:event-num result)
:onChange (fn [_] nil)
:value @racer-text)
(if (result/valid-racer-number? @racer-text)
(kioo/remove-class "error")
(kioo/add-class "error")))
[:input.timestamp] (let [time @time-text]
(kioo/do->
(kioo/set-attr :ref "timeField"
:value time
:placeholder (when (empty? time)
"hh:mm:ss.ms")
:data-event-number (:event-num result)
:data-rank rank
:name (str "time" rank))
(if (result/valid-racer-time? time)
(kioo/remove-class "error")
(kioo/add-class "error"))))
[:a.remove] (kioo/set-attr :data-rank rank)
[:a.remove :img] (kioo/set-attr :src (:remove @cdn-assets))
[:a.insert] (kioo/set-attr :data-rank rank)
[:a.insert :img] (kioo/set-attr :src (:insert @cdn-assets))
[:td.roweventlabel] (kioo/substitute nil)
[:td.rowlabel] (let [label (info-label (:id result))]
(kioo/do-> (kioo/set-attr :name (str "label" rank))
(kioo/content label)
(if (= label "Not Found!")
(kioo/add-class "error")
(kioo/remove-class "error"))))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.