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.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]
[ :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.card-panel (str @element)]
(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]]
#(swap! element update :pages (comp vec conj) {:id (hash @element)
:type :page})}
"Block hinzufügen"
(: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))]
(fn [element options]
(when-let [p (rand-nth (:pages element))]
[ce-core/show p])
(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 #{}}}]
{:display-name "Page-Editor"
(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]))]
[:h4 "Seite " (:title @page)]
(when-not hide-headline
[:h4 "Seite " (:title @page)])
(when-not hide-settings
[page-settings page])]
[:h4 "Inhalt"]
[content-editor/editor content
:data-receivers data-receivers
(ns lernmeister.components.ce-shuffle
[devcards.core :refer [defcard-doc
[lernmeister.components.sample-data :as data]
[ :refer [page]]
[ :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]]
[reagent.core :as reagent]))
(defonce state (reagent/atom {:type :page
:settings {}
:content [{:id "dffd"
:type :random-element
(defcard-rg page-editor
(fn [ _]
[peditor/editor state
:forbidden-types #{}]])
{:inspect-data true
:watch-atom true})
(defcard-rg content-editor
(fn [ _]
[ceditor/editor (reagent/cursor state [:content])
:page-settings (:settings @state)
:forbidden-types #{}]])
{:inspect-data true
:watch-atom true})
(defcard-rg page-content-element
(fn [ _]
[ce-core/show @state]]))
......@@ -6,6 +6,7 @@
[lernmeister.components.core :as core]
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