bulk link creation - saving does not work yet

neo4j-4
Josha von Gizycki 5 years ago
parent 723f7fd09b
commit 465ef3a75d

@ -108,6 +108,7 @@ img, svg {
align-items: center; align-items: center;
margin-top: 0; margin-top: 0;
background-color: ThreeDShadow; background-color: ThreeDShadow;
//noinspection CssUnknownTarget
background-image: url("/img/logo-full-flipped.svg"); background-image: url("/img/logo-full-flipped.svg");
background-size: contain; background-size: contain;
background-position: right; background-position: right;
@ -203,6 +204,14 @@ form {
grid-template-columns: 30% 70%; grid-template-columns: 30% 70%;
grid-auto-flow: row; 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 { label, input, select, textarea, .flash {
margin-bottom: .7rem; margin-bottom: .7rem;
padding: @text-padding-v @text-padding-h / 2; padding: @text-padding-v @text-padding-h / 2;

@ -17,6 +17,20 @@
(:uuid %)) (:uuid %))
instances)}}}) 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] (defn attr-type->widget [attr-type]
(case attr-type (case attr-type
("markdown" "text") :textarea ("markdown" "text") :textarea

@ -3,10 +3,13 @@
GET POST DELETE]] GET POST DELETE]]
[ring.util.response :as resp] [ring.util.response :as resp]
[formulare.core :as form] [formulare.core :as form]
[wanijo.instance.view.edit :refer [edit]] [wanijo.instance.view
[wanijo.instance.view.instances :refer [instances]] [edit :refer [edit]]
[wanijo.instance.view.show :refer [show]] [instances :refer [instances]]
[wanijo.instance.view.link-selection :refer [link-selection]] [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.view.starred :refer [starred]]
[wanijo.instance.db :as domain] [wanijo.instance.db :as domain]
[wanijo.instance.forms :as forms-inst] [wanijo.instance.forms :as forms-inst]
@ -16,13 +19,13 @@
[wanijo.infrastructure.routing :refer [register! path]] [wanijo.infrastructure.routing :refer [register! path]]
[wanijo.attribute.db :as db-attr])) [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) (instances (domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid) (domain/find-by-schema! schema-uuid)
(forms-inst/with-attributes (db-attr/required! schema-uuid)) (forms-inst/with-attributes (db-attr/required! schema-uuid))
req)) req))
(defn new! [req] (defn route-new! [req]
(let [schema-uuid (get-in req [:params :schema-uuid]) (let [schema-uuid (get-in req [:params :schema-uuid])
user-uuid (get-in req [:session :uuid]) user-uuid (get-in req [:session :uuid])
req-attrs (db-attr/required! schema-uuid) req-attrs (db-attr/required! schema-uuid)
@ -37,12 +40,12 @@
instance) instance)
(resp/redirect (path :instance-list (resp/redirect (path :instance-list
(:params req)))) (:params req))))
(list! schema-uuid req)))) (route-list! schema-uuid req))))
(defn instance! [uuid] (defn instance! [uuid]
(domain/full-instance-by-uuid! uuid)) (domain/full-instance-by-uuid! uuid))
(defn show! [uuid req] (defn route-show! [uuid req]
(let [user-uuid (-> req :session :uuid) (let [user-uuid (-> req :session :uuid)
instance (assoc (instance! uuid) instance (assoc (instance! uuid)
:starred :starred
@ -55,7 +58,7 @@
(defn form! [attrs] (defn form! [attrs]
(forms-inst/with-attributes attrs)) (forms-inst/with-attributes attrs))
(defn edit-form! [uuid req] (defn route-edit-form! [uuid req]
(let [instance (instance! uuid) (let [instance (instance! uuid)
attrs (db-attr/find-by-instance! uuid) attrs (db-attr/find-by-instance! uuid)
user-uuid (get-in req [:session :uuid])] user-uuid (get-in req [:session :uuid])]
@ -65,7 +68,7 @@
(domain-schema/accessible-schemas! user-uuid) (domain-schema/accessible-schemas! user-uuid)
req))) req)))
(defn edit! [uuid req] (defn route-edit! [uuid req]
(let [attrs (db-attr/find-by-instance! uuid) (let [attrs (db-attr/find-by-instance! uuid)
form-def (form! attrs)] form-def (form! attrs)]
(if (form/valid? form-def req) (if (form/valid? form-def req)
@ -74,9 +77,9 @@
instance (assoc form-instance :uuid uuid)] instance (assoc form-instance :uuid uuid)]
(domain/edit! instance) (domain/edit! instance)
(resp/redirect (path :instance-show 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)] (let [schema (domain-schema/find-by-instance! uuid)]
(domain/delete! uuid) (domain/delete! uuid)
(resp/redirect (path :instance-list (resp/redirect (path :instance-list
@ -86,13 +89,13 @@
(forms-inst/link-form (forms-inst/link-form
(domain/find-by-schema! schema-uuid))) (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) (link-selection (instance! uuid)
(domain-schema/find-by-uuid! schema-uuid) (domain-schema/find-by-uuid! schema-uuid)
(link-form! schema-uuid) (link-form! schema-uuid)
req)) req))
(defn create-link! [uuid schema-uuid req] (defn route-create-link! [uuid schema-uuid req]
(let [form (link-form! schema-uuid)] (let [form (link-form! schema-uuid)]
(if (form/valid? form req) (if (form/valid? form req)
(let [form-data (form/form-data form req)] (let [form-data (form/form-data form req)]
@ -101,68 +104,89 @@
:to (:instances form-data) :to (:instances form-data)
:by (get-in req [:session :uuid])}) :by (get-in req [:session :uuid])})
(resp/redirect (path :instance-edit-form {:uuid 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) (domain-link/delete! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid uuid}))) (resp/redirect (path :instance-edit-form {:uuid uuid})))
(defn mark-starred! [uuid req] (defn route-mark-starred! [uuid req]
(domain/mark-starred! uuid (domain/mark-starred! uuid
(-> req :session :uuid)) (-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid}))) (resp/redirect (path :instance-show {:uuid uuid})))
(defn remove-starred! [uuid req] (defn route-remove-starred! [uuid req]
(domain/remove-starred! uuid (domain/remove-starred! uuid
(-> req :session :uuid)) (-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid}))) (resp/redirect (path :instance-show {:uuid uuid})))
(defn list-starred! [req] (defn route-list-starred! [req]
(starred (starred
(domain/starred-by-user! (-> req :session :uuid)) (domain/starred-by-user! (-> req :session :uuid))
req)) 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 (defroutes routes
(wrap-routes (wrap-routes
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req] [schema-uuid :as req]
(list! schema-uuid req)) (route-list! schema-uuid req))
(middleware-schema/wrap-allowed-to-read! (middleware-schema/wrap-allowed-to-read!
#(get-in % [:params :schema-uuid]))) #(get-in % [:params :schema-uuid])))
(POST (register! :instance-new "/instance/new") [] (POST (register! :instance-new "/instance/new") []
new!) route-new!)
(GET (register! :instance-show "/instance/:uuid") (GET (register! :instance-show "/instance/:uuid")
[uuid :as req] [uuid :as req]
(show! uuid req)) (route-show! uuid req))
(GET (register! :instance-edit-form "/instance/:uuid/edit") (GET (register! :instance-edit-form "/instance/:uuid/edit")
[uuid :as req] [uuid :as req]
(edit-form! uuid req)) (route-edit-form! uuid req))
(POST (register! :instance-edit "/instance/:uuid") (POST (register! :instance-edit "/instance/:uuid")
[uuid :as req] [uuid :as req]
(edit! uuid req)) (route-edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid") (DELETE (register! :instance-delete "/instance/:uuid")
[uuid] [uuid]
(delete! uuid)) (route-delete! uuid))
(GET (register! :instance-link-selection (GET (register! :instance-link-selection
"/instance/:uuid/link/:schema-uuid") "/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req] [uuid schema-uuid :as req]
(link-selection! uuid schema-uuid req)) (route-link-selection! uuid schema-uuid req))
(POST (register! :instance-link-create (POST (register! :instance-link-create
"/instance/:uuid/link/:schema-uuid") "/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req] [uuid schema-uuid :as req]
(create-link! uuid schema-uuid req)) (route-create-link! uuid schema-uuid req))
(DELETE (register! :instance-link-delete (DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid") "/instance/:uuid/link/:link-uuid")
[uuid link-uuid] [uuid link-uuid]
(delete-link! uuid link-uuid)) (route-delete-link! uuid link-uuid))
(POST (register! :instance-mark-starred (POST (register! :instance-mark-starred
"/instance/:uuid/starred") "/instance/:uuid/starred")
[uuid :as req] [uuid :as req]
(mark-starred! uuid req)) (route-mark-starred! uuid req))
(DELETE (register! :instance-remove-starred (DELETE (register! :instance-remove-starred
"/instance/:uuid/starred") "/instance/:uuid/starred")
[uuid :as req] [uuid :as req]
(remove-starred! uuid req)) (route-remove-starred! uuid req))
(GET (register! :instance-list-starred "/instance/starred/list") (GET (register! :instance-list-starred "/instance/starred/list")
[:as req] [: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)))

@ -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!"))]))

@ -10,7 +10,7 @@
:request req :request req
:content :content
[[:h1 [[:h1
[:small "Link " (-> instance :schema :name) " "] [:small "Link " (-> instance :schema :name h) " "]
(h (:name instance)) (h (:name instance))
[:small " with "] [:small " with "]
(h (:name schema))] (h (:name schema))]

@ -63,7 +63,10 @@
"Edit Instance"] "Edit Instance"]
" | " " | "
[:a {:href (path :vis-explore {:instance-uuid (:uuid 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)) (when (seq (:tags instance))
[:section.tags [:section.tags
(view-tag/tag-list (:tags instance))]) (view-tag/tag-list (:tags instance))])
@ -91,7 +94,7 @@
(when (seq (:links-in instance)) (when (seq (:links-in instance))
(links-table "Incoming links" :links-in instance)) (links-table "Incoming links" :links-in instance))
[:section.quick-edits [:section.quick-edits
[:h2 "Quick edits"] [:h2 {:id "quick-edits"} "Quick edits"]
[:section.link-instance [:section.link-instance
[:h3 "Link Instance with Instance of Schema..."] [:h3 "Link Instance with Instance of Schema..."]
[:ul [:ul
@ -100,7 +103,9 @@
[:a {:href (path :instance-link-selection [:a {:href (path :instance-link-selection
{:uuid (:uuid instance) {:uuid (:uuid instance)
:schema-uuid (:uuid schema)})} :schema-uuid (:uuid schema)})}
(h (:name schema))]])]] (h (:name schema))]])]
[:a {:href (path :instance-bulk-link-selection instance)}
"Bulk create links"]]
[:section.tag-instance [:section.tag-instance
[:h3 "Add or create Tags"] [:h3 "Add or create Tags"]
(view-tag/new-tag-form instance)]]])) (view-tag/new-tag-form instance)]]]))

Loading…
Cancel
Save