#3 Auxlists mostly working

Problems: generating some wrong fieldnames in HugSQL, apparently through not using (safe-name x :sql); not using the right views where multiple links from one entity to another; not getting distinction between many-to-many and one-to-many right.
This commit is contained in:
Simon Brooke 2018-07-30 13:59:23 +01:00
parent 19f1e7e513
commit b78b311d99
3 changed files with 119 additions and 77 deletions

View file

@ -298,7 +298,7 @@
farkey (-> % :attrs :farkey) farkey (-> % :attrs :farkey)
link-type (-> % :attrs :type) link-type (-> % :attrs :type)
link-field (-> % :attrs :name) link-field (-> % :attrs :name)
query-name (list-related-query-name entity far-entity) query-name (list-related-query-name far-entity entity)
signature ":? :*"] signature ":? :*"]
(hash-map (hash-map
(keyword query-name) (keyword query-name)

View file

@ -132,12 +132,13 @@
:entity :entity
#(= (-> % :attrs :name) f-name))] #(= (-> % :attrs :name) f-name))]
(if (and (entity? entity) (entity? farside)) (if (and (entity? entity) (entity? farside))
(list 'if (list 'all-keys-present? 'params (set (key-names entity true)))
(hash-map (hash-map
(keyword (auxlist-data-name auxlist)) (keyword (auxlist-data-name auxlist))
(list (list
(symbol (str "db/" (list-related-query-name entity farside))) (symbol (str "db/" (list-related-query-name entity farside)))
'db/*db* 'db/*db*
{:id (list :id 'params)})) {:id (list :id 'params)})))
(do (do
(if-not (if-not
(entity? entity) (entity? entity)

View file

@ -66,7 +66,6 @@
(defn emit-content (defn emit-content
([content] ([content]
(do-or-warn
(cond (cond
(nil? content) (nil? content)
nil nil
@ -78,8 +77,7 @@
(seq? content) (seq? content)
(map emit-content (remove nil? content)) (map emit-content (remove nil? content))
true true
(str "<!-- don't know what to do with '" content "' -->")) (str "<!-- don't know what to do with '" content "' -->")))
(str "Failed while writing " content)))
([filename application k] ([filename application k]
(emit-content filename nil nil application k)) (emit-content filename nil nil application k))
([filename spec entity application k] ([filename spec entity application k]
@ -375,6 +373,20 @@
"{% endif %}")))}) "{% endif %}")))})
(defn get-size-for-widget
"Return, as an integer, the fieldwidth for the input widget for this
`property`."
[property]
(let [s (try
(read-string
(:size (:attrs property)))
(catch Exception _ 16))]
(if
(not (integer? s))
16
s)))
(defn compose-input-widget-para (defn compose-input-widget-para
"Generate an input widget for this `field-or-property` of this `form` for "Generate an input widget for this `field-or-property` of this `form` for
this `entity` taken from within this `application`, in context of a para this `entity` taken from within this `application`, in context of a para
@ -391,17 +403,8 @@
:name widget-name :name widget-name
:type w-type :type w-type
:value (str "{{record." widget-name "}}") :value (str "{{record." widget-name "}}")
:maxlength (:size (:attrs property)) :maxlength (str (max (get-size-for-widget property) 16))
:size (cond :size (str (min (get-size-for-widget property) 60))}
(nil? (:size (:attrs property)))
"16"
(try
(> (read-string
(:size (:attrs property))) 60)
(catch Exception _ false))
"60"
true
(:size (:attrs property)))}
;; TODO: should match pattern from typedef ;; TODO: should match pattern from typedef
(if (if
(:minimum (:attrs typedef)) (:minimum (:attrs typedef))
@ -480,10 +483,12 @@
(defn edit-link (defn edit-link
[entity application parameters] [source entity application parameters]
(str (str
"{{servlet-context}}/" "{{servlet-context}}/"
(editor-name entity application) (or
(-> source :attrs :onselect)
(editor-name entity application))
"?" "?"
(s/join (s/join
"&amp;" "&amp;"
@ -495,7 +500,7 @@
(defn list-tbody (defn list-tbody
"Return a table body element for the list view for this `list-spec` of "Return a table body element for the list view for this `list-spec` of
this `entity` within this `application`, using data from this source." this `entity` within this `application`, using data from this `source`."
[source list-spec entity application] [source list-spec entity application]
{:tag :tbody {:tag :tbody
:content :content
@ -504,6 +509,8 @@
:content :content
(apply (apply
vector vector
(remove
nil?
(concat (concat
(map (map
(fn [field] (fn [field]
@ -525,7 +532,11 @@
(= (:type (:attrs p)) "entity") (= (:type (:attrs p)) "entity")
[{:tag :a [{:tag :a
:attrs {:href (edit-link :attrs {:href (edit-link
e source
(child-with-tag
application
:entity
#(= (-> % :attrs :name)(-> p :attrs :entity)))
application application
(list (:name (:attrs p))))} (list (:name (:attrs p))))}
:content [(str "{{ record." s "_expanded }}")]}] :content [(str "{{ record." s "_expanded }}")]}]
@ -533,10 +544,14 @@
(children-with-tag list-spec :field)) (children-with-tag list-spec :field))
[{:tag :td [{:tag :td
:content :content
[{:tag :a [(if
(or (= (:tag list-spec) :form)
(-> list-spec :attrs :onselect))
{:tag :a
:attrs :attrs
{:href (edit-link entity application (key-names entity))} {:href (edit-link source entity application (key-names entity))}
:content ["View"]}]}]))} :content ["View"]}
"&nbsp;")]}])))}
"{% endfor %}"]}) "{% endfor %}"]})
@ -559,7 +574,17 @@
{:tag :div {:tag :div
:attrs {:class "auxlist"} :attrs {:class "auxlist"}
:content :content
[{:tag :h2 (apply
vector
(remove
nil?
(flatten
(list
;; only show auxlists if we've got keys
(str "{% if all "
(s/join " " (map #(str "params." %) (key-names entity)))
" %}")
{:tag :h2
:content [(prompt auxlist form entity application)]} :content [(prompt auxlist form entity application)]}
{:tag :table {:tag :table
:content :content
@ -569,6 +594,8 @@
:content :content
(apply (apply
vector vector
(remove
nil?
(flatten (flatten
(list (list
(map (map
@ -576,12 +603,25 @@
:tag :th :tag :th
:content [(prompt % form entity application)]) :content [(prompt % form entity application)])
(children-with-tag auxlist :field)) (children-with-tag auxlist :field))
{:tag :th :content ["&nbsp;"]})))}]} {:tag :th :content ["&nbsp;"]}))))}]}
(list-tbody (list-tbody
(auxlist-data-name auxlist) (auxlist-data-name auxlist)
auxlist auxlist
farside farside
application)]}]}))) application)]}
(if
(= (-> auxlist :attrs :canadd) "true")
(wrap-in-if-member-of
(big-link (str
"Add a new "
(pretty-name property))
(editor-name farside application))
:writeable
farside
application)
)
"{% endif %}"
))))})))
(defn compose-form-auxlists (defn compose-form-auxlists
@ -1031,11 +1071,12 @@
(if (if
(pos? *verbosity*) (pos? *verbosity*)
(*warn* "\tGenerated " filepath)) (*warn* "\tGenerated " filepath))
(str filepath)))))) (str filepath))
(str "While generating " filepath)))))
;; (def a (x/parse "../youyesyet/youyesyet.canonical.adl.xml")) ;; (def a (x/parse "../youyesyet/youyesyet.canonical.adl.xml"))
;; (def e (child-with-tag a :entity)) ;; (def e (child-with-tag a :entity #(= (-> % :attrs :name) "teams")))
;; (def f (child-with-tag e :form)) ;; (def f (child-with-tag e :form))
;; (write-template-file "froboz" (form-to-template f e a) a) ;; (write-template-file "froboz" (form-to-template f e a) a)
;; (def t (form-to-template f e a)) ;; (def t (form-to-template f e a))