Ab sofort ist der Login auf der Weboberfläche von git.fh-muenster.de bevorzugt über FH Muenster SSO möglich.

Commit 46485d73 authored by Bruno Burke's avatar Bruno Burke 😁

add infos to unit/value modal in calculations, ui changes for calculations

parent 16517112
Pipeline #26836 passed with stages
in 2 minutes and 40 seconds
(defproject lernmeister.components "0.4.9.16"
(defproject lernmeister.components "0.4.9.17"
:repositories [["internal" {:url "https://lernmeister.fh-muenster.de:8082/artifactory/libs-release"
:username "anonymous"}]]
:dependencies [[org.clojure/clojure "1.10.0"]
......
......@@ -95,7 +95,7 @@
(fn [exercise-core]
(let [calculations (reagent/cursor exercise-core [:calculations])]
[:div.new-question.card-panel.z-depth-3
[:p [:b "Calculations"]]
[:p [:b "Berechnungen"]]
(map-indexed
(fn [index calculation]
^{:key index} [show-calculation exercise-core index calculation
......@@ -103,7 +103,8 @@
@calculations)
[:a.btn.blue
{:on-click
(fn [] (swap! calculations #(into [] (conj % (get-new-calculation (:with-oom @exercise-core))))))} "+"]]))
(fn [] (swap! calculations #(into [] (conj % (get-new-calculation (:with-oom @exercise-core))))))}
[:i.material-icons.left "add"] "Berechnung"]]))
:component-did-mount
#(swap! exercise-core (fn [exercise-core] (merge {:shuffled false
:with-oom false
......
......@@ -74,6 +74,9 @@
{:on-click (fn []
(ui/close-modal (str "#" unit-modal-id)))} "Schließen"]]]]
])]))
:component-did-update
(fn [] (do (ui/init-modal (str "#" unit-modal-id))
(ui/init-modal (str "#" value-modal-id))))
:component-did-mount
(fn [] (do (ui/init-modal (str "#" unit-modal-id))
(ui/init-modal (str "#" value-modal-id))))})))
......
......@@ -10,6 +10,8 @@
[lernmeister.components.exercise-types.calculation.check
:refer [prefix-mapping prefix-set unit-set not-empty-or-minus]]
[lernmeister.components.exercise-types.calculation.views.helper :refer [input-text-inline parse-int
latex-span
build-units-latex-string
parse-prefix parse-unit]]))
......@@ -51,93 +53,105 @@
(let [units (get-in answer [id :units])]
[:div ;; intended to be "[:<>"
[:div.row
[:div.col.s12.font-plus [:b "Einheiten: "]]
(when-not (empty? units)
(map-indexed
(fn [index unit-entry]
(let [prefix (:prefix unit-entry)
unit (:unit unit-entry)
expo (:expo unit-entry)]
^{:key index}
[unit-chip
:prefix prefix
:unit unit
:expo expo
:answer answer
:on-change (fn [answer]
(on-change-fn (update-in answer [id :units] #(vec-remove % index))))])) units))
(when-not @add-unit?
[:div.col.s12. [:a.btn.btn-small {:on-click #(reset! add-unit? true)} "+ Einheit"]])
(when (:invalid @cur-unit)
[:div.col
[ui/icon "warning" :class "orange-text"]
[:span " Ungültige Einheit"]])]
(when @add-unit?
[:div
[:div.row
[:div.col.s4.expo-padding
[ui/select
:label "Präfix"
:value (:prefix @cur-unit)
:options (map (fn [[p e]]
(hash-map :key (str p) :title (str p " = 10^" e))) prefixes)
:on-change (fn [value]
(when-let [v (parse-prefix (name value))]
(swap! cur-unit assoc :prefix v)))]]
[:div.col.s4.expo-padding
#_[ui/select
:label "Einheit"
[:div.col.s12
[:div.section
[:b "Einheit: "]
(if (pos? (count units))
[latex-span (build-units-latex-string units)]
[:p "Bitte definieren Sie mindestens einen Einheitenbestandteil"]
)]]
[:div.col.s12
[:div.section
[:b "Bestandtteile:"]
[:div.row
(when-not (empty? units)
(map-indexed
(fn [index unit-entry]
(let [prefix (:prefix unit-entry)
unit (:unit unit-entry)
expo (:expo unit-entry)]
^{:key index}
[unit-chip
:prefix prefix
:unit unit
:expo expo
:answer answer
:on-change (fn [answer]
(on-change-fn (update-in answer [id :units] #(vec-remove % index))))])) units))
#_(when-not @add-unit?
[:div.col.s12. [:a.btn.btn-small {:on-click #(reset! add-unit? true)} "+ Einheit"]])
(when (:invalid @cur-unit)
[:div.col.s12
[ui/icon "warning" :class "orange-text"]
[:span " Ungültige Einheit"]])]
[:div
[:div.row
[:div.col.s4.expo-padding
[ui/select
:label "Präfix"
:value (:prefix @cur-unit)
:options (map (fn [[p e]]
(hash-map :key (str p) :title (str p " = 10^" e))) prefixes)
:on-change (fn [value]
(when-let [v (parse-prefix (name value))]
(swap! cur-unit assoc :prefix v)))]]
[:div.col.s4.expo-padding
#_[ui/select
:label "Einheit"
:value (:unit @cur-unit)
:options (map (fn [u]
(hash-map :key (str u) :title u)) unit-options)
:on-change (fn [value]
(when-let [v (parse-unit (name value))]
(swap! cur-unit assoc :unit v)))]
[ui/input-text
:value (:unit @cur-unit)
:options (map (fn [u]
(hash-map :key (str u) :title u)) unit-options)
:label "Einheit"
:input-size 4
:input-class "center-align"
:autocomplete {:options (into {} (map #(vector % nil) unit-options))}
:on-change (fn [value]
(when-let [v (parse-unit (name value))]
(swap! cur-unit assoc :unit v)))]
[ui/input-text
:value (:unit @cur-unit)
:label "Einheit"
:input-size 4
:input-class "center-align"
:autocomplete {:options (into {} (map #(vector % nil) unit-options))}
:on-change (fn [value]
(when-let [v (parse-unit value)]
(swap! cur-unit assoc :unit v)))]]
[:div.col.s2
[input-text-inline nil
:value (:expo @cur-unit)
:label "Exponent"
:width 2
:class "left-align"
:on-change (fn [_ value]
(when-let [v (parse-int value)]
(swap! cur-unit assoc :expo v)))]]
[:div.col.s2.expo-padding
[:button.btn.blue
{:on-click (fn []
(if-let [checked-unit (check-unit @cur-unit)]
(let [prefix (:prefix checked-unit)
unit (:unit checked-unit)
expo (:expo checked-unit)]
(do
(on-change-fn
(update-in answer [id :units]
#(into [] (update-units % :unit unit :prefix prefix :expo expo))))
(reset! add-unit? false)
(reset! cur-unit {:prefix nil :unit nil :expo nil})))
(if (some
#((complement empty?) (val %))
(select-keys @cur-unit [:prefix :unit :expo]))
(swap! cur-unit assoc :invalid :unit)
(swap! cur-unit dissoc :invalid))))}
"+"]]]
[:div.row
[:div.col.s12
[:i.material-icons.left "help_outline"]
"Bei zusammengesetzten Einheiten jeden Bestandtteil einzeln eingeben und mit + bestätigen."]
[:div.col.s12
[:i.material-icons.left "help_outline"]
[:span
"Brüche können mit negativem Exponent beschrieben werden." [:br]]]]])]))))
(when-let [v (parse-unit value)]
(swap! cur-unit assoc :unit v)))]]
[:div.col.s2
[input-text-inline nil
:value (:expo @cur-unit)
:label "Exponent"
:width 2
:class "left-align"
:on-change (fn [_ value]
(when-let [v (parse-int value)]
(swap! cur-unit assoc :expo v)))]]
[:div.col.s2.expo-padding
[:button.btn.blue
{:on-click (fn []
(if-let [checked-unit (check-unit @cur-unit)]
(let [prefix (:prefix checked-unit)
unit (:unit checked-unit)
expo (:expo checked-unit)]
(do
(on-change-fn
(update-in answer [id :units]
#(into [] (update-units % :unit unit :prefix prefix :expo expo))))
(reset! add-unit? false)
(reset! cur-unit {:prefix nil :unit nil :expo nil})))
(if (some
#((complement empty?) (val %))
(select-keys @cur-unit [:prefix :unit :expo]))
(swap! cur-unit assoc :invalid :unit)
(swap! cur-unit dissoc :invalid))))}
"+"]]]
[:div.row
[:div.col.s12
[:i.material-icons.left "help_outline"]
"Bei zusammengesetzten Einheiten bitte jeden Bestandtteil einzeln eingeben und mit + bestätigen."]
[:div.col.s12
[:i.material-icons.left "help_outline"]
"km² = Präfix k, Einheit m, Exponent 2"]
[:div.col.s12
[:i.material-icons.left "help_outline"]
[:span
"Brüche können mit negativem Exponent beschrieben werden." [:br]]]]]]]]]))))
......
......@@ -275,8 +275,16 @@
(defn close-modal [selector-tag]
(.close (js/M.Modal.getInstance (js/document.querySelector selector-tag))))
(defn modal-exists? [selector-tag]
(try
(js/M.Modal.getInstance (js/document.querySelector selector-tag))
(catch js/Error. e
nil)))
(defn init-modal [selector-tag]
(js/M.Modal.init (js/document.querySelector selector-tag)))
(if-let [instance (modal-exists? selector-tag)]
instance
(js/M.Modal.init (js/document.querySelector selector-tag))))
(defn tooltip [& {:keys [selector-tag label]}]
(js/M.Tooltip.init (js/document.querySelector selector-tag) (clj->js {:html label})))
......
......@@ -17,6 +17,7 @@
(def init-modal md/init-modal)
(def open-modal md/open-modal)
(def close-modal md/close-modal)
(def modal-exists? md/modal-exists?)
(def tooltip md/tooltip)
(def table md/table)
(def collapsible md/collapsible)
......
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