Commit c33f73e4 authored by Bruno Burke's avatar Bruno Burke 😁

add random content-element

parent 90b3ac55
Pipeline #16655 passed with stages
in 2 minutes and 34 seconds
......@@ -8,6 +8,7 @@
[lernmeister.components.content-elements.line.core :as ce-line]
[lernmeister.components.content-elements.heading.core :as ce-heading]
[lernmeister.components.content-elements.section.core :as ce-section]
[lernmeister.components.content-elements.random-element.core :as ce-random]
[lernmeister.components.content-elements.text.core :as ce-text]
[lernmeister.components.content-elements.exercise.core :as ce-exercise])))
(ns lernmeister.components.content-elements.random-element.core
(:require [lernmeister.components.content-elements.random-element.show]
[lernmeister.components.content-elements.random-element.edit]
[lernmeister.components.content-elements.core :refer [add-element]]))
(def content-element {:type :random-element
:label "Zufallselement"})
(add-element content-element)
(ns lernmeister.components.content-elements.random-element.edit
(:require [lernmeister.components.content-elements.core :as ce-core]
[reagent.core :as r]
[lernmeister.components.page-editor :refer [editor]]
[lernmeister.components.content-editor :as content-editor]))
(defmethod ce-core/edit :random-element [element options]
(let [id (str (gensym))]
(fn [element options]
[:div
[:div.card-panel (str @element)]
(doall
(for [i (range (count (:pages @element)))]
(let [p (r/cursor element [:pages i :content])]
^{:key (str "ce-re-" (:id element id) "-page-" (:id p))}[:div.card-panel
[:b (str "Block " (inc i))]
[content-editor/editor p
:hide-headline true
:hide-settings true]]
)))
[:a.btn
{:on-click
#(swap! element update :pages (comp vec conj) {:id (hash @element)
:type :page})}
"Block hinzufügen"
]])))
(ns lernmeister.components.content-elements.random-element.show
(:require [reagent.core :as reagent]
[hickory.core :as hickory]
[lernmeister.components.common :as common]
[lernmeister.components.content-elements.core :as ce-core]))
(defmethod ce-core/show :random-element [element options]
(let [id (str (gensym))]
(reagent/create-class
{:reagent-render
(fn [element options]
[:div.content-element.ce-random
(when-let [p (rand-nth (:pages element))]
[ce-core/show p])
#_(doall
(for [p (:pages element)]
^{:key (str (:id element) "-" id)}[ce-core/show p]))])})))
......@@ -32,22 +32,22 @@
)
)
(defn editor [page & {:keys [data-receivers allowed-types forbidden-types hide-settings]
(defn editor [page & {:keys [data-receivers allowed-types forbidden-types hide-settings hide-headline]
:or {forbidden-types #{}}}]
(reagent/create-class
{:display-name "Page-Editor"
:reagent-render
(fn [page & {:keys [data-receivers allowed-types forbidden-types hide-settings]}]
(fn [page & {:keys [data-receivers allowed-types forbidden-types hide-settings hide-headline]}]
(let [content (if (:content @page)
(reagent/cursor page [:content])
(reagent/cursor page [:content-elements]))]
[:div#component-content
[:div
[:h4 "Seite " (:title @page)]
(when-not hide-headline
[:h4 "Seite " (:title @page)])
(when-not hide-settings
[page-settings page])]
[:div
[:hr]
[:h4 "Inhalt"]
[content-editor/editor content
:data-receivers data-receivers
......
(ns lernmeister.components.ce-shuffle
(:require-macros
[devcards.core :refer [defcard-doc
defcard-rg
defcard
mkdn-pprint-source]])
(:require
[lernmeister.components.sample-data :as data]
[lernmeister.components.core]
[lernmeister.components.page :refer [page]]
[lernmeister.components.page-editor :as peditor]
[lernmeister.components.content-elements.core :as ce-core]
[lernmeister.components.content-editor :as ceditor]
[lernmeister.components.ui :as ui]
[clojure.pprint :refer [pprint]]
[devcards.core]
[reagent.core :as reagent]))
(defonce state (reagent/atom {:type :page
:settings {}
:content [{:id "dffd"
:type :random-element
}]}))
(defcard-rg page-editor
(fn [ _]
[:div
[peditor/editor state
:forbidden-types #{}]])
state
{:inspect-data true
:watch-atom true})
(defcard-rg content-editor
(fn [ _]
[:div
[ceditor/editor (reagent/cursor state [:content])
:page-settings (:settings @state)
:forbidden-types #{}]])
state
{:inspect-data true
:watch-atom true})
(defcard-rg page-content-element
(fn [ _]
[:div
[ce-core/show @state]]))
......@@ -6,6 +6,7 @@
[lernmeister.components.md-card]
[lernmeister.components.core :as core]
[lernmeister.components.content-editor-card]
[lernmeister.components.ce-shuffle]
[lernmeister.components.exercise-programming]
[lernmeister.components.exercise-editor-card]
[lernmeister.components.exercise-expression]
......
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