change instance/show to form

integration-tests
Josha von Gizycki 6 years ago
parent d2dc76ac6d
commit 29cbc8d0d0

@ -90,3 +90,15 @@
{:uuid uuid})
(map :s)
first))
(neo4j/defquery find-by-instance
"MATCH (i:instance {uuid:{instance_uuid}}),
(i)-[:of]->(s:schema),
(a:attribute)-[:of]->(s)
RETURN a
ORDER BY a.name")
(defn find-by-instance! [instance-uuid]
(map :a
(neo4j/exec-query! find-by-instance
{:instance_uuid instance-uuid})))

@ -7,8 +7,7 @@
(spec/def ::updated-at ::neo4j/date-str)
(spec/def ::name (spec/and (complement empty?) string?))
(neo4j/defquery
findy-by-schema
(neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid}
RETURN i
@ -77,14 +76,3 @@
(:a %))
(neo4j/exec-query! find-properties
{: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)))

@ -37,3 +37,11 @@
{:attribute ra
:value ((attr->field-id ra) form-data)})
attrs)})
(defn instance->form-data [instance]
(merge {:name (:name instance)}
(reduce #(assoc %1
(attr->field-id (:attribute %2))
(:value %2))
{}
(:properties instance))))

@ -33,8 +33,12 @@
(defn show! [uuid req]
(let [instance (assoc (domain/find-by-uuid! uuid)
:properties
(domain/find-properties! uuid))]
(view/show! instance req)))
(domain/find-properties! uuid))
attrs (domain-attr/find-by-instance! uuid)]
(view/show! instance
(forms-inst/with-attributes attrs)
(forms-inst/instance->form-data instance)
req)))
(defroutes routes
(GET (register! :instance-list "/instance/list/:schema-uuid")

@ -34,13 +34,10 @@
(:uuid schema))
(hform/submit-button "Create!"))]))
(defn show! [instance req]
(defn show! [instance form form-data req]
(view/layout!
:request req
:content
[[:h1 (:name instance)]
[:dl
(for [prop (:properties instance)]
(list
[:dt (:name (:attribute prop))]
[:dd (:value prop)]))]]))
(hform/form-to [:post ""]
(form/render-widgets form form-data req))]))

Loading…
Cancel
Save