parent
33bda110be
commit
29228853dc
@ -0,0 +1,39 @@
|
||||
(ns wanijo.instance.forms
|
||||
(:require [wanijo.instance.domain :as domain]
|
||||
[wanijo.attribute.domain :as domain-attr]))
|
||||
|
||||
(def form
|
||||
{:fields {:name {:label "Name"
|
||||
:required true
|
||||
:spec ::domain/name}}})
|
||||
|
||||
(defn attr-type->widget [attr-type]
|
||||
(case attr-type
|
||||
("markdown" "text") :textarea
|
||||
:input))
|
||||
|
||||
(defn attr->field-id [attr]
|
||||
(keyword (str "attr-" (:uuid attr))))
|
||||
|
||||
(defn attr->field [attr]
|
||||
{:label (:name attr)
|
||||
:required true
|
||||
:widget (attr-type->widget (:type attr))})
|
||||
|
||||
(defn instance-form [schema-uuid]
|
||||
(update form
|
||||
:fields
|
||||
(fn [fields]
|
||||
(reduce (fn [fields attr]
|
||||
(assoc fields
|
||||
(attr->field-id attr)
|
||||
(attr->field attr)))
|
||||
fields
|
||||
(domain-attr/required! schema-uuid)))))
|
||||
|
||||
(defn form-data->instance [form-data required-attrs]
|
||||
{:name (:name form-data)
|
||||
:properties (map (fn [ra]
|
||||
{:attribute ra
|
||||
:value ((attr->field-id ra) form-data)})
|
||||
required-attrs)})
|
Loading…
Reference in new issue