integration-tests
Josha von Gizycki 6 years ago
commit e19376ad03

@ -11,6 +11,7 @@
body { body {
font-family: sans-serif; font-family: sans-serif;
margin: 0;
} }
a:link, a:link,
@ -52,8 +53,7 @@ h2 {
"nav main sidebar" "nav main sidebar"
"footer footer footer"; "footer footer footer";
margin: auto; margin: auto;
min-width: 900px; max-width: 1500px;
width: 80%;
nav { nav {
grid-area: nav; grid-area: nav;

@ -1,16 +1,19 @@
(ns wanijo.framework.form (ns wanijo.framework.form
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[hiccup.form :as hform] [hiccup.form :as hform]
[hiccup.core :as hcore]
[wanijo.framework.view :as view] [wanijo.framework.view :as view]
[ring.util.anti-forgery :refer [anti-forgery-field]])) [ring.util.anti-forgery :refer [anti-forgery-field]]
[wanijo.framework.common :refer [in?]]))
(spec/def ::label string?) (spec/def ::label string?)
(spec/def ::required boolean?) (spec/def ::required boolean?)
(spec/def ::spec keyword?) (spec/def ::spec keyword?)
(spec/def ::options (spec/def ::options
(spec/coll-of (spec/tuple string? string?))) (spec/or :empty empty?
:options (spec/coll-of (spec/tuple string? string?))))
(spec/def ::widget (spec/def ::widget
#(some (partial = %) [:input :select :checkbox :textarea])) #(in? [:input :select :checkbox :textarea :mselect] %))
(spec/def ::field (spec/def ::field
(spec/keys :req-un [::label (spec/keys :req-un [::label
::required ::required
@ -18,11 +21,7 @@
:opt-un [::options :opt-un [::options
::widget])) ::widget]))
(spec/def ::fields (spec/def ::fields
(spec/and map? (spec/map-of keyword? ::field))
(fn [map]
(every? #(spec/valid? ::field (val %)) map))
(fn [map]
(every? #(keyword? (key %)) map))))
(spec/def ::form (spec/def ::form
(spec/keys :req-un [::fields])) (spec/keys :req-un [::fields]))
@ -111,14 +110,31 @@
options options
(if validate? req-value value)))) (if validate? req-value value))))
(defn render-multiselect [id {:keys [label spec options]} value req-value validate?]
(list
(when (and validate? (not (spec/valid? spec req-value)))
(spec-to-errmsg label spec value))
(hform/label id label)
(hcore/html
[:select {:multiple "multiple"
:size 5
:name (name id)
:id (name id)}
(for [option options]
[:option {:value (second option)
:selected (in? (if validate? req-value value)
(second option))}
(first option)])])))
(def render-mapping (def render-mapping
{:input render-input {:input render-input
:checkbox render-checkbox :checkbox render-checkbox
:textarea render-textarea :textarea render-textarea
:select render-select}) :select render-select
:mselect render-multiselect})
(defn render-widgets [form-def values req] (defn render-widgets [form-def values req]
{:pre [(spec/valid? ::form form-def)]} {:pre [(spec/assert ::form form-def)]}
(let [form-hash (str (hash [form-def values])) (let [form-hash (str (hash [form-def values]))
submitted-hash (get-in req [:params :__form-hash]) submitted-hash (get-in req [:params :__form-hash])
validate? (= form-hash submitted-hash)] validate? (= form-hash submitted-hash)]

@ -8,6 +8,9 @@
(spec/def ::created-at (spec/def ::created-at
(spec/and string? ::neo4j/date-str)) (spec/and string? ::neo4j/date-str))
(spec/def ::assigned-to
(complement empty?))
(neo4j/defquery (neo4j/defquery
all-created-by all-created-by
"MATCH (s:schema)-->(u:user) "MATCH (s:schema)-->(u:user)
@ -110,3 +113,16 @@
(neo4j/exec-query! (neo4j/exec-query!
edit edit
schema)) schema))
(neo4j/defquery
assigned-users
"MATCH (s:schema)-[:assigned_to]-(u:user)
WHERE s.uuid = {uuid}
RETURN u
ORDER BY u.ident")
(defn assigned-users! [uuid]
(map :u
(neo4j/exec-query!
assigned-users
{:uuid uuid})))

@ -5,6 +5,7 @@
[wanijo.framework.form :as form] [wanijo.framework.form :as form]
[wanijo.framework.routing :refer [register! path]] [wanijo.framework.routing :refer [register! path]]
[wanijo.schema.domain :as domain] [wanijo.schema.domain :as domain]
[wanijo.user.domain :as domain-user]
[wanijo.schema.view :as view-schema] [wanijo.schema.view :as view-schema]
[wanijo.attribute.domain :as domain-attr])) [wanijo.attribute.domain :as domain-attr]))
@ -35,22 +36,36 @@
(resp/redirect (path :schema-overview))) (resp/redirect (path :schema-overview)))
{:status 403})) {:status 403}))
(defn view! [uuid req]
(view-schema/show-schema!
(assoc (domain/find-by-uuid! uuid)
:assigned (map :uuid (domain/assigned-users! uuid)))
(domain-attr/find-by-schema! uuid)
(assoc-in view-schema/access-form
[:fields :assigned :options]
(map #(vector (:ident %) (:uuid %))
(domain-user/all!)))
req))
(defn assign! [req]
(println (:params req)))
(defroutes routes (defroutes routes
(GET (register! :schema-overview "/schema") (GET (register! :schema-overview "/schema")
[] []
view-schema/overview!) view-schema/overview!)
(GET (register! :schema-show "/schema/:uuid") (GET (register! :schema-show "/schema/:uuid")
[uuid :as req] [uuid :as req]
(view-schema/show-schema! (view! uuid req))
(domain/find-by-uuid! uuid)
(domain-attr/find-by-schema! uuid)
req))
(POST (register! :schema-new "/schema/new") (POST (register! :schema-new "/schema/new")
[] []
new!) new!)
(POST (register! :schema-edit "/schema/edit") (POST (register! :schema-edit "/schema/edit")
[] []
edit!) edit!)
(POST (register! :schema-assign "/schema/assign")
[]
assign!)
(DELETE (register! :schema-delete "/schema/:uuid") (DELETE (register! :schema-delete "/schema/:uuid")
[uuid :as req] [uuid :as req]
(delete-schema! uuid (:session req)))) (delete-schema! uuid (:session req))))

