Commit 95de2c3e authored by Bruno Burke's avatar Bruno Burke 😁

Merge branch 'converge-calculation-and-multistep-calculation-exercise' into develop

parents 02a3dea7 5853174c
......@@ -5,6 +5,9 @@
[calc-change-fn get-collats-for-vec]]
......@@ -22,13 +25,15 @@
(def modal-state-atom (reagent/atom {}))
(defn get-new-calculation []
{:id (get-unique-id "ae")
:name nil
:number {:significand nil :order-of-magnitude "0"}
:correct-points 0
:incorrect-points 0
:error-relative 1})
(defn get-new-calculation [with-units]
(let [base-object {:id (get-unique-id "ae")
:name nil
:number number-obj
:correct-points 0
:incorrect-points 0
:error-relative 1}]
(if with-units (assoc base-object :units [])
(defn set-prop-in-all-calcs [prop-key value calc-cursor]
(dorun (map-indexed
......@@ -68,14 +73,11 @@
:on-change #(change-fn (conj base-path :name) (str/triml %))}]]]
[ui/field {:label "Fehler (in %)"}
{:value (:error-relative calculation "1")
:on-change (fn [value]
(when-let [v (-> value
(re-matches #"^\-?(0*)(([1-9]\d*)|0)$"))
(nth 2))]
(change-fn (conj base-path :error-relative) (edn/read-string v))))}]]]
{:value (:error-relative calculation)
:min 0
:max 5
:on-change #(change-fn (conj base-path :error-relative) %)}]]]
[ui/field {:label "Punkte (korrekt)"}
......@@ -102,13 +104,15 @@
(defn new-exercise-form [{:keys [exercise-atom change-fn]}]
(let [exercise @exercise-atom
exercise-core (:core exercise)
with-units (:with-units exercise-core)
calculations (:calculations exercise-core)]
{:title "Berechnungen"
:footer-items [[:a.button.footer-item
{:on-click #(change-fn [:core :calculations] (conj calculations (get-new-calculation)))}
[:span.icon [:i.fas.fa-plus]] [:span "Berechnung"]]]}
{:on-click #(change-fn [:core :calculations] (conj calculations (get-new-calculation with-units)))}
[:span.icon [:i.fas.fa-plus]] [:span "Berechnung"]]]}
(fn [index calculation]
......@@ -32,9 +32,9 @@
(def modal-state-atom (reagent/atom {}))
(defn get-new-calculation [with-units]
(if with-units
{:number number-obj :units []}
{:number number-obj}))
(let [base-object {:number number-obj}]
(if with-units (assoc base-object :units [])
(defn fresh-answer-obj [calculation-ids with-units]
{:calculations (reduce (fn [res id] (assoc res id (get-new-calculation with-units))) {} calculation-ids)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment