creating links between instances

integration-tests
Josha von Gizycki 6 years ago
parent 0314d8368a
commit 06b049f0ff

@ -122,3 +122,17 @@
(defn delete! [uuid] (defn delete! [uuid]
(neo4j/exec-query! delete {:uuid uuid})) (neo4j/exec-query! delete {:uuid uuid}))
(neo4j/defquery create-link
"MATCH (i:instance {uuid:{instance_uuid}}),
(i2)
WHERE i2.uuid IN {instance_uuids}
CREATE (i)-[:link {name:{name},
created_at:{created_at}}]->(i2)")
(defn create-link! [instance-uuid name instance-uuids]
(neo4j/exec-query! create-link
{:instance_uuid instance-uuid
:name name
:created_at (neo4j/now-str)
:instance_uuids instance-uuids}))

@ -6,6 +6,15 @@
:required true :required true
:spec ::domain/name}}}) :spec ::domain/name}}})
(defn link-form [instances]
{:fields {:name {:label "Name"
:required true}
:instances {:label "Instances"
:widget :mselect
:options (map #(vector (:name %)
(:uuid %))
instances)}}})
(defn attr-type->widget [attr-type] (defn attr-type->widget [attr-type]
(case attr-type (case attr-type
("markdown" "text") :textarea ("markdown" "text") :textarea

@ -48,10 +48,12 @@
(defn edit-form! [uuid req] (defn edit-form! [uuid req]
(let [instance (instance! uuid) (let [instance (instance! uuid)
attrs (domain-attr/find-by-instance! uuid)] attrs (domain-attr/find-by-instance! uuid)
user-uuid (get-in req [:session :uuid])]
(view/edit! instance (view/edit! instance
(form! uuid) (form! uuid)
(forms-inst/instance->form-data instance) (forms-inst/instance->form-data instance)
(domain-schema/accessible-schemas! user-uuid)
req))) req)))
(defn edit! [uuid req] (defn edit! [uuid req]
@ -72,6 +74,26 @@
(resp/redirect (path :instance-list (resp/redirect (path :instance-list
{:schema-uuid (:uuid schema)})))) {:schema-uuid (:uuid schema)}))))
(defn link-form! [schema-uuid]
(forms-inst/link-form
(domain/find-by-schema! schema-uuid)))
(defn link-selection! [uuid schema-uuid req]
(view/link-selection (instance! uuid)
(domain-schema/find-by-uuid! schema-uuid)
(link-form! schema-uuid)
req))
(defn create-link! [uuid schema-uuid req]
(let [form (link-form! schema-uuid)]
(if (form/valid? form req)
(let [form-data (form/form-data form req)]
(domain/create-link! uuid
(:name form-data)
(:instances form-data))
(resp/redirect (path :instance-show {:uuid uuid})))
(link-selection! uuid schema-uuid req))))
(defroutes routes (defroutes routes
(wrap-routes (wrap-routes
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")
@ -92,4 +114,12 @@
(edit! uuid req)) (edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid") (DELETE (register! :instance-delete "/instance/:uuid")
[uuid :as req] [uuid :as req]
(delete! uuid req))) (delete! uuid req))
(GET (register! :instance-link-selection
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(link-selection! uuid schema-uuid req))
(POST (register! :instance-create-link
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(create-link! uuid schema-uuid req)))

@ -62,7 +62,7 @@
"attr-type-" type)} "attr-type-" type)}
(render-fn (:value prop))]))])) (render-fn (:value prop))]))]))
(defn edit! [instance form form-data req] (defn edit! [instance form form-data schemas req]
(view/layout! (view/layout!
:request req :request req
:content :content
@ -70,9 +70,33 @@
(h (-> instance :schema :name)) (h (-> instance :schema :name))
" " " "
[:small (h (:name instance))]] [:small (h (:name instance))]]
[:h2 "Edit Instance"]
(hform/form-to [:post (path :instance-edit instance)] (hform/form-to [:post (path :instance-edit instance)]
(form/render-widgets form form-data req) (form/render-widgets form form-data req)
(hform/submit-button "Edit!")) (hform/submit-button "Edit!"))
(hform/form-to [:delete (path :instance-delete instance)] (hform/form-to [:delete (path :instance-delete instance)]
(anti-forgery-field) (anti-forgery-field)
(view/delete-btn))])) (view/delete-btn))
[:h2 "Link Instance with Instance of Schema..."]
[:ul
(for [schema schemas]
[:li
[:a {:href (path :instance-link-selection
{:uuid (:uuid instance)
:schema-uuid (:uuid schema)})}
(h (:name schema))]])]]))
(defn link-selection [instance schema form req]
(view/layout!
:request req
:content
[[:h1
[:small "Link " (-> instance :schema :name) " "]
(h (:name instance))
[:small " with "]
(h (:name schema))]
(hform/form-to [:post (path :instance-create-link
{:uuid (:uuid instance)
:schema-uuid (:uuid schema)})]
(form/render-widgets form nil req)
(hform/submit-button "Link!"))]))

Loading…
Cancel
Save