From 691e1fa6d2b8ba130f331768f9af356173167c65 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Mon, 2 Jul 2018 11:59:21 +0200 Subject: [PATCH] show-schema --- resources/app/stylesheets/app.less | 2 +- src/wanijo/schema/domain.clj | 14 +++++++++ src/wanijo/schema/routes.clj | 9 +++++- src/wanijo/schema/view.clj | 46 ++++++++++++++++++------------ 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index da2b560..a372224 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -12,7 +12,7 @@ body { a:link, a:visited { - color: #555; + color: #115577; text-decoration: none; } diff --git a/src/wanijo/schema/domain.clj b/src/wanijo/schema/domain.clj index 94a2910..b442b0d 100644 --- a/src/wanijo/schema/domain.clj +++ b/src/wanijo/schema/domain.clj @@ -42,3 +42,17 @@ :s_uuid (neo4j/uuid)}) first :uuid)) + +(neo4j/defquery + find-by-id! + "MATCH (s:schema) + WHERE s.uuid = {uuid} + RETURN s") + +(defn find-by-uuid! [uuid] + (->> + (neo4j/exec-query + find-by-id! + {:uuid uuid}) + first + :s)) diff --git a/src/wanijo/schema/routes.clj b/src/wanijo/schema/routes.clj index 5be7b0d..d3b0be7 100644 --- a/src/wanijo/schema/routes.clj +++ b/src/wanijo/schema/routes.clj @@ -6,7 +6,7 @@ [wanijo.schema.domain :as domain] [wanijo.schema.view :as view-schema])) -(defn- new! [req] +(defn new! [req] (if (form/valid? view-schema/new-form req) (do (domain/create-new! @@ -15,6 +15,13 @@ (resp/redirect "/schema")) (view-schema/overview! req))) +(defn show-schema! [uuid session] + (println uuid session) + (view-schema/show-schema! + (domain/find-by-uuid! uuid) + session)) + (defroutes schema-routes (GET "/schema" [] view-schema/overview!) + (GET "/schema/:uuid" [uuid :as req] (show-schema! uuid (:session req))) (POST "/schema/new" [] new!)) diff --git a/src/wanijo/schema/view.clj b/src/wanijo/schema/view.clj index f623038..3a518c2 100644 --- a/src/wanijo/schema/view.clj +++ b/src/wanijo/schema/view.clj @@ -15,22 +15,30 @@ uuid (:uuid session) schemas (domain/all-created-by! uuid)] (view/layout! - :session session - :content - [[:h1 "Ali jaki ijo"] - [:table - [:thead - [:tr - [:th "Nimi"] - [:th "Tenpo kama"]]] - [:tbody - (for [schema schemas] - [:tr - [:td (:name schema)] - [:td (:created_at schema)]])]] - [:h1 "Pali sin e jaki ijo"] - (hform/form-to - [:post "/schema/new"] - (form/field new-form :schema-name req) - (hform/submit-button "Pali") - (anti-forgery-field))]))) + :session session + :content + [[:h1 "Ali jaki ijo"] + [:table + [:thead + [:tr + [:th "Nimi"] + [:th "Tenpo kama"]]] + [:tbody + (for [schema schemas] + [:tr + [:td + [:a {:href (str "/schema/" (:uuid schema))} + (:name schema)]] + [:td (:created_at schema)]])]] + [:h1 "Pali sin e jaki ijo"] + (hform/form-to + [:post "/schema/new"] + (form/field new-form :schema-name req) + (hform/submit-button "Pali") + (anti-forgery-field))]))) + +(defn show-schema! [schema session] + (view/layout! + :session session + :content + [[:h1 "Jaki ijo " (:name schema)]]))