specs, again!

neo4j-4
Josha von Gizycki 5 years ago
parent d3efb3165e
commit 8937d28346

@ -1,7 +1,19 @@
(ns wanijo.visualisation.domain
(:require [wanijo.framework.neo4j :as neo4j]
(:require [clojure.spec.alpha :as spec]
[wanijo.framework.neo4j :as neo4j]
[wanijo.instance.domain :as domain-instance]))
(spec/def ::link-name
(spec/or :not-give nil?
:given string?))
(spec/def ::links-out
(spec/coll-of
(spec/merge ::domain-instance/instance
(spec/keys :req-un [::link-name]))))
(spec/def ::with-enriched-out-links
(spec/merge ::domain-instance/instance
(spec/keys :req-un [::links-out])))
(neo4j/defquery all-instance-connections
"MATCH
(source:instance)-[:of]->(schema:schema)
@ -28,9 +40,11 @@
(-> % :label :name))
links-in))))
(defn search! [term]
{:post [(spec/assert (spec/coll-of ::with-enriched-out-links) %)]}
(->> (neo4j/exec-query! search {:term (str ".*" term ".*")})
(map #(domain-instance/full-instance-by-uuid! (-> % :i :uuid)))
(map enrich-links)))
(defn instance! [uuid]
{:post [(spec/assert ::with-enriched-out-links %)]}
(enrich-links (domain-instance/full-instance-by-uuid! uuid)))

@ -35,7 +35,8 @@
(defroutes routes
(GET (register! :vis-explore "/vis/explore/:instance-uuid")
[instance-uuid :as req]
(vis-view/index instance-uuid req))
(vis-view/index (domain-instance/find-by-uuid! instance-uuid)
req))
(GET (register! :vis-all-instances "/vis/all-instances")
[:as req]
(all-instances req))

@ -1,22 +1,22 @@
(ns wanijo.visualisation.view
(:require [hiccup.page :refer [include-js include-css]]
[hiccup.form :as hform]
[hiccup.core :refer [h]]
[wanijo.framework.routing :refer [path]]
[wanijo.framework.view :as view]))
(defn index [instance-uuid req]
(defn index [instance req]
(view/layout!
:request req
:head (list (include-css "/css/vis-network.min.css")
(include-js "/js/vis-network.min.js"
"/js/vis.js"))
:content
[[:h1 "Explore"]
[[:h1 "Explore instance " [:small (h (:name instance))]]
[:form.search {:action (path :vis-search-instance {:term ""})}
(hform/label "term" "Search Instance")
(hform/text-field {:autofocus true} "term")
[:input {:style "display: none" :type "submit"}]]
[:div.vis-canvas {:data-instance-url (path :vis-get-instance
{:uuid instance-uuid})}]
[:div.vis-canvas {:data-instance-url (path :vis-get-instance instance)}]
[:p.flash--warn
"Changes to the visualisation will not (yet) mirror to the actual database"]]))

Loading…
Cancel
Save