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! (apply neo4j/exec-queries!
(concat [instance-tuple] (concat [instance-tuple]
prop-tuples)))) 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 :required true
:widget (attr-type->widget (:type attr))}) :widget (attr-type->widget (:type attr))})
(defn instance-form [schema-uuid] (defn new-form [schema-uuid required-attrs]
(update form (update form
:fields :fields
(fn [fields] (fn [fields]
@ -29,7 +29,7 @@
(attr->field-id attr) (attr->field-id attr)
(attr->field attr))) (attr->field attr)))
fields fields
(domain-attr/required! schema-uuid))))) required-attrs))))
(defn form-data->instance [form-data required-attrs] (defn form-data->instance [form-data required-attrs]
{:name (:name form-data) {:name (:name form-data)

@ -13,12 +13,14 @@
(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/instance-form schema-uuid) (forms-inst/new-form 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/instance-form schema-uuid)] form-def (forms-inst/new-form 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)
@ -30,9 +32,18 @@
(:params req)))) (:params req))))
(list! schema-uuid 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 (defroutes routes
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req] [schema-uuid :as req]
(list! schema-uuid req)) (list! schema-uuid req))
(POST (register! :instance-new "/instance/new") [] (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] (for [instance instances]
[:tr [:tr
[:td [:td
[:a (:name instance)]] [:a {:href (path :instance-show instance)}
(:name instance)]]
[:td (prettify-dt (:updated_at instance))] [:td (prettify-dt (:updated_at instance))]
[:td (prettify-dt (:created_at instance))]])]] [:td (prettify-dt (:created_at instance))]])]]
[:h1 "New Instance"] [:h1 "New Instance"]
@ -32,3 +33,14 @@
(hform/hidden-field "schema-uuid" (hform/hidden-field "schema-uuid"
(:uuid schema)) (:uuid schema))
(hform/submit-button "Create!"))])) (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