|
|
@ -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)))
|
|
|
|