From 3cf0c7117a0845fb6453c2c50ae7bfac7c2c38db Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 27 Dec 2020 14:51:36 +0100 Subject: [PATCH] add sub-form capabilities, nicer bulk linking tables helper functions --- resources/app/stylesheets/app.less | 2 +- src/wanijo/instance/routes.clj | 3 +- .../instance/view/bulk_link_selection.clj | 29 ++++++++++++++----- src/wanijo/instance/view/instances.clj | 12 ++------ src/wanijo/instance/view/view.clj | 15 ++++++++++ src/wanijo/schema/db.clj | 11 +++++-- 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index 10bdad4..40075f9 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -199,7 +199,7 @@ img, svg { } } -form { +form, .sub-form { display: grid; grid-template-columns: 30% 70%; grid-auto-flow: row; diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index e4b9e40..5f7d1c6 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -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))) diff --git a/src/wanijo/instance/view/bulk_link_selection.clj b/src/wanijo/instance/view/bulk_link_selection.clj index de4e493..7dbfb09 100644 --- a/src/wanijo/instance/view/bulk_link_selection.clj +++ b/src/wanijo/instance/view/bulk_link_selection.clj @@ -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!"))])) diff --git a/src/wanijo/instance/view/instances.clj b/src/wanijo/instance/view/instances.clj index 009f2f7..c788575 100644 --- a/src/wanijo/instance/view/instances.clj +++ b/src/wanijo/instance/view/instances.clj @@ -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))]])]]])) diff --git a/src/wanijo/instance/view/view.clj b/src/wanijo/instance/view/view.clj index 7be7615..bb9aec9 100644 --- a/src/wanijo/instance/view/view.clj +++ b/src/wanijo/instance/view/view.clj @@ -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)) diff --git a/src/wanijo/schema/db.clj b/src/wanijo/schema/db.clj index 7515a2d..ebe793d 100644 --- a/src/wanijo/schema/db.clj +++ b/src/wanijo/schema/db.clj @@ -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})))