butiful devbar

integration-tests
Josha von Gizycki 7 years ago
parent da8fb77fc0
commit a2bd971596

@ -12,9 +12,9 @@
:exclusions [commons-codec]]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]
:plugins [[lein-less "1.7.5"]]}}
:profiles {:dev {:dependencies
[[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]
:plugins [[lein-less "1.7.5"]]}}
:less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"})

@ -0,0 +1,24 @@
.devbar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
font-family: monospace;
background-color: #ccc;
ol {
list-style-type: none;
padding: 0;
margin: 0;
li {
padding: .5rem;
border: 1px solid black;
margin: .5rem;
pre {
margin: 0;
}
}
}
}

@ -0,0 +1,45 @@
(ns wanijo.devmode
(:require [hiccup.core :as hcore]))
(def bar-entries (atom []))
(defn send-to-bar [msg]
(swap! bar-entries #(conj % msg)))
(defn devmode-on? [req]
(let [query-param (get-in req [:query-params "dev"])
cookie (get-in req [:cookies "devmode" :value])]
(or (= query-param "on")
(and (= cookie "1")
(not= query-param "off")))))
(defn devbar []
(hcore/html
[:section.devbar
[:ol
(for [entry @bar-entries]
[:li [:pre entry]])]]))
(defn append-devbar [resp]
(let [body (:body resp)
new-body (clojure.string/replace
body "</body>" (str (devbar) "</body>"))]
(assoc resp :body new-body)))
(defn wrap-devmode [handler]
(fn [req]
(let [on? (devmode-on? req)
query-param? (get-in req [:query-params "dev"])
new-req (assoc-in req [:session :devmode] on?)
resp (handler new-req)
new-resp (cond
on? (-> resp
append-devbar
(assoc-in [:cookies :devmode] 1))
(some? query-param?) (assoc-in
resp
[:cookies :devmode]
(if on? 1 0))
:else resp)]
(reset! bar-entries [])
new-resp)))

@ -1,10 +1,11 @@
(ns wanijo.domain.schema
(:require [clojurewerkz.neocons.rest.cypher :as cypher]
[clojure.spec.alpha :as spec]
[wanijo.neo4j :as neo4j]))
[wanijo.neo4j :as neo4j]
[wanijo.devmode :as devmode]))
(spec/def ::name
(spec/and string? not-empty))
(spec/and string? not-empty int?))
(spec/def ::created-at
(spec/or :int (spec/and int?
@ -13,12 +14,12 @@
#(re-matches #"\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}" %))))
(defn all-created-by! [ident]
(->>
(cypher/tquery
neo4j/conn
"MATCH (s:schema)-[created_by]->(u:user)
(neo4j/query-rawdata!
:query
"MATCH (s:schema)-[:created_by]->(u:user)
WHERE u.ident = {ident}
RETURN s
ORDER BY s.name"
{:ident ident})
(map #(:data (get % "s")))))
:params {:ident ident}
:alias "s"
))

@ -3,7 +3,7 @@
[clojure.spec.alpha :as spec]
[wanijo.view :as view]))
(defn spec-to-errmsg [label spec-data]
(defn spec-to-errmsg [label spec-key field-value]
(view/flash-error
(map
(fn [prob]
@ -12,24 +12,27 @@
[:span.flash__field label]
" must comply to "
[:span.flash__pred (:pred prob)]])
(:clojure.spec.alpha/problems spec-data))))
(: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
spec-valid? (or (empty? (:params req))
(spec/valid? spec-key field-value))]
{:keys [label required] spec-key :spec} field-def]
(list
(when-not spec-valid?
(spec-to-errmsg label
(spec/explain-data spec-key field-value)))
(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
(get-in req [:params field])))))
field-value))))
(defn valid? [req form-def]
(defn valid? [form-def req]
(clojure.pprint/pprint req)
(reduce-kv
(fn [result field value]
(if (spec/valid?

@ -7,13 +7,14 @@
[ring.middleware.session.cookie :as session-cookie]
[wanijo.auth.routes :refer [auth-routes]]
[wanijo.home.routes :refer [home-routes]]
[wanijo.schema.routes :refer [schema-routes]]))
[wanijo.schema.routes :refer [schema-routes]]
[wanijo.devmode :as devmode]))
(defn- wrap-login-redirect [handler]
(fn [req]
(if-not (get-in req [:session :ident])
(rur/redirect "/login")
(handler req))))
(if (get-in req [:session :ident])
(handler req)
(rur/redirect "/login"))))
(defroutes app-routes
(routes auth-routes)
@ -24,6 +25,9 @@
(def app
(-> app-routes
(wrap-defaults (assoc-in site-defaults
[:session :store]
(session-cookie/cookie-store {:key "1234567890123456"})))))
devmode/wrap-devmode
(wrap-defaults
(assoc-in site-defaults
[:session :store]
(session-cookie/cookie-store
{:key "1234567890123456"})))))

@ -1,14 +1,36 @@
(ns wanijo.neo4j
(:require [clojurewerkz.neocons.rest :as nr]
[clojurewerkz.neocons.rest.nodes :as nrn]
[clojurewerkz.neocons.rest.cypher :as nrc]))
[clojurewerkz.neocons.rest.cypher :as cypher]
[wanijo.devmode :as devmode]))
(def conn (nr/connect "http://neo4j:b@localhost:7474/db/data"))
(def conn
(delay (nr/connect "http://neo4j:b@localhost:7474/db/data")))
(defn conn! []
@conn)
(defn butiful-query [qry]
(->> qry
clojure.string/trim-newline
clojure.string/split-lines
(map clojure.string/trim)
(filter #(> (count %) 0))
(clojure.string/join \newline)))
(defn query-rawdata!
[& {:keys [query alias params]
:or {params {}}}]
(devmode/send-to-bar (str (butiful-query query) "<br>---Params---<br>" params))
(->>
(cypher/tquery (conn!) query params)
(map #(get % alias))
(map :data)))
(defn find-user! [ident]
(some->
(nrc/tquery
conn
(cypher/tquery
(conn!)
"MATCH (n:user) WHERE n.ident = {ident} RETURN n"
{:ident ident})
first

@ -15,16 +15,17 @@
:or {content []
title nil
session {}}}]
(println session)
(let [ident (:ident session)
authed? (some? ident)]
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")]
(include-css "/css/app.css")
(when devmode? (include-css "/css/devmode.css"))]
[:body
[:section.grid
[:header

Loading…
Cancel
Save