parent
b62c25df8d
commit
82cd9ed367
@ -1,4 +1,4 @@
|
|||||||
(ns wanijo.devmode
|
(ns wanijo.framework.devmode
|
||||||
(:require [hiccup.core :as hcore]))
|
(:require [hiccup.core :as hcore]))
|
||||||
|
|
||||||
(def bar-entries (atom []))
|
(def bar-entries (atom []))
|
@ -0,0 +1,43 @@
|
|||||||
|
(ns wanijo.framework.form
|
||||||
|
(:require [clojure.spec.alpha :as spec]
|
||||||
|
[hiccup.form :as hform]
|
||||||
|
[wanijo.framework.view :as view]))
|
||||||
|
|
||||||
|
(defn spec-to-errmsg [label spec-key field-value]
|
||||||
|
(view/flash-error
|
||||||
|
(map
|
||||||
|
(fn [prob]
|
||||||
|
[:p
|
||||||
|
"Field "
|
||||||
|
[:span.flash__field label]
|
||||||
|
" must comply to "
|
||||||
|
[:span.flash__pred (:pred prob)]])
|
||||||
|
(:clojure.spec.alpha/problems
|
||||||
|
(spec/explain-data spec-key field-value)))))
|
||||||
|
|
||||||
|
(defn field-valid? [value spec-key req]
|
||||||
|
(or (empty? (:form-params req))
|
||||||
|
(spec/valid? spec-key value)))
|
||||||
|
|
||||||
|
(defn field [form-def field req]
|
||||||
|
(let [field-value (get-in req [:params field])
|
||||||
|
field-def (get-in form-def [:fields field])
|
||||||
|
{:keys [label required] spec-key :spec} field-def]
|
||||||
|
(list
|
||||||
|
(when-not (field-valid? field-value spec-key req)
|
||||||
|
(spec-to-errmsg label spec-key field-value))
|
||||||
|
(hform/label field label)
|
||||||
|
(hform/text-field {:required (when required "required")}
|
||||||
|
field
|
||||||
|
field-value))))
|
||||||
|
|
||||||
|
(defn valid? [form-def req]
|
||||||
|
(reduce-kv
|
||||||
|
(fn [result field value]
|
||||||
|
(if-let [field-spec (get-in form-def [:fields field :spec])]
|
||||||
|
(if (spec/valid? field-spec value)
|
||||||
|
true
|
||||||
|
(reduced false))
|
||||||
|
result))
|
||||||
|
true
|
||||||
|
(:params req)))
|
@ -1,4 +1,4 @@
|
|||||||
(ns wanijo.repl
|
(ns wanijo.framework.repl
|
||||||
(:require [buddy.hashers :as hashers]
|
(:require [buddy.hashers :as hashers]
|
||||||
[neo4j-clj.core :as db]
|
[neo4j-clj.core :as db]
|
||||||
[wanijo.neo4j :as neo4j]))
|
[wanijo.neo4j :as neo4j]))
|
@ -0,0 +1,49 @@
|
|||||||
|
(ns wanijo.framework.view
|
||||||
|
(:require [hiccup.page :refer
|
||||||
|
[html5 include-css]]))
|
||||||
|
|
||||||
|
(defn btnlink
|
||||||
|
([target caption]
|
||||||
|
(btnlink target caption ""))
|
||||||
|
([target caption class]
|
||||||
|
[:a {:href target}
|
||||||
|
[:button {:class class}
|
||||||
|
caption]]))
|
||||||
|
|
||||||
|
(defn layout!
|
||||||
|
[& {:keys [content title session]
|
||||||
|
:or {content []
|
||||||
|
title nil
|
||||||
|
session {}}}]
|
||||||
|
(let [ident (:ident session)
|
||||||
|
authed? (some? ident)
|
||||||
|
devmode? (:devmode session)]
|
||||||
|
(html5
|
||||||
|
[:head
|
||||||
|
[:meta {:charset "utf-8"}]
|
||||||
|
[:meta {:name "viewport"
|
||||||
|
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
|
||||||
|
[:title (str "wan ijo" (when title (str " - " title)))]
|
||||||
|
(include-css "/css/app.css")
|
||||||
|
(when devmode? (include-css "/css/devmode.css"))]
|
||||||
|
[:body
|
||||||
|
[:section.grid
|
||||||
|
[:header
|
||||||
|
[:h1.app-title "wan ijo"
|
||||||
|
(when authed?
|
||||||
|
[:small.app-title__hello
|
||||||
|
(str "O, " ident)])]
|
||||||
|
(when authed?
|
||||||
|
[:section.header-content
|
||||||
|
(btnlink "/schema" "Jaki ijo" "header-content__link")
|
||||||
|
(btnlink "/logout" "Lape" "header-content__link")])]
|
||||||
|
[:nav (when authed? "nav")]
|
||||||
|
(vec (concat [:main] content))
|
||||||
|
[:aside (when authed? "aside")]
|
||||||
|
[:footer
|
||||||
|
[:small "Ilo pali e ijo"]]]])))
|
||||||
|
|
||||||
|
(defn flash-error [content]
|
||||||
|
[:section.flash--error
|
||||||
|
[:h2.flash__heading--error "Pakala"]
|
||||||
|
content])
|
@ -1,5 +1,5 @@
|
|||||||
(ns wanijo.home.view
|
(ns wanijo.home.view
|
||||||
(:require [wanijo.view.page :as page]))
|
(:require [wanijo.framework.view :as view]))
|
||||||
|
|
||||||
(defn root! [req]
|
(defn root! [req]
|
||||||
(page/layout! :session (:session req)))
|
(view/layout! :session (:session req)))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
(ns wanijo.domain.schema
|
(ns wanijo.schema.domain
|
||||||
(:require [clojure.spec.alpha :as spec]
|
(:require [clojure.spec.alpha :as spec]
|
||||||
[wanijo.neo4j :as neo4j]))
|
[wanijo.framework.neo4j :as neo4j]))
|
||||||
|
|
||||||
(spec/def ::name
|
(spec/def ::name
|
||||||
(spec/and string? not-empty))
|
(spec/and string? not-empty))
|
@ -1,5 +1,5 @@
|
|||||||
(ns wanijo.domain.user
|
(ns wanijo.user.domain
|
||||||
(:require [wanijo.neo4j :as neo4j]))
|
(:require [wanijo.framework.neo4j :as neo4j]))
|
||||||
|
|
||||||
(neo4j/defquery
|
(neo4j/defquery
|
||||||
find-user
|
find-user
|
@ -1,43 +0,0 @@
|
|||||||
(ns wanijo.view.forms
|
|
||||||
(:require [hiccup.form :as hform]
|
|
||||||
[clojure.spec.alpha :as spec]
|
|
||||||
[wanijo.view.page :as page]))
|
|
||||||
|
|
||||||
(defn spec-to-errmsg [label spec-key field-value]
|
|
||||||
(page/flash-error
|
|
||||||
(map
|
|
||||||
(fn [prob]
|
|
||||||
[:p
|
|
||||||
"Field "
|
|
||||||
[:span.flash__field label]
|
|
||||||
" must comply to "
|
|
||||||
[:span.flash__pred (:pred prob)]])
|
|
||||||
(:clojure.spec.alpha/problems
|
|
||||||
(spec/explain-data spec-key field-value)))))
|
|
||||||
|
|
||||||
(defn field-valid? [value spec-key req]
|
|
||||||
(or (empty? (:form-params req))
|
|
||||||
(spec/valid? spec-key value)))
|
|
||||||
|
|
||||||
(defn field [form-def field req]
|
|
||||||
(let [field-value (get-in req [:params field])
|
|
||||||
field-def (get-in form-def [:fields field])
|
|
||||||
{:keys [label required] spec-key :spec} field-def]
|
|
||||||
(list
|
|
||||||
(when-not (field-valid? field-value spec-key req)
|
|
||||||
(spec-to-errmsg label spec-key field-value))
|
|
||||||
(hform/label field label)
|
|
||||||
(hform/text-field {:required (when required "required")}
|
|
||||||
field
|
|
||||||
field-value))))
|
|
||||||
|
|
||||||
(defn valid? [form-def req]
|
|
||||||
(reduce-kv
|
|
||||||
(fn [result field value]
|
|
||||||
(if-let [field-spec (get-in form-def [:fields field :spec])]
|
|
||||||
(if (spec/valid? field-spec value)
|
|
||||||
true
|
|
||||||
(reduced false))
|
|
||||||
result))
|
|
||||||
true
|
|
||||||
(:params req)))
|
|
@ -1,49 +0,0 @@
|
|||||||
(ns wanijo.view.page
|
|
||||||
(:require [hiccup.page :refer
|
|
||||||
[html5 include-css]]))
|
|
||||||
|
|
||||||
(defn btnlink
|
|
||||||
([target caption]
|
|
||||||
(btnlink target caption ""))
|
|
||||||
([target caption class]
|
|
||||||
[:a {:href target}
|
|
||||||
[:button {:class class}
|
|
||||||
caption]]))
|
|
||||||
|
|
||||||
(defn layout!
|
|
||||||
[& {:keys [content title session]
|
|
||||||
:or {content []
|
|
||||||
title nil
|
|
||||||
session {}}}]
|
|
||||||
(let [ident (:ident session)
|
|
||||||
authed? (some? ident)
|
|
||||||
devmode? (:devmode session)]
|
|
||||||
(html5
|
|
||||||
[:head
|
|
||||||
[:meta {:charset "utf-8"}]
|
|
||||||
[:meta {:name "viewport"
|
|
||||||
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
|
|
||||||
[:title (str "wan ijo" (when title (str " - " title)))]
|
|
||||||
(include-css "/css/app.css")
|
|
||||||
(when devmode? (include-css "/css/devmode.css"))]
|
|
||||||
[:body
|
|
||||||
[:section.grid
|
|
||||||
[:header
|
|
||||||
[:h1.app-title "wan ijo"
|
|
||||||
(when authed?
|
|
||||||
[:small.app-title__hello
|
|
||||||
(str "O, " ident)])]
|
|
||||||
(when authed?
|
|
||||||
[:section.header-content
|
|
||||||
(btnlink "/schema" "Jaki ijo" "header-content__link")
|
|
||||||
(btnlink "/logout" "Lape" "header-content__link")])]
|
|
||||||
[:nav (when authed? "nav")]
|
|
||||||
(vec (concat [:main] content))
|
|
||||||
[:aside (when authed? "aside")]
|
|
||||||
[:footer
|
|
||||||
[:small "Ilo pali e ijo"]]]])))
|
|
||||||
|
|
||||||
(defn flash-error [content]
|
|
||||||
[:section.flash--error
|
|
||||||
[:h2.flash__heading--error "Pakala"]
|
|
||||||
content])
|
|
Loading…
Reference in new issue