From adca71875cd639dec6edbc13516af4cefd43e147 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 16 Jun 2018 11:29:21 +0100 Subject: [PATCH] Work on getting forms working. Not complete but a considerable advance. --- src/adl/to_selmer_routes.clj | 9 ++++- src/adl/to_selmer_templates.clj | 72 ++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/adl/to_selmer_routes.clj b/src/adl/to_selmer_routes.clj index 597797a..62170c1 100644 --- a/src/adl/to_selmer_routes.clj +++ b/src/adl/to_selmer_routes.clj @@ -61,7 +61,10 @@ 'defn (symbol n) (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 'l/render (list 'resolve-template (str n ".html")) @@ -71,10 +74,12 @@ (case (:tag f) (:form :page) {:record + (list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) [] (list (symbol (str "db/get-" (singularise (:name (:attrs e))))) - 'p)} + (symbol "db/*db*") + 'p))} :list {:records (list diff --git a/src/adl/to_selmer_templates.clj b/src/adl/to_selmer_templates.clj index a813092..b784f9b 100644 --- a/src/adl/to_selmer_templates.clj +++ b/src/adl/to_selmer_templates.clj @@ -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 "Return a table head element for the list view for this `list-spec` of this `entity` within - 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" + this `application`." [list-spec entity application] {:tag :thead :content @@ -388,33 +412,16 @@ :content (apply vector - (concat - (map - (fn [f] - (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)) - '({:tag :th - :content - [{:tag :input - :attrs {:type "submit" - :id "search" - :value "Search"}}]})))}]}) + (concat + (map + #(compose-list-search-widget % entity) + (fields list-spec)) + '({:tag :th + :content + [{:tag :input + :attrs {:type "submit" + :id "search" + :value "Search"}}]})))}]}) (defn edit-link @@ -425,8 +432,7 @@ (s/join "&" (map - #(let [n (:name (:attrs %1))] - (str n "={{ record." %2 " }}")) + #(str %1 "={{ record." %2 " }}") (key-names entity) parameters))))