Commit 739cf70b authored by Bruno Burke's avatar Bruno Burke 😁

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

parents a7ade4de 41a8aac5
Pipeline #47836 passed with stages
in 2 minutes and 19 seconds
(defproject lernmeister.components "1.0.0.6-dev"
(defproject lernmeister.components "1.0.0.7-dev"
:repositories [["internal" {:url "https://lernmeister.fh-muenster.de:8082/artifactory/libs-release"
:username "anonymous"}]]
:dependencies [[org.clojure/clojure "1.10.0"]
......
......@@ -35,7 +35,7 @@
(defn correct-tick-fa []
[:span.icon.has-background-white.has-text-success
[:i.far.fa-check-square]])
[:i.fas.fa-check-square]])
(defn neutral-tick []
(fn []
......@@ -43,7 +43,7 @@
(defn neutral-tick-fa []
[:span.icon.has-background-white.has-text-info
[:i.far.fa-meh]])
[:i.fas.fa-meh]])
(defn wrong-tick []
(fn []
......@@ -51,7 +51,7 @@
(defn wrong-tick-fa []
[:span.icon.has-background-white.has-text-danger
[:i.far.fa-times-circle]])
[:i.fas.fa-times-circle]])
(defn binary-input [{:keys [default-bits result on-change-fn bitcount]
:or {bitcount 8}}]
......
......@@ -26,8 +26,6 @@
[clj-helper.vector :as vhelper]
[reagent.core :as reagent]))
(def modal-state-atom (reagent/atom {}))
(defn get-new-calculation [with-units]
(let [base-object {:id (get-unique-id "ae")
:name nil
......@@ -54,7 +52,7 @@
:correct int-part
:incorrect (str "-" int-part))))))
(defn show-calculation [{:keys [exercise-core index calculation change-fn delete-fn]}]
(defn show-calculation [{:keys [exercise-core index calculation change-fn delete-fn modal-state-atom]}]
(let [calculations (:calculations exercise-core)
base-path [:core :calculations index]
answer (into {}
......@@ -104,7 +102,7 @@
:do-render true
:modal-state-atom modal-state-atom}]]]]))
(defn new-exercise-form [{:keys [exercise-atom change-fn]}]
(defn new-exercise-form [{:keys [exercise-atom change-fn modal-state-atom]}]
(let [exercise @exercise-atom
exercise-core (:core exercise)
with-units (:with-units exercise-core)
......@@ -130,7 +128,8 @@
:index index
:calculation calculation
:change-fn change-fn
:delete-fn #(change-fn [:core :calculations] (vec-remove calculations %))}])
:delete-fn #(change-fn [:core :calculations] (vec-remove calculations %))
:modal-state-atom modal-state-atom}])
calculations)]]
[ui/modal-panel
{:state (reagent/cursor modal-state-atom [:modal-visible?])
......@@ -234,11 +233,13 @@
exercise-scheme-version)))))}))
(defn additional-forms [exercise-atom]
(when (= :current (get-in @exercise-atom [:authoring :migration-status]))
[new-exercise-form {:exercise-atom exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)}]))
(reagent/with-let [modal-state-atom (reagent/atom {})]
(when (= :current (get-in @exercise-atom [:authoring :migration-status]))
[new-exercise-form {:exercise-atom exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)
:modal-state-atom modal-state-atom}])))
(defmethod e-edit/show-settings :calculation [_ _]
(fn [exercise-atom _]
......
......@@ -13,10 +13,12 @@
[lernmeister.components.exercise-types.calchelper
:refer
[build-latex-string calc-change-fn]]
[lernmeister.components.exercise-types.calculation.check
:refer
[get-calculation-ids]]
[lernmeister.components.exercise-types.calculation.migrate-answer
:refer
[answer-scheme-version migrate-answer]]
[lernmeister.components.exercise-types.calculation.check :refer [get-calculation-ids]]
[lernmeister.components.exercise-types.multistep-calculation.check
:refer
[number-obj]]
......@@ -31,8 +33,6 @@
[lernmeister.components.ui :as ui]
[reagent.core :as reagent]))
(def modal-state-atom (reagent/atom {}))
(defn get-new-calculation [with-units]
(let [base-object {:number number-obj}]
(if with-units (assoc base-object :units [])
......@@ -99,7 +99,7 @@
[:span.icon [:i.fas.fa-edit]]
[:span "Einheit"]]])]])]]))
(defn calculations [{:keys [exercise-core result answer change-fn]}]
(defn calculations [{:keys [exercise-core result answer change-fn modal-state-atom]}]
(let [calculations (:calculations exercise-core)]
(if (pos? (count calculations))
[:<>
......@@ -117,7 +117,7 @@
calculations)]
[:span "No calculations available"])))
(defn print-calculation-exercise [{:keys [answer exercise change-fn result options]}]
(defn print-calculation-exercise [{:keys [answer exercise change-fn result modal-state-atom options]}]
[:<>
[ui/card
{:title (str (:title exercise))}
......@@ -127,7 +127,8 @@
[calculations {:exercise-core (:core exercise)
:result result
:answer answer
:change-fn change-fn}]
:change-fn change-fn
:modal-state-atom modal-state-atom}]
(when result
[:div.has-text-right {:class (get-result-color-class result)}
[point-result {:result result}]])]]
......@@ -157,18 +158,20 @@
:used-units selectable-units}])]]])
(defn exercise-renderer [exercise {:keys [result answer on-change]}]
(let [calculation-ids (get-calculation-ids exercise)
ans-obj (or answer (fresh-answer-obj calculation-ids (get-in exercise [:core :with-units])))
options (ce-core/receive-options (:core exercise))]
(if-let [migrated-answer (migrate-if-necessary ans-obj :answer-scheme "calculation" answer-scheme-version
(partial migrate-answer calculation-ids))]
[print-calculation-exercise
{:answer migrated-answer
:exercise exercise
:change-fn (partial calc-change-fn on-change migrated-answer)
:result result
:options options}]
[unmigrateable-answer])))
(reagent/with-let [modal-state-atom (reagent/atom {})]
(let [calculation-ids (get-calculation-ids exercise)
ans-obj (or answer (fresh-answer-obj calculation-ids (get-in exercise [:core :with-units])))
options (ce-core/receive-options (:core exercise))]
(if-let [migrated-answer (migrate-if-necessary ans-obj :answer-scheme "calculation" answer-scheme-version
(partial migrate-answer calculation-ids))]
[print-calculation-exercise
{:answer migrated-answer
:exercise exercise
:change-fn (partial calc-change-fn on-change migrated-answer)
:result result
:options options
:modal-state-atom modal-state-atom}]
[unmigrateable-answer]))))
(defmethod ce-ex/render-exercise :calculation [_ _]
(fn [exercise data]
......
......@@ -37,8 +37,6 @@
[lernmeister.components.ui :as ui]
[reagent.core :as reagent]))
(def modal-state-atom (reagent/atom {}))
(defn sort-names-mapping [names-map]
(sort-by #(:name-text %)
(into [] (map (fn [item]
......@@ -67,7 +65,7 @@
:change-fn change-fn}]))
names-mapping)]])
(defn new-exercise-form [{:keys [exercise-atom change-fn phrase-fn]}]
(defn new-exercise-form [{:keys [exercise-atom change-fn phrase-fn modal-state-atom]}]
(let [exercise @exercise-atom
exercise-core (:core exercise)
with-oom (get-in exercise [:core :with-oom])
......@@ -245,12 +243,14 @@
exercise-scheme-version)))))}))
(defn additional-forms [exercise-atom]
(when (= :current (get-in @exercise-atom [:authoring :migration-status]))
[new-exercise-form {:exercise-atom exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)
:phrase-fn (partial get-phrase @exercise-atom [:core :phrasing] names-map)}]))
(reagent/with-let [modal-state-atom (reagent/atom {})]
(when (= :current (get-in @exercise-atom [:authoring :migration-status]))
[new-exercise-form {:exercise-atom exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)
:phrase-fn (partial get-phrase @exercise-atom [:core :phrasing] names-map)
:modal-state-atom modal-state-atom}])))
(defmethod e-edit/show-settings :multistep-calculation [exercise-atom options]
(fn [exercise-atom options]
......
......@@ -36,8 +36,6 @@
(def selectable-units (reagent/atom {}))
(def modal-state-atom (reagent/atom {}))
(defn b-crumb-step [{:keys [position current-position phrase-fn on-click-fn]}]
[:<>
[:li {:class (when (= position current-position) "is-active")}
......@@ -109,7 +107,7 @@
[:p "-"])))
(defn multistep-calculation-answer-form [{:keys [answer exercise-core change-fn phrase-fn current-position
result]}]
result modal-state-atom]}]
(let [path (:path @modal-state-atom)
description-ids (:description-ids exercise-core)
steps (:steps answer)
......@@ -208,7 +206,8 @@
[result-view {:step-result (:step-result @modal-state-atom)
:assignment-type (:assignment-type @modal-state-atom)}])]]]))
(defn print-multistep-calculation-exercise [{:keys [answer exercise change-fn phrase-fn result]}]
(defn print-multistep-calculation-exercise [{:keys [answer exercise change-fn phrase-fn result
modal-state-atom]}]
(reagent/with-let [current-position (reagent/atom :task)]
(let [exercise-core (:core exercise)
positions (as-> [:task] v
......@@ -233,7 +232,8 @@
:change-fn change-fn
:phrase-fn phrase-fn
:current-position @current-position
:result result}]]]
:result result
:modal-state-atom modal-state-atom}]]]
(if result
[:span.is-pulled-right [point-result {:result result}]]
(when-not (= @current-position :steps)
......@@ -243,15 +243,17 @@
:on-click-fn #(reset! current-position %)}]))]])))
(defn exercise-renderer [exercise {:keys [result answer on-change]}]
(if-let [migrated-answer (migrate-if-necessary answer :answer-scheme "multistep-calculation"
answer-scheme-version migrate-answer)]
[print-multistep-calculation-exercise
{:answer migrated-answer
:exercise exercise
:change-fn (partial calc-change-fn on-change migrated-answer)
:phrase-fn (partial get-phrase exercise [:core :phrasing] names-map)
:result result}]
[unmigrateable-answer]))
(reagent/with-let [modal-state-atom (reagent/atom {})]
(if-let [migrated-answer (migrate-if-necessary answer :answer-scheme "multistep-calculation"
answer-scheme-version migrate-answer)]
[print-multistep-calculation-exercise
{:answer migrated-answer
:exercise exercise
:change-fn (partial calc-change-fn on-change migrated-answer)
:phrase-fn (partial get-phrase exercise [:core :phrasing] names-map)
:result result
:modal-state-atom modal-state-atom}]
[unmigrateable-answer])))
(defmethod ce-ex/render-exercise :multistep-calculation [_ _]
(fn [exercise data]
......
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