parent
2b09913ca4
commit
b62c25df8d
@ -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!))
|
||||
|
@ -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))])))
|
Loading…
Reference in new issue