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 @@
[lernmeister.components.exercise-types.calchelper
:refer
[calc-change-fn get-collats-for-vec]]
[lernmeister.components.exercise-types.multistep-calculation.check
:refer
[number-obj]]
[lernmeister.components.exercise-types.calculation.components.migration
:refer
[migrate-exercise-atom]]
......@@ -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 [])
base-object)))
(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 %))}]]]
[:div.column.is-half
[ui/field {:label "Fehler (in %)"}
[ui/input-text
{: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))))}]]]
[ui/input-range
{:value (:error-relative calculation)
:min 0
:max 5
:on-change #(change-fn (conj base-path :error-relative) %)}]]]
[:div.column.is-half
[ui/field {:label "Punkte (korrekt)"}
[ui/input-text
......@@ -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)]
[:<>
[ui/card
{: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"]]]}
:footer-items
[[:a.button.footer-item
{:on-click #(change-fn [:core :calculations] (conj calculations (get-new-calculation with-units)))}
[:span.icon [:i.fas.fa-plus]] [:span "Berechnung"]]]}
[:div.new-question.card-panel.z-depth-3
(map-indexed
(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 [])
base-object)))
(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