dedicated edit route for instances, view-only route

integration-tests
Josha von Gizycki 6 years ago
parent b8339001f0
commit 5541b3113d

@ -28,6 +28,11 @@ a:active {
h1 { h1 {
font-size: 1.5rem; font-size: 1.5rem;
small {
font-weight: normal;
font-size: 1.5rem;
}
} }
h2 { h2 {
@ -35,6 +40,10 @@ h2 {
border-bottom: 1px solid @ci-blue; border-bottom: 1px solid @ci-blue;
} }
em {
font-weight: bold;
}
.thin-border { .thin-border {
border: @border-stack; border: @border-stack;
} }

@ -56,12 +56,15 @@
(neo4j/defquery find-by-uuid (neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}}) "MATCH (i:instance {uuid:{uuid}})
RETURN i") -[:of]->(s:schema)
RETURN i, s")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
(->> (neo4j/exec-query! find-by-uuid (->> (neo4j/exec-query! find-by-uuid
{:uuid uuid}) {:uuid uuid})
(map :i) (map #(assoc (:i %)
:schema
(:s %)))
first)) first))
(neo4j/defquery find-properties (neo4j/defquery find-properties

@ -1,6 +1,5 @@
(ns wanijo.instance.forms (ns wanijo.instance.forms
(:require [wanijo.instance.domain :as domain] (:require [wanijo.instance.domain :as domain]))
[wanijo.attribute.domain :as domain-attr]))
(def form (def form
{:fields {:name {:label "Name" {:fields {:name {:label "Name"

@ -44,9 +44,14 @@
(domain/find-properties! uuid))) (domain/find-properties! uuid)))
(defn show! [uuid req] (defn show! [uuid req]
(view/show! (instance! uuid)
(domain-attr/find-by-instance! uuid)
req))
(defn edit-form! [uuid req]
(let [instance (instance! uuid) (let [instance (instance! uuid)
attrs (domain-attr/find-by-instance! uuid)] attrs (domain-attr/find-by-instance! uuid)]
(view/show! instance (view/edit! instance
(form! uuid) (form! uuid)
(forms-inst/instance->form-data instance) (forms-inst/instance->form-data instance)
req))) req)))
@ -74,6 +79,9 @@
(GET (register! :instance-show "/instance/:uuid") (GET (register! :instance-show "/instance/:uuid")
[uuid :as req] [uuid :as req]
(show! uuid req)) (show! uuid req))
(GET (register! :instance-edit-form "/instance/:uuid/edit")
[uuid :as req]
(edit-form! uuid req))
(POST (register! :instance-edit "/instance/:uuid") (POST (register! :instance-edit "/instance/:uuid")
[uuid :as req] [uuid :as req]
(edit! uuid req))) (edit! uuid req)))

@ -34,7 +34,25 @@
(:uuid schema)) (:uuid schema))
(hform/submit-button "Create!"))])) (hform/submit-button "Create!"))]))
(defn show! [instance form form-data req] (defn show! [instance attrs req]
(view/layout!
:request req
:content
[[:h1
(-> instance :schema :name)
" "
[:small (:name instance)]]
[:p
[:small [:a {:href (path :instance-edit-form instance)}
"Edit Instance"]]]
(for [attr attrs
:let [auuid (:uuid attr)
prop (first (filter #(= auuid (-> % :attribute :uuid))
(:properties instance)))]]
(list [:em (:name attr)]
[:p (:value prop)]))]))
(defn edit! [instance form form-data req]
(view/layout! (view/layout!
:request req :request req
:content :content

Loading…
Cancel
Save