instance editing with property merging

integration-tests
Josha von Gizycki 6 years ago
parent cccfa3e237
commit a8a16a0663

@ -31,6 +31,7 @@
[lein-kibit "LATEST"]]}
:uberjar {:aot :all}}
:repl-options {:init-ns wanijo.framework.repl}
:ring {:handler wanijo.handler/app}
:less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"}

@ -32,7 +32,8 @@
CREATE (p:property {uuid:{prop_uuid}})-[:of]->(i),
(p)-[:of]->(a)
SET p.value = {value},
p.created_at = {created_at}")
p.created_at = {created_at},
p.updated_at = {updated_at}")
(defn create! [schema-uuid instance]
(let [instance-uuid (neo4j/uuid)
@ -82,8 +83,29 @@
SET i.name = {name},
i.updated_at = {updated_at}")
(neo4j/defquery edit-property
"MATCH (i:instance {uuid:{instance_uuid}}),
(a:attribute {uuid:{attribute_uuid}})
MERGE (p:property {uuid:{uuid}})-[:of]->(i)
MERGE (p)-[:of]->(a)
ON CREATE SET p.created_at = {now},
p.updated_at = {now},
p.value = {value}
ON MATCH SET p.updated_at = {now},
p.value = {value}")
(defn edit! [instance]
(neo4j/exec-query! edit-instance
(clojure.pprint/pprint instance)
(let [prop-tuples (map #(vector edit-property
{:uuid (:uuid % (neo4j/uuid))
:now (neo4j/now-str)
:value (:value %)
:instance_uuid (:uuid instance)
:attribute_uuid (-> % :attribute :uuid)})
(:properties instance))]
(apply neo4j/exec-queries!
(concat [[edit-instance
{:uuid (:uuid instance)
:name (:name instance)
:updated_at (neo4j/now-str)}))
:updated_at (neo4j/now-str)}]]
prop-tuples))))

@ -20,6 +20,9 @@
:required (= 1 (:required attr))
:widget (attr-type->widget (:type attr))})
(defn attr->uuid-field-id [attr]
(keyword (str "attr-" (:uuid attr) "-prop-uuid")))
(defn with-attributes [attrs]
(update form
:fields
@ -27,21 +30,26 @@
(reduce (fn [fields attr]
(assoc fields
(attr->field-id attr)
(attr->field attr)))
(attr->field attr)
(attr->uuid-field-id attr)
{:widget :hidden}))
fields
attrs))))
(defn form-data->instance [form-data attrs]
{:name (:name form-data)
:properties (map (fn [ra]
{:attribute ra
:value ((attr->field-id ra) form-data)})
:properties (map (fn [attr]
{:attribute attr
:value ((attr->field-id attr) form-data)
:uuid ((attr->uuid-field-id attr) form-data)})
attrs)})
(defn instance->form-data [instance]
(merge {:name (:name instance)}
(reduce #(assoc %1
(attr->field-id (:attribute %2))
(:value %2))
(:value %2)
(attr->uuid-field-id (:attribute %2))
(:uuid %2))
{}
(:properties instance))))

@ -41,4 +41,4 @@
[[:h1 (:name instance)]
(hform/form-to [:post (path :instance-edit instance)]
(form/render-widgets form form-data req)
(hform/submit-button "Create!"))]))
(hform/submit-button "Edit!"))]))

Loading…
Cancel
Save