From 3f2623d8b629181b6998c838ee5949d0531599f0 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 27 Dec 2020 01:45:17 +0100 Subject: [PATCH] some tinkering on bulk link creation --- resources/app/stylesheets/app.less | 5 ++ src/wanijo/instance/routes.clj | 41 ++++++++-------- .../instance/view/bulk_link_selection.clj | 47 ++++++++++++------- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index c58d3bc..10bdad4 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -283,6 +283,10 @@ form.inline { } } +form.no-grid { + display: block; +} + table { width: 100%; border-collapse: collapse; @@ -357,6 +361,7 @@ table { button, input { margin-right: @element-margin; + margin-bottom: 0; } } diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index 10a78b2..e4b9e40 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -87,7 +87,7 @@ (defn link-form! [schema-uuid] (forms-inst/link-form - (domain/find-by-schema! schema-uuid))) + (domain/find-by-schema! schema-uuid))) (defn route-link-selection! [uuid schema-uuid req] (link-selection (instance! uuid) @@ -122,18 +122,19 @@ (defn route-list-starred! [req] (starred - (domain/starred-by-user! (-> req :session :uuid)) - req)) + (domain/starred-by-user! (-> req :session :uuid)) + req)) (defn route-bulk-link-selection! [uuid req] (let [user-uuid (-> req :session :uuid)] (bulk-link-selection (domain/full-instance-by-uuid! uuid) (->> (domain-schema/accessible-schemas! - user-uuid) + user-uuid) (map (fn [schema] - {:form (link-form! (:uuid schema)) - :schema schema})) - (forms-inst/bulk-link-form)) + {;; :form (link-form! (:uuid schema)) + :schema schema + :instances (domain/find-by-schema! + (:uuid schema))}))) req))) (defn route-create-bulk-link! [uuid req] @@ -142,13 +143,13 @@ (defroutes routes (wrap-routes - (GET (register! :instance-list "/instance/list/:schema-uuid") - [schema-uuid :as req] - (route-list! schema-uuid req)) - (middleware-schema/wrap-allowed-to-read! - #(get-in % [:params :schema-uuid]))) + (GET (register! :instance-list "/instance/list/:schema-uuid") + [schema-uuid :as req] + (route-list! schema-uuid req)) + (middleware-schema/wrap-allowed-to-read! + #(get-in % [:params :schema-uuid]))) (POST (register! :instance-new "/instance/new") [] - route-new!) + route-new!) (GET (register! :instance-show "/instance/:uuid") [uuid :as req] (route-show! uuid req)) @@ -157,10 +158,10 @@ (route-edit-form! uuid req)) (POST (register! :instance-edit "/instance/:uuid") [uuid :as req] - (route-edit! uuid req)) + (route-edit! uuid req)) (DELETE (register! :instance-delete "/instance/:uuid") [uuid] - (route-delete! uuid)) + (route-delete! uuid)) (GET (register! :instance-link-selection "/instance/:uuid/link/:schema-uuid") [uuid schema-uuid :as req] @@ -168,19 +169,19 @@ (POST (register! :instance-link-create "/instance/:uuid/link/:schema-uuid") [uuid schema-uuid :as req] - (route-create-link! uuid schema-uuid req)) + (route-create-link! uuid schema-uuid req)) (DELETE (register! :instance-link-delete "/instance/:uuid/link/:link-uuid") [uuid link-uuid] - (route-delete-link! uuid link-uuid)) + (route-delete-link! uuid link-uuid)) (POST (register! :instance-mark-starred "/instance/:uuid/starred") [uuid :as req] - (route-mark-starred! uuid req)) + (route-mark-starred! uuid req)) (DELETE (register! :instance-remove-starred "/instance/:uuid/starred") [uuid :as req] - (route-remove-starred! uuid req)) + (route-remove-starred! uuid req)) (GET (register! :instance-list-starred "/instance/starred/list") [:as req] (route-list-starred! req)) @@ -189,4 +190,4 @@ (route-bulk-link-selection! uuid req)) (POST (register! :instance-bulk-link-create "/instance/:uuid/bulk-link") [uuid :as req] - (route-create-bulk-link! uuid req))) + (route-create-bulk-link! uuid req))) diff --git a/src/wanijo/instance/view/bulk_link_selection.clj b/src/wanijo/instance/view/bulk_link_selection.clj index 5b77f6a..de4e493 100644 --- a/src/wanijo/instance/view/bulk_link_selection.clj +++ b/src/wanijo/instance/view/bulk_link_selection.clj @@ -9,20 +9,33 @@ (defn bulk-link-selection [instance forms req] (clojure.pprint/pprint forms) (view/layout - :request req - :content - [[:h1 - [:small "Link " (-> instance :schema :name h) " "] - (h (:name instance)) - [:small " with..."]] - (hform/form-to - [:post (path :instance-bulk-link-create instance)] - (anti-forgery-field) - (for [{:keys [schema form]} forms] - [:fieldset - [:legend "Schema " [:strong (-> schema :name h)]] - (form/render-widgets form - nil - req - {:render-anti-forgery-field? false})]) - (hform/submit-button "Link!"))])) + :request req + :content + [[:h1 + [:small "Link " (-> instance :schema :name h) " "] + (h (:name instance)) + [:small " with..."]] + (hform/form-to + {:class "no-grid"} + [:post (path :instance-bulk-link-create instance)] + (anti-forgery-field) + (for [{:keys [schema instances]} forms] + (list + [:h2 "Schema " (h (:name schema))] + [:label + "Link name " + [:input {:name (str "name[" (:uuid schema) "]")}]] + [:table + [:thead + [:tr + [:th "Selection"] + [:th "Name"]]] + [:tbody + (for [{:keys [name uuid]} instances] + [:tr + [:td {:style "text-align: center;"} + [:input {:type "checkbox" + :name (str "instances[" (:uuid schema) "]") + :value uuid}]] + [:td (h name)]])]])) + (hform/submit-button "Link!"))]))