Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

some refactoring, still ugly

  • Loading branch information...
commit 4c94e535eba4565a12e5f71b61f74c8e7a7ccaf3 1 parent 95c74b6
Martin Sander authored

Showing 1 changed file with 70 additions and 69 deletions. Show diff stats Hide diff stats

  1. +70 69 clojurescript/src/foreclojure/core.cljs
139 clojurescript/src/foreclojure/core.cljs
@@ -63,9 +63,73 @@
63 63 (.hide ($ "#golfgraph") "fast")
64 64 (.html ($ "#graph-link") "View Chart"))
65 65
66   -(def wait-time-per-item 500 )
  66 +(def wait-time-per-item 500)
67 67 (def wait-time wait-time-per-item) ; TODO change to local val
68 68 (def cont true)
  69 +(def editor)
  70 +(def session)
  71 +
  72 +(defn click-handler []
  73 + (let [text (. session (getValue))
  74 + id (.attr ($ "#id") "value")
  75 + images (.find ($ ".testcases") "img")
  76 + animation-time 800
  77 + before-send (fn [data]
  78 + (set! cont true)
  79 + (let [anim (fn anim [high]
  80 + (when cont
  81 + (.animate images
  82 + (js-map {"opacity" (if high 1.0 0.1)})
  83 + animation-time)
  84 + (set-timeout (fn [] (anim (not high))))
  85 + ))]
  86 + (.each images (fn [index element]
  87 + (set-icon-color element "blue")))
  88 + (.text ($ "#message-text")
  89 + "Executing unit tests...")
  90 + (set-timeout change-to-code-view 0)
  91 + (set-timeout (fn [] (anim false)))
  92 + ))
  93 + error (fn [data string error]
  94 + (.text
  95 + ($ "#message-text")
  96 + (str "An Error occured: " error)))
  97 + success (fn [data]
  98 + (let [failing-test (.failingTest data)
  99 + get-color-for (fn [index]
  100 + (if (= index failing-test)
  101 + "red" "green"))
  102 + test-was-executed (fn [index]
  103 + (<= index failing-test))
  104 + set-color (fn [index element]
  105 + (let [color (get-color-for index)]
  106 + (set! wait-time (* wait-time-per-item (inc index)))
  107 + (set-icon-color element color wait-time)))
  108 + set-messages (fn []
  109 + (.html ($ "#message-text") (.message data))
  110 + (.html ($ "#golfgraph") (.golfChart data))
  111 + (.html ($ "#golfscore") (.golfScore data))
  112 + (configure-golf))
  113 + stop-animation (fn []
  114 + (set! cont false)
  115 + (.stop images true)
  116 + (.css images (js-map {"opacity" 1.0})))
  117 + ]
  118 + (set-timeout stop-animation 0)
  119 + (.each
  120 + (.filter images test-was-executed)
  121 + set-color)
  122 + (set-timeout set-messages wait-time)))]
  123 + (.ajax $ (js-map
  124 + {"type" "POST"
  125 + "url" (str "/rest/problem/" id)
  126 + "dataType" "json"
  127 + "data" (js-map {"id" id "code" text})
  128 + "timeout" 20000 ; default clojail timeout is 10000
  129 + "beforeSend" before-send
  130 + "success" success
  131 + "error" error}))
  132 + false))
69 133
70 134 (defn configure-code-box []
71 135 (let [old-box ($ "#code-box")]
@@ -76,74 +140,10 @@
76 140 "</pre></div>"
77 141 "<input type=\"hidden\" value=\"blank\" name=\"code\" id=\"code\">"))
78 142 (when-not (zero? (.length ($ "#run-button")))
79   - (let [editor (.edit ace "editor")
80   - clojure-mode (.Mode (js-require "ace/mode/clojure"))
81   - session (.getSession editor ())
82   - click-handler (fn []
83   - (let [text (. session (getValue))
84   - id (.attr ($ "#id") "value")
85   - images (.find ($ ".testcases") "img")
86   - animation-time 800
87   - before-send (fn [data]
88   - (set! cont true)
89   - (let [anim (fn anim [high]
90   - (when cont
91   - (.animate images
92   - (js-map {"opacity" (if high 1.0 0.1)})
93   - animation-time)
94   - (set-timeout (fn [] (anim (not high))))
95   - ))]
96   - (.each images (fn [index element]
97   - (set-icon-color element "blue")))
98   - (.text ($ "#message-text")
99   - "Executing unit tests...")
100   - (set-timeout change-to-code-view 0)
101   - (set-timeout (fn [] (anim false)))
102   - ))
103   - error (fn [data string error]
104   - (.text
105   - ($ "#message-text")
106   - (str "An Error occured: " error)))
107   - success (fn [data]
108   - (let [failing-test (.failingTest data)
109   - get-color-for (fn [index]
110   - (if (= index failing-test)
111   - "red" "green"))
112   - test-was-executed (fn [index]
113   - (<= index failing-test))
114   - set-color (fn [index element]
115   - (let [color (get-color-for index)]
116   - (set! wait-time (* wait-time-per-item (inc index)))
117   - (set-icon-color element color wait-time)))
118   - set-messages (fn []
119   - (.html ($ "#message-text") (.message data))
120   - (.html ($ "#golfgraph") (.golfChart data))
121   - (.html ($ "#golfscore") (.golfScore data))
122   - (configure-golf))
123   - stop-animation (fn []
124   - (set! cont false)
125   - (.stop images true)
126   - (.css images (js-map {"opacity" 1.0})))
127   - ]
128   - (set-timeout stop-animation 0)
129   - (.each
130   - (.filter images test-was-executed)
131   - set-color)
132   - (set-timeout set-messages wait-time)
133   - )
134   - )]
135   - (.ajax $ (js-map
136   - {"type" "POST"
137   - "url" (str "/rest/problem/" id)
138   - "dataType" "json"
139   - "data" (js-map {"id" id "code" text})
140   - "timeout" 20000 ; default clojail timeout is 10000
141   - "beforeSend" before-send
142   - "success" success
143   - "error" error}))
144   - false))]
  143 + (set! editor (.edit ace "editor"))
  144 + (set! session (. editor (getSession)))
  145 + (let [clojure-mode (.Mode (js-require "ace/mode/clojure"))]
145 146 (.setTheme editor "ace/theme/textmate")
146   - (.click ($ "#run-button") click-handler)
147 147 (doto session
148 148 (.setMode (clojure-mode.))
149 149 (.setUseSoftTabs true)
@@ -153,7 +153,8 @@
153 153 (.getElementById "editor")
154 154 .style
155 155 .fontSize)
156   - 13)))))
  156 + 13)
  157 + (.click ($ "#run-button") click-handler)))))
157 158
158 159 (defn on-document-ready []
159 160 (configure-data-tables)

0 comments on commit 4c94e53

Please sign in to comment.
Something went wrong with that request. Please try again.