add sub-form capabilities, nicer bulk linking tables

helper functions
neo4j-4
Josha von Gizycki 4 years ago
parent 3f2623d8b6
commit 3cf0c7117a

@ -199,7 +199,7 @@ img, svg {
}
}
form {
form, .sub-form {
display: grid;
grid-template-columns: 30% 70%;
grid-auto-flow: row;

@ -131,8 +131,7 @@
(->> (domain-schema/accessible-schemas!
user-uuid)
(map (fn [schema]
{;; :form (link-form! (:uuid schema))
:schema schema
{:schema schema
:instances (domain/find-by-schema!
(:uuid schema))})))
req)))

@ -3,11 +3,15 @@
[hiccup.core :refer [h]]
[wanijo.infrastructure.view :as view]
[wanijo.infrastructure.routing :refer [path]]
[wanijo.infrastructure.time :refer [prettify-dt]]
[wanijo.instance.view.view
:refer [req-attrs-headings
req-attrs-cells
tags-for-search]]
[formulare.core :as form]
[ring.util.anti-forgery :refer [anti-forgery-field]]))
(defn bulk-link-selection [instance forms req]
(clojure.pprint/pprint forms)
(view/layout
:request req
:content
@ -22,20 +26,29 @@
(for [{:keys [schema instances]} forms]
(list
[:h2 "Schema " (h (:name schema))]
[:label
"Link name "
[:input {:name (str "name[" (:uuid schema) "]")}]]
(let [ident (str "name[" (:uuid schema) "]")]
[:div.sub-form
[:label {:for ident}
"Link name"]
[:input {:name ident :id ident}]])
[:table
[:thead
[:tr
[:th "Selection"]
[:th "Name"]]]
[:th "Name"]
(req-attrs-headings schema)
[:th "Updated"]
[:th "Created"]]]
[:tbody
(for [{:keys [name uuid]} instances]
(for [inst instances]
[:tr
[:td {:style "text-align: center;"}
[:input {:type "checkbox"
:name (str "instances[" (:uuid schema) "]")
:value uuid}]]
[:td (h name)]])]]))
:value (:uuid inst)}]]
[:td (h (:name inst))
(tags-for-search inst)]
(req-attrs-cells schema inst)
[:td (-> inst :updated_at prettify-dt)]
[:td (-> inst :created_at prettify-dt)]])]]))
(hform/submit-button "Link!"))]))

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

@ -4,3 +4,18 @@
(defn tags-for-search [{tags :tags}]
[:span.tags-for-search
(reduce #(str %1 ":" (h (:name %2))) "" tags)])
(defn req-attrs-headings [{:keys [req-attrs]}]
(map (fn [attr] [:th (h (:name attr))])
req-attrs))
(defn req-attrs-cells [{:keys [req-attrs]}
{:keys [properties]}]
(map (fn [{attr-uuid :uuid}]
[:td (->> properties
(filter #(= attr-uuid
(-> % :attribute :uuid)))
first
:value
h)])
req-attrs))

@ -85,10 +85,17 @@
(u:user {uuid:{user_uuid}})
WHERE EXISTS((u)-[:permission {type:'read'}]->(s))
OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s))
RETURN s
WITH s
OPTIONAL MATCH
(s)<-[:of]-(a:attribute)
WHERE a.required = 1
RETURN s, COLLECT(a) AS a
ORDER BY s.name")
(defn accessible-schemas! [user-uuid]
(map :s
{:post [(spec/assert ::domain/schema-with-req-attrs %)]}
(map (fn [{s :s a :a}]
(assoc s
:req-attrs (sort-by :name a)))
(neo4j/exec-query! accessible-schemas
{:user_uuid user-uuid})))

Loading…
Cancel
Save