change instance/show to form

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

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

@ -37,3 +37,11 @@
{:attribute ra {:attribute ra
:value ((attr->field-id ra) form-data)}) :value ((attr->field-id ra) form-data)})
attrs)}) 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] (defn show! [uuid req]
(let [instance (assoc (domain/find-by-uuid! uuid) (let [instance (assoc (domain/find-by-uuid! uuid)
:properties :properties
(domain/find-properties! uuid))] (domain/find-properties! uuid))
(view/show! instance req))) attrs (domain-attr/find-by-instance! uuid)]
(view/show! instance
(forms-inst/with-attributes attrs)
(forms-inst/instance->form-data instance)
req)))
(defroutes routes (defroutes routes
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")

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

Loading…
Cancel
Save