diff --git a/src/wanijo/instance/domain.clj b/src/wanijo/instance/domain.clj index 0789ef7..c688d37 100644 --- a/src/wanijo/instance/domain.clj +++ b/src/wanijo/instance/domain.clj @@ -23,16 +23,6 @@ ::name])) (spec/def ::target ::instance) (spec/def ::source ::instance) -(spec/def ::links-out - (spec/coll-of - (spec/keys :req-un [::link - ::target - ::domain-schema/schema]))) -(spec/def ::links-in - (spec/coll-of - (spec/keys :req-un [::link - ::source - ::domain-schema/schema]))) (spec/def ::tags (spec/coll-of ::domain-tag/tag)) (spec/def ::contains-schema @@ -212,37 +202,57 @@ (:to link))] (apply neo4j/exec-queries! tuples))) +(defn grouped-links-by-tag [uuid query direction] + (->> (neo4j/exec-query! query + {:uuid uuid}) + (group-by + (fn [{:keys [link schema] :as row}] + {:link link + direction (direction row) + :schema schema})) + (map (fn [[link tags]] + (assoc link + :tags + (filter some? + (map :tag tags))))))) + +(spec/def ::links-out + (spec/coll-of + (spec/keys :req-un [::link + ::target + ::domain-schema/schema + ::tags]))) (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 s.name, t.name, t.created_at") + "MATCH (inst:instance {uuid:{uuid}}), + (inst)<-[:link_from]-(link:link), + (link)-[:link_to]->(target:instance), + (target)-[:of]->(schema:schema) + OPTIONAL MATCH + (target)-[:tagged_with]->(tag:tag) + RETURN link, target, schema, tag + ORDER BY schema.name, target.name, target.created_at") (defn outgoing-links! [uuid] {:post [(spec/assert ::links-out %)]} - (map (fn [row] - {:link (:l row) - :target (:t row) - :schema (:s row)}) - (neo4j/exec-query! outgoing-links - {:uuid uuid}))) + (grouped-links-by-tag uuid outgoing-links :target)) +(spec/def ::links-in + (spec/coll-of + (spec/keys :req-un [::link + ::source + ::domain-schema/schema + ::tags]))) (neo4j/defquery incoming-links - "MATCH (i:instance {uuid:{uuid}}), - (i)<-[:link_to]-(l:link), - (l)-[:link_from]->(source:instance), + "MATCH (inst:instance {uuid:{uuid}}), + (inst)<-[:link_to]-(link:link), + (link)-[:link_from]->(source:instance), (source)-[:of]->(schema:schema) - RETURN i, l, source, schema + OPTIONAL MATCH + (source)-[:tagged_with]->(tag:tag) + RETURN link, source, schema, tag ORDER BY schema.name, source.name, source.created_at") (defn incoming-links! [uuid] {:post [(spec/assert ::links-in %)]} - (map (fn [row] - {:link (:l row) - :source (:source row) - :schema (:schema row)}) - (neo4j/exec-query! incoming-links - {:uuid uuid}))) + (grouped-links-by-tag uuid incoming-links :source)) (neo4j/defquery delete-link "MATCH (l:link {uuid:{uuid}}), diff --git a/src/wanijo/instance/view.clj b/src/wanijo/instance/view.clj index 2dca798..9daa683 100644 --- a/src/wanijo/instance/view.clj +++ b/src/wanijo/instance/view.clj @@ -128,12 +128,14 @@ [:th "Schema"] [:th "Created"]]] [:tbody - (for [{:keys [link target schema]} (:links-out instance) + (for [{:keys [link target schema] :as row} (:links-out instance) :let [name (:name link) empty (empty? name) name (if empty [:i "empty"] (h name))]] [:tr - [:td name] + [:td + (tags-for-search row) + name] [:td [:a {:href (path :instance-show target)} (h (:name target))]] [:td [:a {:href (path :instance-list @@ -151,12 +153,14 @@ [:th "Schema"] [:th "Created"]]] [:tbody - (for [{:keys [link source schema]} (:links-in instance) + (for [{:keys [link source schema] :as row} (:links-in instance) :let [name (:name link) empty (empty? name) name (if empty [:i "empty"] (h name))]] [:tr - [:td name] + [:td + (tags-for-search row) + name] [:td [:a {:href (path :instance-show source)} (h (:name source))]] [:td [:a {:href (path :instance-list