Commit d85fdd75 authored by Joachim Schunk's avatar Joachim Schunk

make show-view work with bulma-modal-panel

parent 3c337d4c
Pipeline #45151 passed with stages
in 1 minute and 30 seconds
(ns lernmeister.components.exercise-types.multistep-calculation.views.common
(:require [lernmeister.components.common :refer [latex-span]]
[lernmeister.components.exercise-types.calchelper
:refer
[build-units-latex-string units-to-set]]
[lernmeister.components.exercise-types.multistep-calculation.check
:refer
[number-obj]]
......@@ -7,7 +10,9 @@
[lernmeister.components.modal-editor.helper
:refer
[get-var-symbol-data]]
[lernmeister.components.modal-editor.renderers :refer [sign-with-subtext]]
[lernmeister.components.modal-editor.renderers
:refer
[sign-with-subtext]]
[lernmeister.components.ui :as ui]))
(def editor-type-mapping {:edit :calculation :show :calc-answer})
......@@ -68,6 +73,15 @@
{:path (conj step-path :var-mapping)}
{:path [:authoring (keyword step-id) :number]}]))
(defn add-to-selectable-units [path selectable-units subject]
(let [cur-units (get-in subject path)]
(when (not-empty cur-units)
(let [units-ident (units-to-set cur-units)]
(when-not (contains? @selectable-units units-ident)
(swap! selectable-units assoc units-ident
{:units cur-units
:latex-str (build-units-latex-string cur-units)}))))))
(defn assignment-type-from-step-idx [step-idx assignments steps]
(:type (find-in-vec-by-id assignments (get-in steps [step-idx :assignment-id]))))
......@@ -106,7 +120,8 @@
[:div.level-item
[blue-line]]]]]))
(defn discrete-phys-val-editor [{:keys [context assignment-type path collats-fn symbol-data modal-state-atom latex-number-str latex-units-str]}]
(defn discrete-phys-val-editor [{:keys [context assignment-type path collats-fn symbol-data modal-state-atom
latex-number-str latex-units-str selectable-units]}]
(let [editable-number? (and assignment-type
(not (and (= context :edit) (not= assignment-type :constant))))
editable-units? (and assignment-type (not= context :edit))]
......@@ -128,17 +143,21 @@
[latex-span latex-units-str]]
[:div.right-icon (if editable-units?
{:class "has-background-success green-border pointer"
:on-click (fn [] (reset! modal-state-atom
{:modal-visible? true
:path path
:type :units-only
:collats-fn collats-fn
:symbol-data symbol-data}))}
:on-click (fn []
(reset! modal-state-atom
{:modal-visible? true
:on-close-fn (partial
add-to-selectable-units
(conj path :units) selectable-units)
:path path
:type :units-only
:collats-fn collats-fn
:symbol-data symbol-data}))}
{:class "has-background-grey-light grey-border"})
[:span.icon [:i.far.fa-edit]]]]))
(defn step-config [{:keys [step vars path assocs params assignments steps change-fn collats-fn
phys-val-collats-fn symbol-data modal-state-atom latex-number-str
phys-val-collats-fn symbol-data modal-state-atom selectable-units latex-number-str
latex-units-str context assignment-type step-result]}]
[:<>
[:td
......@@ -202,4 +221,5 @@
:symbol-data symbol-data
:modal-state-atom modal-state-atom
:latex-number-str latex-number-str
:latex-units-str latex-units-str}])]])
:latex-units-str latex-units-str
:selectable-units selectable-units}])]])
......@@ -47,8 +47,8 @@
(let [modified-answer (vec-remove answer (last path))]
(change-fn [] modified-answer (change-var-mapping-collats id modified-answer))))
(defn answer-step-input [{:keys [answer step assocs params assignments path change-fn modal-id
answer-id result number-of-steps modal-state-atom]}]
(defn answer-step-input [{:keys [answer step assocs params assignments path change-fn answer-id result
number-of-steps modal-state-atom selectable-units]}]
(let [step-id (:id step)
assignment-type (:type (find-in-vec-by-id assignments (:assignment-id step)))
last-step? (= (inc (last path)) number-of-steps)
......@@ -71,8 +71,8 @@
:collats-fn #(change-assignment-collats step-id answer (last path))
:phys-val-collats-fn #(change-var-mapping-collats step-id answer)
:symbol-data (get-step-symbol-data step assocs assignments)
:modal-id modal-id
:modal-state-atom modal-state-atom
:selectable-units selectable-units
:latex-number-str latex-number-str
:latex-units-str latex-units-str
:context :show
......@@ -86,8 +86,9 @@
:on-click #(step-delete change-fn path answer step-id)}
[:span.icon [:i.fas.fa-minus]]])]]]))
(defn answer-steps [{:keys [answer change-fn phrase-fn result modal-id description-id descriptions assocs
params assignments number-of-steps number-of-answer-steps modal-state-atom]}]
(defn answer-steps [{:keys [answer change-fn phrase-fn result description-id descriptions assocs params
assignments number-of-steps number-of-answer-steps modal-state-atom
selectable-units]}]
[:<>
(when description-id
[:div.row
......@@ -113,11 +114,11 @@
:assignments assignments
:path [:steps index]
:change-fn change-fn
:modal-id modal-id
:answer-id (get-in answer [index :id])
:result result
:number-of-steps number-of-steps
:modal-state-atom modal-state-atom}])
:modal-state-atom modal-state-atom
:selectable-units selectable-units}])
(range number-of-answer-steps))
(when (and (not result) (< number-of-answer-steps number-of-steps))
[step-add-tr {:add-fn #(change-fn [:steps] (conj answer (get-new-answer-step assocs)))}])]]])
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