form refactor foo

integration-tests
Josha von Gizycki 6 years ago
parent a72ddfb7f4
commit b5898110c4

@ -9,7 +9,7 @@
(neo4j/defquery (neo4j/defquery
findy-by-schema findy-by-schema
"MATCH (i:instance)-->(s:schema) "MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN i RETURN i
ORDER BY i.updated_at DESC") ORDER BY i.updated_at DESC")
@ -77,3 +77,14 @@
(:a %)) (:a %))
(neo4j/exec-query! find-properties (neo4j/exec-query! find-properties
{:uuid uuid}))) {:uuid uuid})))
(neo4j/defquery schema-of
"MATCH (i:instance {uuid:{uuid}}),
(i)-[:of]->(s:schema)
RETURN s")
(defn schema-of [uuid]
(-> (neo4j/exec-query! schema-of
{:uuid uuid})
first
(map :s)))

@ -20,7 +20,7 @@
:required true :required true
:widget (attr-type->widget (:type attr))}) :widget (attr-type->widget (:type attr))})
(defn new-form [schema-uuid required-attrs] (defn with-attributes [attrs]
(update form (update form
:fields :fields
(fn [fields] (fn [fields]
@ -29,11 +29,11 @@
(attr->field-id attr) (attr->field-id attr)
(attr->field attr))) (attr->field attr)))
fields fields
required-attrs)))) attrs))))
(defn form-data->instance [form-data required-attrs] (defn form-data->instance [form-data attrs]
{:name (:name form-data) {:name (:name form-data)
:properties (map (fn [ra] :properties (map (fn [ra]
{:attribute ra {:attribute ra
:value ((attr->field-id ra) form-data)}) :value ((attr->field-id ra) form-data)})
required-attrs)}) attrs)})

@ -13,14 +13,12 @@
(defn list! [schema-uuid req] (defn list! [schema-uuid req]
(view/list! (domain-schema/find-by-uuid! schema-uuid) (view/list! (domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid) (domain/find-by-schema! schema-uuid)
(forms-inst/new-form schema-uuid (forms-inst/with-attributes (domain-attr/required! schema-uuid))
(domain-attr/required! schema-uuid))
req)) req))
(defn new! [req] (defn new! [req]
(let [schema-uuid (get-in req [:params :schema-uuid]) (let [schema-uuid (get-in req [:params :schema-uuid])
form-def (forms-inst/new-form schema-uuid form-def (forms-inst/with-attributes (domain-attr/required! schema-uuid))]
(domain-attr/required! schema-uuid))]
(if (form/valid? form-def req) (if (form/valid? form-def req)
(let [form-data (form/form-data form-def req) (let [form-data (form/form-data form-def req)
req-attrs (domain-attr/required! schema-uuid) req-attrs (domain-attr/required! schema-uuid)

Loading…
Cancel
Save