add created and other schemas to sidebar

integration-tests
Josha von Gizycki 6 years ago
parent cfb70fbbf6
commit 62a86ec5fb

@ -44,8 +44,18 @@
(btnlink (path :auth-logout) (btnlink (path :auth-logout)
"Logout!" "Logout!"
"header-content__link")])] "header-content__link")])]
[:nav (when authed? "nav")] [:nav
(vec (concat [:main] content)) (when authed?
[:section.schemas
[:h2 "Created Schemas"]
[:ul
(for [schema (:created-schemas session)]
[:li (:name schema)])]
[:h2 "Other Schemas"]
[:ul
(for [schema (:other-schemas session)]
[:li (:name schema)])]])]
(into [:main] content)
[:aside (when authed? "aside")] [:aside (when authed? "aside")]
[:footer [:footer
[:small "Ilo pali e ijo"]]]]))) [:small "Ilo pali e ijo"]]]])))

@ -8,6 +8,7 @@
[ring.middleware.session.cookie :as session-cookie] [ring.middleware.session.cookie :as session-cookie]
[wanijo.home.routes :as home-routes] [wanijo.home.routes :as home-routes]
[wanijo.schema.routes :as schema-routes] [wanijo.schema.routes :as schema-routes]
[wanijo.schema.middleware :as schema-middleware]
[wanijo.user.routes :as user-routes] [wanijo.user.routes :as user-routes]
[wanijo.attribute.routes :as attr-routes] [wanijo.attribute.routes :as attr-routes]
[wanijo.framework.auth :as auth] [wanijo.framework.auth :as auth]
@ -32,6 +33,7 @@
(def app (def app
(-> app-routes (-> app-routes
devmode/wrap-devmode devmode/wrap-devmode
schema-middleware/wrap-user-schemas
(wrap-defaults (wrap-defaults
(assoc-in site-defaults (assoc-in site-defaults
[:session :store] [:session :store]

@ -22,6 +22,16 @@
{:uuid user-uuid}) {:uuid user-uuid})
(map :s))) (map :s)))
(neo4j/defquery
all
"MATCH (s:schema)
RETURN s
ORDER BY s.name")
(defn all! []
(map :s
(neo4j/exec-query! all {})))
(neo4j/defquery (neo4j/defquery
create-new create-new
"MATCH (u:user) "MATCH (u:user)

@ -0,0 +1,16 @@
(ns wanijo.schema.middleware
(:require [wanijo.schema.domain :as domain]))
(defn wrap-user-schemas [handler]
(fn [req]
(if-let [uuid (get-in req [:session :uuid])]
(let [created (domain/all-created-by! uuid)
created-uids (map :uuid created)
others (filter (fn [other]
(not (some (partial = (:uuid other))
created-uids)))
(domain/all!))]
(handler (-> req
(assoc-in [:session :created-schemas] created)
(assoc-in [:session :other-schemas] others))))
(handler req))))
Loading…
Cancel
Save