diff --git a/.gitignore b/.gitignore index 4e50b60..7c55f4e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ pom.xml.asc /.lein-* /.nrepl-port /resources/public/css +.idea +*.iml diff --git a/src/wanijo/schema/routes.clj b/src/wanijo/schema/routes.clj index 76f1def..c27b51f 100644 --- a/src/wanijo/schema/routes.clj +++ b/src/wanijo/schema/routes.clj @@ -1,52 +1,19 @@ (ns wanijo.schema.routes (:require [compojure.core :refer [defroutes GET POST]] - [ring.util.anti-forgery :refer [anti-forgery-field]] [ring.util.response :as resp] - [hiccup.form :as hform] [wanijo.domain.schema :as domain-schema] - [wanijo.view.page :as page] - [wanijo.view.forms :as forms])) - -(def new-schema-form - {:fields {:schema-name {:label "Nimi" - :required true - :spec :wanijo.domain.schema/name}}}) - -(defn- overview! [req] - (let [session (:session req) - uuid (:uuid session) - schemas (domain-schema/all-created-by! uuid)] - (println schemas) - (page/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"] - (forms/field new-schema-form :schema-name req) - (hform/submit-button "Pali") - (anti-forgery-field))]))) + [wanijo.view.forms :as forms] + [wanijo.schema.view :as view-schema])) (defn- new! [req] - (if (forms/valid? new-schema-form req) + (if (forms/valid? view-schema/new-form req) (do (domain-schema/create-new! (get-in req [:params :schema-name]) (get-in req [:session :uuid])) (resp/redirect "/schema")) - (overview! req))) + (view-schema/overview! req))) (defroutes schema-routes - (GET "/schema" [] overview!) + (GET "/schema" [] view-schema/overview!) (POST "/schema/new" [] new!)) diff --git a/src/wanijo/schema/view.clj b/src/wanijo/schema/view.clj new file mode 100644 index 0000000..d6f7973 --- /dev/null +++ b/src/wanijo/schema/view.clj @@ -0,0 +1,36 @@ +(ns wanijo.schema.view + (:require [hiccup.form :as hform] + [ring.util.anti-forgery :refer [anti-forgery-field]] + [wanijo.view.page :as page] + [wanijo.domain.schema :as domain-schema] + [wanijo.view.forms :as forms])) + +(def new-form + {:fields {:schema-name {:label "Nimi" + :required true + :spec :wanijo.domain.schema/name}}}) + +(defn overview! [req] + (let [session (:session req) + uuid (:uuid session) + schemas (domain-schema/all-created-by! uuid)] + (page/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"] + (forms/field new-form :schema-name req) + (hform/submit-button "Pali") + (anti-forgery-field))])))