Work on getting forms working. Not complete but a considerable advance.
This commit is contained in:
parent
40fc3a99cc
commit
adca71875c
|
@ -61,7 +61,10 @@
|
||||||
'defn
|
'defn
|
||||||
(symbol n)
|
(symbol n)
|
||||||
(vector 'r)
|
(vector 'r)
|
||||||
(list 'let (vector 'p (list :form-params 'r))
|
(list 'let (vector 'p (list :params 'r)) ;; TODO: we must take key params out of just params,
|
||||||
|
;; but we should take all other params out of form-params - because we need the key to
|
||||||
|
;; load the form in the first place, but just accepting values of other params would
|
||||||
|
;; allow spoofing.
|
||||||
(list
|
(list
|
||||||
'l/render
|
'l/render
|
||||||
(list 'resolve-template (str n ".html"))
|
(list 'resolve-template (str n ".html"))
|
||||||
|
@ -71,10 +74,12 @@
|
||||||
(case (:tag f)
|
(case (:tag f)
|
||||||
(:form :page)
|
(:form :page)
|
||||||
{:record
|
{:record
|
||||||
|
(list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) []
|
||||||
(list
|
(list
|
||||||
(symbol
|
(symbol
|
||||||
(str "db/get-" (singularise (:name (:attrs e)))))
|
(str "db/get-" (singularise (:name (:attrs e)))))
|
||||||
'p)}
|
(symbol "db/*db*")
|
||||||
|
'p))}
|
||||||
:list
|
:list
|
||||||
{:records
|
{:records
|
||||||
(list
|
(list
|
||||||
|
|
|
@ -366,12 +366,36 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
(defn compose-list-search-widget
|
||||||
|
[field entity]
|
||||||
|
(let [property (first
|
||||||
|
(children
|
||||||
|
entity
|
||||||
|
(fn [p] (and (= (:tag p) :property)
|
||||||
|
(= (:name (:attrs p)) (:property (:attrs field)))))))
|
||||||
|
input-type (case (:type (:attrs property))
|
||||||
|
("integer" "real" "money") "number"
|
||||||
|
("date" "timestamp") "date"
|
||||||
|
"time" "time"
|
||||||
|
"text")
|
||||||
|
base-name (:property (:attrs field))
|
||||||
|
search-name (if
|
||||||
|
(= (:type (:attrs property)) "entity")
|
||||||
|
(str base-name "_expanded") base-name)]
|
||||||
|
(hash-map
|
||||||
|
:tag :th
|
||||||
|
:content
|
||||||
|
[{:tag :input
|
||||||
|
:attrs {:id search-name
|
||||||
|
:type input-type
|
||||||
|
:name search-name
|
||||||
|
:value (str "{{ params." search-name " }}")}}])))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn- list-thead
|
(defn- list-thead
|
||||||
"Return a table head element for the list view for this `list-spec` of this `entity` within
|
"Return a table head element for the list view for this `list-spec` of this `entity` within
|
||||||
this `application`.
|
this `application`."
|
||||||
|
|
||||||
TODO: where entity fields are being shown/searched on, we should be using the user-distinct
|
|
||||||
fields of the far side, rather than key values"
|
|
||||||
[list-spec entity application]
|
[list-spec entity application]
|
||||||
{:tag :thead
|
{:tag :thead
|
||||||
:content
|
:content
|
||||||
|
@ -390,24 +414,7 @@
|
||||||
vector
|
vector
|
||||||
(concat
|
(concat
|
||||||
(map
|
(map
|
||||||
(fn [f]
|
#(compose-list-search-widget % entity)
|
||||||
(let [property (first
|
|
||||||
(children
|
|
||||||
entity
|
|
||||||
(fn [p] (and (= (:tag p) :property)
|
|
||||||
(= (:name (:attrs p)) (:property (:attrs f)))))))]
|
|
||||||
(hash-map
|
|
||||||
:tag :th
|
|
||||||
:content
|
|
||||||
[{:tag :input
|
|
||||||
:attrs {:id (:property (:attrs f))
|
|
||||||
:type (case (:type (:attrs property))
|
|
||||||
("integer" "real" "money") "number"
|
|
||||||
("date" "timestamp") "date"
|
|
||||||
"time" "time"
|
|
||||||
"text")
|
|
||||||
:name (:property (:attrs f))
|
|
||||||
:value (str "{{ params." (:property (:attrs f)) " }}")}}])))
|
|
||||||
(fields list-spec))
|
(fields list-spec))
|
||||||
'({:tag :th
|
'({:tag :th
|
||||||
:content
|
:content
|
||||||
|
@ -425,8 +432,7 @@
|
||||||
(s/join
|
(s/join
|
||||||
"&"
|
"&"
|
||||||
(map
|
(map
|
||||||
#(let [n (:name (:attrs %1))]
|
#(str %1 "={{ record." %2 " }}")
|
||||||
(str n "={{ record." %2 " }}"))
|
|
||||||
(key-names entity)
|
(key-names entity)
|
||||||
parameters))))
|
parameters))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue