search in tables by tag

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

@ -243,6 +243,10 @@ table {
margin-top: 1rem; margin-top: 1rem;
margin-bottom: 1rem; margin-bottom: 1rem;
.tags-for-search {
display: none;
}
thead { thead {
position: sticky; position: sticky;
top: 0; top: 0;

@ -147,7 +147,7 @@ document.addEventListener('DOMContentLoaded', function () {
const contents = tblRows(ctx.tbl).map(function (row) { const contents = tblRows(ctx.tbl).map(function (row) {
return Array.from(row.cells).reduce(function (carr, cell) { return Array.from(row.cells).reduce(function (carr, cell) {
return carr + cell.innerText.toLocaleLowerCase() return carr + cell.textContent.toLocaleLowerCase()
}, "") }, "")
}) })

@ -12,7 +12,7 @@
(spec/def ::uuid (spec/def ::uuid
#(re-matches #(re-matches
#"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" %)) #"[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+" %))
(def conn (def conn
(let [env #(or (System/getenv %1) %2) (let [env #(or (System/getenv %1) %2)

@ -38,16 +38,25 @@
(spec/def ::contains-schema (spec/def ::contains-schema
(spec/keys :req-un [::domain-schema/schema])) (spec/keys :req-un [::domain-schema/schema]))
(spec/def ::instances-with-tags
(spec/coll-of (spec/merge ::instance
(spec/keys :req-un [::tags]))))
(neo4j/defquery findy-by-schema (neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema) "MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN i OPTIONAL MATCH
(i)-[:tagged_with]->(t:tag)
RETURN i, t
ORDER BY i.name") ORDER BY i.name")
(defn find-by-schema! [schema-uuid] (defn find-by-schema! [schema-uuid]
(map :i {:post [(spec/assert ::instances-with-tags %)]}
(neo4j/exec-query! (->> (neo4j/exec-query! findy-by-schema
findy-by-schema {:uuid schema-uuid})
{:uuid schema-uuid}))) (group-by :i)
(map #(assoc (key %)
:tags (->> (val %)
(map :t)
(filter some?))))))
(neo4j/defquery create-instance (neo4j/defquery create-instance
"MATCH (s:schema {uuid:{schema_uuid}}), "MATCH (s:schema {uuid:{schema_uuid}}),
@ -91,8 +100,7 @@
(spec/def ::instance-with-schema (spec/def ::instance-with-schema
(spec/merge ::instance ::contains-schema)) (spec/merge ::instance ::contains-schema))
(neo4j/defquery find-by-uuid (neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}}) "MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema)
-[:of]->(s:schema)
RETURN i, s") RETURN i, s")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
{:post [(spec/assert ::instance-with-schema %)]} {:post [(spec/assert ::instance-with-schema %)]}

@ -13,6 +13,10 @@
[routing :refer [path]] [routing :refer [path]]
[time :refer [prettify-dt]]])) [time :refer [prettify-dt]]]))
(defn tags-for-search [{tags :tags}]
[:span.tags-for-search
(reduce #(str %1 ":" (:name %2)) "" tags)])
(defn list! [schema instances new-form req] (defn list! [schema instances new-form req]
(view/layout! (view/layout!
:request req :request req
@ -35,6 +39,7 @@
(for [instance instances] (for [instance instances]
[:tr [:tr
[:td [:td
(tags-for-search instance)
[:a {:href (path :instance-show instance)} [:a {:href (path :instance-show instance)}
(h (:name instance))]] (h (:name instance))]]
[:td (prettify-dt (:updated_at instance))] [:td (prettify-dt (:updated_at instance))]

Loading…
Cancel
Save