From 62a86ec5fb3e77d1857c1d25574868cf391daf04 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Fri, 14 Sep 2018 18:47:57 +0200 Subject: [PATCH] add created and other schemas to sidebar --- src/wanijo/framework/view.clj | 14 ++++++++++++-- src/wanijo/handler.clj | 2 ++ src/wanijo/schema/domain.clj | 10 ++++++++++ src/wanijo/schema/middleware.clj | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/wanijo/schema/middleware.clj diff --git a/src/wanijo/framework/view.clj b/src/wanijo/framework/view.clj index 6bb61fc..752a02e 100644 --- a/src/wanijo/framework/view.clj +++ b/src/wanijo/framework/view.clj @@ -44,8 +44,18 @@ (btnlink (path :auth-logout) "Logout!" "header-content__link")])] - [:nav (when authed? "nav")] - (vec (concat [:main] content)) + [:nav + (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")] [:footer [:small "Ilo pali e ijo"]]]]))) diff --git a/src/wanijo/handler.clj b/src/wanijo/handler.clj index c83bffa..9e535d2 100644 --- a/src/wanijo/handler.clj +++ b/src/wanijo/handler.clj @@ -8,6 +8,7 @@ [ring.middleware.session.cookie :as session-cookie] [wanijo.home.routes :as home-routes] [wanijo.schema.routes :as schema-routes] + [wanijo.schema.middleware :as schema-middleware] [wanijo.user.routes :as user-routes] [wanijo.attribute.routes :as attr-routes] [wanijo.framework.auth :as auth] @@ -32,6 +33,7 @@ (def app (-> app-routes devmode/wrap-devmode + schema-middleware/wrap-user-schemas (wrap-defaults (assoc-in site-defaults [:session :store] diff --git a/src/wanijo/schema/domain.clj b/src/wanijo/schema/domain.clj index 55c1191..4ce2835 100644 --- a/src/wanijo/schema/domain.clj +++ b/src/wanijo/schema/domain.clj @@ -22,6 +22,16 @@ {:uuid user-uuid}) (map :s))) +(neo4j/defquery + all + "MATCH (s:schema) + RETURN s + ORDER BY s.name") + +(defn all! [] + (map :s + (neo4j/exec-query! all {}))) + (neo4j/defquery create-new "MATCH (u:user) diff --git a/src/wanijo/schema/middleware.clj b/src/wanijo/schema/middleware.clj new file mode 100644 index 0000000..8c5493f --- /dev/null +++ b/src/wanijo/schema/middleware.clj @@ -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))))