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

Commit 2eb36576 authored by Bruno Burke's avatar Bruno Burke 😁

allow workspace preparation for blockly component

parent 0dd3e61b
Pipeline #18265 passed with stages
in 2 minutes and 18 seconds
......@@ -3,6 +3,7 @@
[lernmeister.components.exercise-types.programming.spec :refer [programming-languages]]
[lernmeister.components.content-elements.core :as ce-core]
[lernmeister.components.content-elements.blockly.blocks :as bblock]
[lernmeister.components.content-elements.blockly.show :refer [blockly-component]]
[cljsjs.codemirror]
[cljsjs.codemirror.mode.python]
[lernmeister.components.ui :as ui]))
......@@ -117,6 +118,38 @@
)
))
(defn workspace-preparation [workspace content-element]
(let [prepare? (reagent/atom false)
temp-workspace (atom nil)]
(fn [workspace content-element]
[:div
(if-not @prepare?
[:div.center
[:a.btn.btn-flat {:on-click #(swap! prepare? not)}
[:i.material-icons.left "settings_input_component"]
"Workspace vorbereiten"]]
[:div
[ce-core/show @content-element
{:state (:workspace-xml @workspace)
:on-change #(let [id (.-workspaceId %)]
(reset! temp-workspace
(js/Blockly.Xml.domToText
(js/Blockly.Xml.workspaceToDom
(js/Blockly.Workspace.getById id)))))}]
[:a.btn.secondary {:on-click #(do
(swap! workspace assoc :workspace-xml @temp-workspace)
(swap! prepare? not))}
[:i.material-icons.left "cancel"]
"Verwerfen"]
" "
[:a.btn.green {:on-click #(do
(swap! workspace assoc :workspace-xml @temp-workspace)
(swap! prepare? not))}
[:i.material-icons.left "save"]
"Speichern"]
])])))
(defmethod ce-core/edit :blockly [element options]
(fn [element options]
......@@ -129,6 +162,9 @@
[:div.col.s12.m6
[workspace-settings (reagent/cursor element [:workspace-settings])]
]
[:div.col.s12
[workspace-preparation (reagent/cursor element [:workspace]) element]
]
]
])))
......
......@@ -6,12 +6,15 @@
[lernmeister.components.jshelper :refer [load-script]]))
(defn code-component [element & {:keys [answer on-change status run-code]}]
(defn blockly-component [element & {:keys [answer on-change status run-code]}]
(let [eid (:id element)
blockly-editor-id (str (gensym "blockly") "-" eid)
toolbox-id (str blockly-editor-id "-toolbox")
workspace (reagent/atom nil)
python-code (reagent/atom "")]
python-code (reagent/atom "")
update-fn (reagent/atom #(if on-change
(on-change %)
(identity %)))]
(reagent/create-class
{
:component-name "blockly-content-element"
......@@ -55,7 +58,13 @@
:maxScale 3
:minScale 0.3
:scaleSpeed 1.2}})
))))))))))))))
))))
(when-let [workspace-xml (get-in element [:workspace :workspace-xml])]
(js/Blockly.Xml.domToWorkspace
(js/Blockly.Xml.textToDom workspace-xml)
@workspace))
(.addChangeListener @workspace #(@update-fn %))
))))))))))
:reagent-render
(fn [element & {:keys [result answer on-change]}]
(let [selected-categories (set (map
......@@ -117,5 +126,7 @@
(let [code (:code options answer)
options (merge (ce-core/receive-options element) options)]
[:div
[code-component element :answer @code :on-change #(reset! code %)
[blockly-component element
:answer @code
:on-change (:on-change options)
:run-code (:run-code options)]]))))
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