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; display: grid;
grid-template-columns: 30% 70%; grid-template-columns: 30% 70%;
grid-auto-flow: row; grid-auto-flow: row;

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

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

@ -24,8 +24,7 @@
[:thead [:thead
[:tr [:tr
[:th "Name"] [:th "Name"]
(map (fn [attr] [:th (h (:name attr))]) (view-instance/req-attrs-headings schema)
(:req-attrs schema))
[:th "Updated"] [:th "Updated"]
[:th "Created"]]] [:th "Created"]]]
[:tbody [:tbody
@ -35,13 +34,6 @@
[: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] (view-instance/req-attrs-cells schema instance)
[: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))]])]]]))

@ -4,3 +4,18 @@
(defn tags-for-search [{tags :tags}] (defn tags-for-search [{tags :tags}]
[:span.tags-for-search [:span.tags-for-search
(reduce #(str %1 ":" (h (:name %2))) "" tags)]) (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}}) (u:user {uuid:{user_uuid}})
WHERE EXISTS((u)-[:permission {type:'read'}]->(s)) WHERE EXISTS((u)-[:permission {type:'read'}]->(s))
OR NOT EXISTS((:user)-[: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") ORDER BY s.name")
(defn accessible-schemas! [user-uuid] (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 (neo4j/exec-query! accessible-schemas
{:user_uuid user-uuid}))) {:user_uuid user-uuid})))

Loading…
Cancel
Save