ultra basic show action for instances

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

@ -53,3 +53,27 @@
(apply neo4j/exec-queries!
(concat [instance-tuple]
prop-tuples))))
(neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}})
RETURN i")
(defn find-by-uuid! [uuid]
(->> (neo4j/exec-query! find-by-uuid
{:uuid uuid})
(map :i)
first))
(neo4j/defquery find-properties
"MATCH (i:instance {uuid:{uuid}}),
(p:property)-[:of]->(i),
(p)-[:of]->(a:attribute)
RETURN p, a
ORDER BY a.name")
(defn find-properties! [uuid]
(map #(assoc (:p %)
:attribute
(:a %))
(neo4j/exec-query! find-properties
{:uuid uuid})))

@ -20,7 +20,7 @@
:required true
:widget (attr-type->widget (:type attr))})
(defn instance-form [schema-uuid]
(defn new-form [schema-uuid required-attrs]
(update form
:fields
(fn [fields]
@ -29,7 +29,7 @@
(attr->field-id attr)
(attr->field attr)))
fields
(domain-attr/required! schema-uuid)))))
required-attrs))))
(defn form-data->instance [form-data required-attrs]
{:name (:name form-data)

@ -13,12 +13,14 @@
(defn list! [schema-uuid req]
(view/list! (domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid)
(forms-inst/instance-form schema-uuid)
(forms-inst/new-form schema-uuid
(domain-attr/required! schema-uuid))
req))
(defn new! [req]
(let [schema-uuid (get-in req [:params :schema-uuid])
form-def (forms-inst/instance-form schema-uuid)]
form-def (forms-inst/new-form schema-uuid
(domain-attr/required! schema-uuid))]
(if (form/valid? form-def req)
(let [form-data (form/form-data form-def req)
req-attrs (domain-attr/required! schema-uuid)
@ -30,9 +32,18 @@
(:params req))))
(list! schema-uuid req))))
(defn show! [uuid req]
(let [instance (assoc (domain/find-by-uuid! uuid)
:properties
(domain/find-properties! uuid))]
(view/show! instance req)))
(defroutes routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(list! schema-uuid req))
(POST (register! :instance-new "/instance/new") []
new!))
new!)
(GET (register! :instance-show "/instance/:uuid")
[uuid :as req]
(show! uuid req)))

@ -23,7 +23,8 @@
(for [instance instances]
[:tr
[:td
[:a (:name instance)]]
[:a {:href (path :instance-show instance)}
(:name instance)]]
[:td (prettify-dt (:updated_at instance))]
[:td (prettify-dt (:created_at instance))]])]]
[:h1 "New Instance"]
@ -32,3 +33,14 @@
(hform/hidden-field "schema-uuid"
(:uuid schema))
(hform/submit-button "Create!"))]))
(defn show! [instance req]
(view/layout!
:request req
:content
[[:h1 (:name instance)]
[:dl
(for [prop (:properties instance)]
(list
[:dt (:name (:attribute prop))]
[:dd (:value prop)]))]]))

Loading…
Cancel
Save