(page "index.html"
(:require [app.rpc :as rpc]
[cljs.pprint :refer [pprint]]
[cljsjs.semantic-ui :as ui]
[clojure.string :refer [trim]]
[Blockly]
[Blockly.Blocks.loops]
[Blockly.Blocks.lists]
[Blockly.Blocks.texts]
[Blockly.Blocks.procedures]
[Blockly.Blocks.math]
[Blockly.Blocks.variables]
[Blockly.Blocks.colour]
[Blockly.Blocks.logic]
[Blockly.Msg.en]))
(rpc/init)
(defc= state rpc/state)
(defc= error rpc/error)
(def toolbox
"
")
(defelem blockly-workspace
[{:keys [options] :as attr} kids]
(let [elem (div (dissoc attr :options) kids)]
(with-init!
(set! (.-workspace elem)
(.inject js/Blockly elem (clj->js options))))
elem))
(html
(head
(link :rel "stylesheet" :type "text/css"
:href "cljsjs/semantic-ui/common/semantic.min.css")
(title "Tankputer"))
(body
(h1 "Status")
(let [current (cell= (reduce + (map #(float (second %))
(:current (:pm state)))))]
(h2 (text "Power (~{current} A)")))
(table
(loop-tpl
:bindings [[port name state] (cell= (:status (:pm state)))]
(let [toggle (cell false)
name (cell= (trim name))
name-input (input :toggle toggle :value name)]
(tr
(td port)
(td :click #(reset! toggle true)
(span :toggle (cell= (not toggle))
:text (cell= (if (empty? name) "(unnamed)" name)))
(form :submit #(do (rpc/set-name @port (.-value name-input))
(reset! toggle false))
name-input
(input :toggle toggle :type "submit")))
(td state)
(td (button :click #(rpc/turn-on @port) "On")
(button :click #(rpc/turn-off @port) "Off"))))))
(h2 "Temperature")
(ul
(loop-tpl :bindings [[id temp] (cell= (:state (:temps state)))]
(let [millicelsius (cell= (int temp))
fahrenheit (cell= (+ 32 (* 0.0018 millicelsius)))]
(li (text "Sensor ~{id}: ~{fahrenheit} \u00b0F")))))
(textarea :text (cell= (with-out-str (pprint state))))))
;; vim: set expandtab ts=2 sw=2 filetype=clojure :