Commit 5805d337 authored by Joachim Schunk's avatar Joachim Schunk

add helper-function "set-migration-status"

parent 8d0ef654
Pipeline #47559 passed with stages
in 1 minute and 47 seconds
......@@ -99,17 +99,20 @@
:different))
:missing))
(defn set-migration-status [exercise scheme-version]
(assoc-in
exercise [:authoring :migration-status]
(scheme-version-check exercise :exercise-scheme scheme-version)))
(defn get-migration-status [type-status subject scheme-key current-version]
(case type-status
:identical (scheme-version-check subject scheme-key current-version)
:missing :migrate
nil))
(defn set-migration-status [exercise scheme-key valid-type current-version]
(let [type-status (scheme-type-check exercise scheme-key valid-type)
migration-status (get-migration-status type-status exercise scheme-key current-version)]
(assoc-in exercise [:authoring :migration-status] migration-status)))
(defn migrate-if-necessary [subject scheme-key valid-type current-version migrate-fn]
(let [type-status (scheme-type-check subject scheme-key valid-type)
migration-status (case type-status
:identical (scheme-version-check subject scheme-key current-version)
:missing :migrate
nil)]
migration-status (get-migration-status type-status subject scheme-key current-version)]
(case migration-status
:migrate (migrate-fn subject)
:current subject
......
......@@ -157,20 +157,26 @@
texts)])
(def migration-strgs {:admin "Kontaktieren Sie Ihren Administrator!"
:wrong "Inkompatibler Datenstruktur-Typ."
:incompatible "Inkompatibilität von Datenstruktur und Umgebung."
:invalid "Ungültige Versionsbenennung der Datenstruktur."
:migrate (str "Um die Aufgabe bearbeiten zu können, "
"sollte eine Migration der Datenstruktur durchgeführt werden!")})
"muss eine Migration der Datenstruktur durchgeführt werden!")})
(defn scheme-migration-dialogue [{:keys [migration-status migrate-fn exercise-atom]}]
[:div.is-block.has-text-centered
(cond
(= :incompatible migration-status)
[:p.is-warning (:incompatible migration-strgs) [:br] (:admin migration-strgs)]
(= :invalid migration-status)
[:p.is-warning (:invalid migration-strgs) [:br] (:admin migration-strgs)]
(= :migrate migration-status)
[:<>
[:h5.mt-6.mb-5 [:b (:migrate migration-strgs)]]
[:a.button.is-info.mb-6 {:on-click (partial migrate-fn exercise-atom)}
"Datenstruktur migrieren"]])])
(case migration-status
:incompatible [:div.mt-6.mb-5.has-text-danger
[:h5.mb-3 [:b (:incompatible migration-strgs)]]
[:p (:admin migration-strgs)]]
:invalid [:div.mt-6.mb-5.has-text-danger
[:h5.mb-3 [:b (:invalid migration-strgs)]]
[:p (:admin migration-strgs)]]
:migrate [:<>
[:h5.mt-6.mb-5 [:b (:migrate migration-strgs)]]
[:a.button.is-info.mb-6
{:on-click (partial migrate-fn exercise-atom)}
"Datenstruktur migrieren"]]
[:div.mt-6.mb-5.has-text-danger
[:h5.mb-3 [:b (:wrong migration-strgs)]]
[:p (:admin migration-strgs)]])])
(ns lernmeister.components.exercise-types.calculation.views.edit
(:require [clojure.string :as str]
[clojure.tools.reader.edn :as edn]
[lernmeister.components.common :refer [scheme-migration-dialogue]]
[lernmeister.components.exercise-types.calchelper
:refer
[calc-change-fn get-collats-for-vec]]
[lernmeister.components.exercise-types.calculation.components.migration
:refer
[migrate-exercise-atom]]
[lernmeister.components.exercise-types.calculation.migrate
:refer
[exercise-scheme-version]]
[lernmeister.components.exercise-types.calculation.views.show :as show]
[lernmeister.components.exercise-types.edit :as e-edit]
[lernmeister.components.modal-editor.renderers :as modal-renderers]
[lernmeister.components.helper :refer [vec-remove]]
[lernmeister.components.helper :refer [set-migration-status vec-remove]]
[lernmeister.components.jshelper :refer [get-unique-id]]
[lernmeister.components.modal-editor.core :refer [modal-editor]]
[lernmeister.components.modal-editor.renderers :as modal-renderers]
[lernmeister.components.ui :as ui]
[reagent.core :as reagent]))
......@@ -123,10 +130,8 @@
[:div
[modal-editor {:subject exercise
:change-fn change-fn
:phrase-fn #(str "DamnPhrase: " %)
:visible? (:modal-visible? @modal-state-atom)
:path (:path @modal-state-atom)
:variable-idx (:variable-idx @modal-state-atom)
:type (:type @modal-state-atom)
:with-oom (:with-oom @modal-state-atom)
:with-units (:with-units @modal-state-atom)
......@@ -166,24 +171,33 @@
{:display-name "calculation-settings"
:reagent-render
(fn [exercise-atom]
[new-exercise-options {:exercise @exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)}])
(let [migration-status (get-in @exercise-atom [:authoring :migration-status])]
(if (= :current migration-status)
[new-exercise-options {:exercise @exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@exercise-atom)}]
[scheme-migration-dialogue {:migration-status migration-status
:migrate-fn migrate-exercise-atom
:exercise-atom exercise-atom}])))
:component-did-mount
(fn [comp]
(let [exercise-atom (first (reagent/children comp))]
(reset! exercise-atom (update @exercise-atom :core #(merge {:shuffled false
:with-oom false
:with-units false
:calculations []}
%)))))}))
(reset! exercise-atom
(-> @exercise-atom
(update :core #(merge {:shuffled false
:with-oom false
:with-units false
:calculations []}
%))
(set-migration-status :exercise-scheme "calculation" exercise-scheme-version)))))}))
(defn additional-forms [exercise-atom]
[new-exercise-form {:exercise-atom exercise-atom
:change-fn (partial calc-change-fn
(fn [exercise] (reset! exercise-atom exercise))
@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)}]))
(defmethod e-edit/show-settings :calculation [_ _]
(fn [exercise-atom _]
......
......@@ -232,25 +232,17 @@
:exercise-atom exercise-atom}])))
:component-did-mount
(fn [comp]
(let [set-scheme (fn [exercise]
(let [{:keys [assocs params assignments steps]} (:core exercise)]
(if (some not-empty [assocs params assignments steps])
(if (= (get-in exercise [:exercise-scheme :type]) "multistep-calculation")
exercise
(assoc exercise :exercise-scheme {:type "multistep-calculation"
:version "0000-00-00"}))
(assoc exercise :exercise-scheme {:type "multistep-calculation"
:version exercise-scheme-version}))))
exercise-atom (first (reagent/children comp))]
(reset! exercise-atom (-> @exercise-atom
(assoc-in [:core :with-oom] true)
(assoc-in [:core :with-units] true)
(update :core #(merge {:assocs []
:params []
:assignments []
:steps []} %))
set-scheme
(set-migration-status exercise-scheme-version)))))}))
(let [exercise-atom (first (reagent/children comp))]
(reset! exercise-atom
(-> @exercise-atom
(assoc-in [:core :with-oom] true)
(assoc-in [:core :with-units] true)
(update :core #(merge {:assocs []
:params []
:assignments []
:steps []} %))
(set-migration-status :exercise-scheme "multistep-calculation"
exercise-scheme-version)))))}))
(defn additional-forms [exercise-atom]
(when (= :current (get-in @exercise-atom [:authoring :migration-status]))
......
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