@ -10,8 +10,8 @@
(def form (def form
{:fields {:name {:label "Name" {:fields {:name {:label "Name"
:required true :required true
:spec ::domain/name}}}) :spec ::domain/name}}})
(def attr-form (def attr-form
{:fields {:name {:label "Name" {:fields {:name {:label "Name"
@ -29,6 +29,12 @@
:spec ::attr-domain/required :spec ::attr-domain/required
:widget :checkbox}}}) :widget :checkbox}}})
(def access-form
{:fields {:assigned {:label "Users"
:required false
:spec :a
:widget :mselect}}})
(defn overview! [req] (defn overview! [req]
(let [session (:session req) (let [session (:session req)
uuid (:uuid session) uuid (:uuid session)
@ -55,7 +61,8 @@
(form/render-widgets form {} req) (form/render-widgets form {} req)
(hform/submit-button "Create"))]))) (hform/submit-button "Create"))])))
(defn show-schema! [schema attrs req] (defn show-schema! [schema attrs access-form req]
(println access-form)
(view/layout! (view/layout!
:session (:session req) :session (:session req)
:content :content
@ -65,7 +72,12 @@
(hform/form-to [:post (path :schema-edit)] (hform/form-to [:post (path :schema-edit)]
(form/render-widgets form schema req) (form/render-widgets form schema req)
(hform/hidden-field "uuid" (:uuid schema)) (hform/hidden-field "uuid" (:uuid schema))
(hform/submit-button "Save")) (hform/submit-button "Edit"))
[:h2 "Assign to users"]
(hform/form-to [:post (path :schema-assign)]
(form/render-widgets access-form schema req)
(hform/hidden-field "uuid" (:uuid schema))
(hform/submit-button "Assign"))
[:h2 "Attributes"] [:h2 "Attributes"]
[:ul.schema-attributes [:ul.schema-attributes
(for [attr attrs] (for [attr attrs]
@ -83,7 +95,7 @@
(hform/form-to [:post (path :attribute-new)] (hform/form-to [:post (path :attribute-new)]
(form/render-widgets attr-form {} req) (form/render-widgets attr-form {} req)
(hform/hidden-field "schema" (:uuid schema)) (hform/hidden-field "schema" (:uuid schema))
(hform/submit-button "Save")) (hform/submit-button "Create"))
[:h2 "Actions"] [:h2 "Actions"]
(hform/form-to {:class "inline"} (hform/form-to {:class "inline"}
[:delete (path :schema-delete schema)] [:delete (path :schema-delete schema)]

@ -23,3 +23,15 @@
{:ident ident}) {:ident ident})
first first
:n)) :n))
(neo4j/defquery
all
"MATCH (u:user)
RETURN u
ORDER BY u.ident")
(defn all! []
(map :u
(neo4j/exec-query!
all
{})))

Loading…
Cancel
Save