show required attributes in instance list

neo4j-4
Josha von Gizycki 5 years ago
parent 6d256c6d37
commit 53bca6a698

@ -24,15 +24,12 @@
(spec/def ::contains-schema (spec/def ::contains-schema
(spec/keys :req-un [::db-schema/schema])) (spec/keys :req-un [::db-schema/schema]))
(spec/def ::instances-with-tags-and-props
(spec/coll-of (spec/merge ::instance
(spec/keys :req-un [::tags
::properties]))))
(spec/def ::instance-with-tags-and-props (spec/def ::instance-with-tags-and-props
(spec/merge ::instance (spec/merge ::instance
(spec/keys :req-un [::tags (spec/keys :req-un [::tags
::properties]))) ::properties])))
(spec/def ::instances-with-tags-and-props
(spec/coll-of ::instance-with-tags-and-props))
(spec/def ::instance-with-schema (spec/def ::instance-with-schema
(spec/merge ::instance ::contains-schema)) (spec/merge ::instance ::contains-schema))

@ -23,6 +23,8 @@
[:thead [:thead
[:tr [:tr
[:th "Name"] [:th "Name"]
(map (fn [attr] [:th (h (:name attr))])
(:req-attrs schema))
[:th "Updated"] [:th "Updated"]
[:th "Created"]]] [:th "Created"]]]
[:tbody [:tbody
@ -32,5 +34,13 @@
[:a {:href (path :instance-show instance)} [:a {:href (path :instance-show instance)}
(h (:name instance))] (h (:name instance))]
(view-instance/tags-for-search instance)] (view-instance/tags-for-search instance)]
(map (fn [attr]
[:td (->> (:properties instance)
(filter #(= (:uuid attr)
(-> % :attribute :uuid)))
first
:value
h)])
(:req-attrs schema))
[:td (prettify-dt (:updated_at instance))] [:td (prettify-dt (:updated_at instance))]
[:td (prettify-dt (:created_at instance))]])]]])) [:td (prettify-dt (:created_at instance))]])]]]))

@ -1,6 +1,7 @@
(ns wanijo.schema.db (ns wanijo.schema.db
(:require [wanijo.infrastructure.neo4j :as neo4j] (:require [wanijo.infrastructure.neo4j :as neo4j]
[wanijo.schema.domain :as domain])) [wanijo.schema.domain :as domain]
[clojure.spec.alpha :as spec]))
(neo4j/defquery all-created-by (neo4j/defquery all-created-by
"MATCH (s:schema)-[:created_by]->(u:user) "MATCH (s:schema)-[:created_by]->(u:user)
@ -43,14 +44,20 @@
(neo4j/defquery find-by-uuid (neo4j/defquery find-by-uuid
"MATCH (s:schema) "MATCH (s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN s") OPTIONAL MATCH
(s)<-[:of]-(a:attribute)
WHERE a.required = 1
RETURN s, a
ORDER BY a.name")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
(->> {:post [(spec/assert ::domain/schema-with-req-attrs %)]}
(neo4j/exec-query! (let [result (neo4j/exec-query!
find-by-uuid find-by-uuid
{:uuid uuid}) {:uuid uuid})
first schema (:s (first result))]
:s)) (when schema
(assoc schema
:req-attrs (map :a result)))))
(neo4j/defquery schema-permissions (neo4j/defquery schema-permissions
"MATCH (s:schema {uuid:{schema_uuid}}) "MATCH (s:schema {uuid:{schema_uuid}})

@ -1,6 +1,7 @@
(ns wanijo.schema.domain (ns wanijo.schema.domain
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs] [wanijo.specs :as specs]
[wanijo.attribute.domain :as domain-attr]
[wanijo.infrastructure.neo4j :as neo4j])) [wanijo.infrastructure.neo4j :as neo4j]))
(spec/def ::name (spec/def ::name
@ -18,3 +19,9 @@
[{public? :is_public [{public? :is_public
user-permission :user_has_permission}] user-permission :user_has_permission}]
(or public? user-permission)) (or public? user-permission))
(spec/def ::req-attrs
(spec/coll-of ::domain-attr/attribute))
(spec/def ::schema-with-req-attrs
(spec/merge ::schema
:req-un [::req-attrs]))

Loading…
Cancel
Save