diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index 171048b..c58d3bc 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -108,6 +108,7 @@ img, svg { align-items: center; margin-top: 0; background-color: ThreeDShadow; + //noinspection CssUnknownTarget background-image: url("/img/logo-full-flipped.svg"); background-size: contain; background-position: right; @@ -203,6 +204,14 @@ form { grid-template-columns: 30% 70%; grid-auto-flow: row; + fieldset { + display: grid; + grid-column: 1 e("/") 3; + grid-template-columns: 30% 70%; + grid-auto-flow: row; + margin-bottom: @text-padding-h; + } + label, input, select, textarea, .flash { margin-bottom: .7rem; padding: @text-padding-v @text-padding-h / 2; diff --git a/src/wanijo/instance/forms.clj b/src/wanijo/instance/forms.clj index d98fc47..c1cbae0 100644 --- a/src/wanijo/instance/forms.clj +++ b/src/wanijo/instance/forms.clj @@ -17,6 +17,20 @@ (:uuid %)) instances)}}}) +(defn bulk-link-form [link-forms] + (map (fn [{:keys [schema form]}] + (let [name-field (keyword (str "name-" (:uuid schema))) + instances-field (keyword (str "instances-" (:uuid schema)))] + {:schema schema + :form (-> form + (assoc-in [:fields name-field] + (-> form :fields :name)) + (update :fields dissoc :name) + (assoc-in [:fields instances-field] + (-> form :fields :instances)) + (update :fields dissoc :instances))})) + link-forms)) + (defn attr-type->widget [attr-type] (case attr-type ("markdown" "text") :textarea diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index f7a994b..10a78b2 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -3,10 +3,13 @@ GET POST DELETE]] [ring.util.response :as resp] [formulare.core :as form] - [wanijo.instance.view.edit :refer [edit]] - [wanijo.instance.view.instances :refer [instances]] - [wanijo.instance.view.show :refer [show]] - [wanijo.instance.view.link-selection :refer [link-selection]] + [wanijo.instance.view + [edit :refer [edit]] + [instances :refer [instances]] + [show :refer [show]] + [link-selection :refer [link-selection]] + [bulk-link-selection :refer [bulk-link-selection]] + [starred :refer [starred]]] [wanijo.instance.view.starred :refer [starred]] [wanijo.instance.db :as domain] [wanijo.instance.forms :as forms-inst] @@ -16,13 +19,13 @@ [wanijo.infrastructure.routing :refer [register! path]] [wanijo.attribute.db :as db-attr])) -(defn list! [schema-uuid req] +(defn route-list! [schema-uuid req] (instances (domain-schema/find-by-uuid! schema-uuid) (domain/find-by-schema! schema-uuid) (forms-inst/with-attributes (db-attr/required! schema-uuid)) req)) -(defn new! [req] +(defn route-new! [req] (let [schema-uuid (get-in req [:params :schema-uuid]) user-uuid (get-in req [:session :uuid]) req-attrs (db-attr/required! schema-uuid) @@ -37,12 +40,12 @@ instance) (resp/redirect (path :instance-list (:params req)))) - (list! schema-uuid req)))) + (route-list! schema-uuid req)))) (defn instance! [uuid] (domain/full-instance-by-uuid! uuid)) -(defn show! [uuid req] +(defn route-show! [uuid req] (let [user-uuid (-> req :session :uuid) instance (assoc (instance! uuid) :starred @@ -55,7 +58,7 @@ (defn form! [attrs] (forms-inst/with-attributes attrs)) -(defn edit-form! [uuid req] +(defn route-edit-form! [uuid req] (let [instance (instance! uuid) attrs (db-attr/find-by-instance! uuid) user-uuid (get-in req [:session :uuid])] @@ -65,7 +68,7 @@ (domain-schema/accessible-schemas! user-uuid) req))) -(defn edit! [uuid req] +(defn route-edit! [uuid req] (let [attrs (db-attr/find-by-instance! uuid) form-def (form! attrs)] (if (form/valid? form-def req) @@ -74,9 +77,9 @@ instance (assoc form-instance :uuid uuid)] (domain/edit! instance) (resp/redirect (path :instance-show instance))) - (show! uuid req)))) + (route-show! uuid req)))) -(defn delete! [uuid] +(defn route-delete! [uuid] (let [schema (domain-schema/find-by-instance! uuid)] (domain/delete! uuid) (resp/redirect (path :instance-list @@ -86,13 +89,13 @@ (forms-inst/link-form (domain/find-by-schema! schema-uuid))) -(defn link-selection! [uuid schema-uuid req] +(defn route-link-selection! [uuid schema-uuid req] (link-selection (instance! uuid) (domain-schema/find-by-uuid! schema-uuid) (link-form! schema-uuid) req)) -(defn create-link! [uuid schema-uuid req] +(defn route-create-link! [uuid schema-uuid req] (let [form (link-form! schema-uuid)] (if (form/valid? form req) (let [form-data (form/form-data form req)] @@ -101,68 +104,89 @@ :to (:instances form-data) :by (get-in req [:session :uuid])}) (resp/redirect (path :instance-edit-form {:uuid uuid}))) - (link-selection! uuid schema-uuid req)))) + (route-link-selection! uuid schema-uuid req)))) -(defn delete-link! [uuid link-uuid] +(defn route-delete-link! [uuid link-uuid] (domain-link/delete! link-uuid) (resp/redirect (path :instance-edit-form {:uuid uuid}))) -(defn mark-starred! [uuid req] +(defn route-mark-starred! [uuid req] (domain/mark-starred! uuid (-> req :session :uuid)) (resp/redirect (path :instance-show {:uuid uuid}))) -(defn remove-starred! [uuid req] +(defn route-remove-starred! [uuid req] (domain/remove-starred! uuid (-> req :session :uuid)) (resp/redirect (path :instance-show {:uuid uuid}))) -(defn list-starred! [req] +(defn route-list-starred! [req] (starred (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) + (map (fn [schema] + {:form (link-form! (:uuid schema)) + :schema schema})) + (forms-inst/bulk-link-form)) + req))) + +(defn route-create-bulk-link! [uuid req] + (clojure.pprint/pprint req) + (resp/redirect (path :instance-show {:uuid uuid}))) + (defroutes routes (wrap-routes (GET (register! :instance-list "/instance/list/:schema-uuid") [schema-uuid :as req] - (list! schema-uuid req)) + (route-list! schema-uuid req)) (middleware-schema/wrap-allowed-to-read! #(get-in % [:params :schema-uuid]))) (POST (register! :instance-new "/instance/new") [] - new!) + route-new!) (GET (register! :instance-show "/instance/:uuid") [uuid :as req] - (show! uuid req)) + (route-show! uuid req)) (GET (register! :instance-edit-form "/instance/:uuid/edit") [uuid :as req] - (edit-form! uuid req)) + (route-edit-form! uuid req)) (POST (register! :instance-edit "/instance/:uuid") [uuid :as req] - (edit! uuid req)) + (route-edit! uuid req)) (DELETE (register! :instance-delete "/instance/:uuid") [uuid] - (delete! uuid)) + (route-delete! uuid)) (GET (register! :instance-link-selection "/instance/:uuid/link/:schema-uuid") [uuid schema-uuid :as req] - (link-selection! uuid schema-uuid req)) + (route-link-selection! uuid schema-uuid req)) (POST (register! :instance-link-create "/instance/:uuid/link/:schema-uuid") [uuid schema-uuid :as req] - (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] - (delete-link! uuid link-uuid)) + (route-delete-link! uuid link-uuid)) (POST (register! :instance-mark-starred "/instance/:uuid/starred") [uuid :as req] - (mark-starred! uuid req)) + (route-mark-starred! uuid req)) (DELETE (register! :instance-remove-starred "/instance/:uuid/starred") [uuid :as req] - (remove-starred! uuid req)) + (route-remove-starred! uuid req)) (GET (register! :instance-list-starred "/instance/starred/list") [:as req] - (list-starred! req))) + (route-list-starred! req)) + (GET (register! :instance-bulk-link-selection "/instance/:uuid/bulk-link") + [uuid :as req] + (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))) diff --git a/src/wanijo/instance/view/bulk_link_selection.clj b/src/wanijo/instance/view/bulk_link_selection.clj new file mode 100644 index 0000000..a53602c --- /dev/null +++ b/src/wanijo/instance/view/bulk_link_selection.clj @@ -0,0 +1,24 @@ +(ns wanijo.instance.view.bulk-link-selection + (:require [hiccup.form :as hform] + [hiccup.core :refer [h]] + [wanijo.infrastructure.view :as view] + [wanijo.infrastructure.routing :refer [path]] + [formulare.core :as form] + [ring.util.anti-forgery :refer [anti-forgery-field]])) + +(defn bulk-link-selection [instance forms req] + (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)]) + (hform/submit-button "Link!"))])) diff --git a/src/wanijo/instance/view/link_selection.clj b/src/wanijo/instance/view/link_selection.clj index 3b845f2..7c50ca4 100644 --- a/src/wanijo/instance/view/link_selection.clj +++ b/src/wanijo/instance/view/link_selection.clj @@ -10,7 +10,7 @@ :request req :content [[:h1 - [:small "Link " (-> instance :schema :name) " "] + [:small "Link " (-> instance :schema :name h) " "] (h (:name instance)) [:small " with "] (h (:name schema))] diff --git a/src/wanijo/instance/view/show.clj b/src/wanijo/instance/view/show.clj index a8dca0c..015082d 100644 --- a/src/wanijo/instance/view/show.clj +++ b/src/wanijo/instance/view/show.clj @@ -63,7 +63,10 @@ "Edit Instance"] " | " [:a {:href (path :vis-explore {:instance-uuid (:uuid instance)})} - "Explore from here"]]] + "Explore from here"] + " | " + [:a {:href "#quick-edits"} + "Quick edits"]]] (when (seq (:tags instance)) [:section.tags (view-tag/tag-list (:tags instance))]) @@ -91,7 +94,7 @@ (when (seq (:links-in instance)) (links-table "Incoming links" :links-in instance)) [:section.quick-edits - [:h2 "Quick edits"] + [:h2 {:id "quick-edits"} "Quick edits"] [:section.link-instance [:h3 "Link Instance with Instance of Schema..."] [:ul @@ -100,7 +103,9 @@ [:a {:href (path :instance-link-selection {:uuid (:uuid instance) :schema-uuid (:uuid schema)})} - (h (:name schema))]])]] + (h (:name schema))]])] + [:a {:href (path :instance-bulk-link-selection instance)} + "Bulk create links"]] [:section.tag-instance [:h3 "Add or create Tags"] (view-tag/new-tag-form instance)]]]))