make hopefully all instance lists searchable by tags

neo4j-4
Josha von Gizycki 5 years ago
parent 62929a8c22
commit 5d7f62d142

@ -23,16 +23,6 @@
::name])) ::name]))
(spec/def ::target ::instance) (spec/def ::target ::instance)
(spec/def ::source ::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/def ::tags
(spec/coll-of ::domain-tag/tag)) (spec/coll-of ::domain-tag/tag))
(spec/def ::contains-schema (spec/def ::contains-schema
@ -212,37 +202,57 @@
(:to link))] (:to link))]
(apply neo4j/exec-queries! tuples))) (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 (neo4j/defquery outgoing-links
"MATCH (i:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid:{uuid}}),
(i)<-[:link_from]-(l:link), (inst)<-[:link_from]-(link:link),
(l)-[:link_to]->(t:instance), (link)-[:link_to]->(target:instance),
(t)-[:of]->(s:schema) (target)-[:of]->(schema:schema)
RETURN i, l, t, s OPTIONAL MATCH
ORDER BY s.name, t.name, t.created_at") (target)-[:tagged_with]->(tag:tag)
RETURN link, target, schema, tag
ORDER BY schema.name, target.name, target.created_at")
(defn outgoing-links! [uuid] (defn outgoing-links! [uuid]
{:post [(spec/assert ::links-out %)]} {:post [(spec/assert ::links-out %)]}
(map (fn [row] (grouped-links-by-tag uuid outgoing-links :target))
{:link (:l row)
:target (:t row)
:schema (:s row)})
(neo4j/exec-query! outgoing-links
{:uuid uuid})))
(spec/def ::links-in
(spec/coll-of
(spec/keys :req-un [::link
::source
::domain-schema/schema
::tags])))
(neo4j/defquery incoming-links (neo4j/defquery incoming-links
"MATCH (i:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid:{uuid}}),
(i)<-[:link_to]-(l:link), (inst)<-[:link_to]-(link:link),
(l)-[:link_from]->(source:instance), (link)-[:link_from]->(source:instance),
(source)-[:of]->(schema:schema) (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") ORDER BY schema.name, source.name, source.created_at")
(defn incoming-links! [uuid] (defn incoming-links! [uuid]
{:post [(spec/assert ::links-in %)]} {:post [(spec/assert ::links-in %)]}
(map (fn [row] (grouped-links-by-tag uuid incoming-links :source))
{:link (:l row)
:source (:source row)
:schema (:schema row)})
(neo4j/exec-query! incoming-links
{:uuid uuid})))
(neo4j/defquery delete-link (neo4j/defquery delete-link
"MATCH (l:link {uuid:{uuid}}), "MATCH (l:link {uuid:{uuid}}),

@ -128,12 +128,14 @@
[:th "Schema"] [:th "Schema"]
[:th "Created"]]] [:th "Created"]]]
[:tbody [:tbody
(for [{:keys [link target schema]} (:links-out instance) (for [{:keys [link target schema] :as row} (:links-out instance)
:let [name (:name link) :let [name (:name link)
empty (empty? name) empty (empty? name)
name (if empty [:i "empty"] (h name))]] name (if empty [:i "empty"] (h name))]]
[:tr [:tr
[:td name] [:td
(tags-for-search row)
name]
[:td [:a {:href (path :instance-show target)} [:td [:a {:href (path :instance-show target)}
(h (:name target))]] (h (:name target))]]
[:td [:a {:href (path :instance-list [:td [:a {:href (path :instance-list
@ -151,12 +153,14 @@
[:th "Schema"] [:th "Schema"]
[:th "Created"]]] [:th "Created"]]]
[:tbody [:tbody
(for [{:keys [link source schema]} (:links-in instance) (for [{:keys [link source schema] :as row} (:links-in instance)
:let [name (:name link) :let [name (:name link)
empty (empty? name) empty (empty? name)
name (if empty [:i "empty"] (h name))]] name (if empty [:i "empty"] (h name))]]
[:tr [:tr
[:td name] [:td
(tags-for-search row)
name]
[:td [:a {:href (path :instance-show source)} [:td [:a {:href (path :instance-show source)}
(h (:name source))]] (h (:name source))]]
[:td [:a {:href (path :instance-list [:td [:a {:href (path :instance-list

Loading…
Cancel
Save