diff --git a/src/wanijo/instance/domain.clj b/src/wanijo/instance/domain.clj index 61877fb..3a7f88b 100644 --- a/src/wanijo/instance/domain.clj +++ b/src/wanijo/instance/domain.clj @@ -138,3 +138,19 @@ (assoc link :uuid (neo4j/uuid) :created_at (neo4j/now-str)))) + +(neo4j/defquery outgoing-links + "MATCH (i:instance {uuid:{uuid}}), + (i)<-[:link_from]-(l:link), + (l)-[:link_to]->(t:instance), + (t)-[:of]->(s:schema) + RETURN i, l, t, s + ORDER BY l.created_at") + +(defn outgoing-links! [uuid] + (map (fn [row] + {:link (:l row) + :target (:t row) + :schema (:s row)}) + (neo4j/exec-query! outgoing-links + {:uuid uuid}))) diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index c824bc3..fd49abc 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -41,7 +41,9 @@ (defn instance! [uuid] (assoc (domain/find-by-uuid! uuid) :properties - (domain/find-properties! uuid))) + (domain/find-properties! uuid) + :links-out + (domain/outgoing-links! uuid))) (defn show! [uuid req] (view/show! (instance! uuid) req)) diff --git a/src/wanijo/instance/view.clj b/src/wanijo/instance/view.clj index 4c18005..d9ed6ec 100644 --- a/src/wanijo/instance/view.clj +++ b/src/wanijo/instance/view.clj @@ -60,7 +60,24 @@ (list [:h3 (h (:name attr))] [:div {:class (str "instance-content " "attr-type-" type)} - (render-fn (:value prop))]))])) + (render-fn (:value prop))])) + (when-not (empty? (:links-out instance)) + [:section.links + [:h2 "Outgoing Links"] + [:table + [:thead + [:tr + [:th "Name"] + [:th "Schema"] + [:th "Instance"] + [:th "Created"]]] + [:tbody + (for [{:keys [link target schema]} (:links-out instance)] + [:tr + [:td (h (:name link))] + [:td (h (:name schema))] + [:td (h (:name target))] + [:td (prettify-dt (:created_at link))]])]]])])) (defn edit! [instance form form-data schemas req] (view/layout!