Small improvements. More and more works.
This commit is contained in:
parent
981ff1d5fc
commit
ac070b537f
|
@ -114,10 +114,6 @@
|
||||||
(defn update-query
|
(defn update-query
|
||||||
"Generate an appropriate `update` query for this `entity`"
|
"Generate an appropriate `update` query for this `entity`"
|
||||||
[entity]
|
[entity]
|
||||||
(if
|
|
||||||
(and
|
|
||||||
(has-primary-key? entity)
|
|
||||||
(has-non-key-properties? entity))
|
|
||||||
(let [entity-name (safe-name (:name (:attrs entity)) :sql)
|
(let [entity-name (safe-name (:name (:attrs entity)) :sql)
|
||||||
pretty-name (singularise entity-name)
|
pretty-name (singularise entity-name)
|
||||||
property-names (map #(:name (:attrs %)) (insertable-properties entity))
|
property-names (map #(:name (:attrs %)) (insertable-properties entity))
|
||||||
|
@ -136,8 +132,7 @@
|
||||||
"SET "
|
"SET "
|
||||||
(s/join ",\n\t" (map #(str (safe-name % :sql) " = " (keyword %)) property-names))
|
(s/join ",\n\t" (map #(str (safe-name % :sql) " = " (keyword %)) property-names))
|
||||||
"\n"
|
"\n"
|
||||||
(where-clause entity))}))
|
(where-clause entity))})))
|
||||||
{}))
|
|
||||||
|
|
||||||
|
|
||||||
(defn search-query [entity application]
|
(defn search-query [entity application]
|
||||||
|
|
|
@ -182,28 +182,49 @@
|
||||||
(list
|
(list
|
||||||
'l/render
|
'l/render
|
||||||
(list 'support/resolve-template (str n ".html"))
|
(list 'support/resolve-template (str n ".html"))
|
||||||
'(:session r)
|
(list :session 'r)
|
||||||
(merge
|
(list 'merge
|
||||||
{:title (capitalise (:name (:attrs f)))
|
{:title (capitalise (:name (:attrs f)))
|
||||||
:params 'p}
|
:params 'p}
|
||||||
(case (:tag f)
|
(case (:tag f)
|
||||||
(:form :page)
|
(:form :page)
|
||||||
(reduce
|
(list
|
||||||
merge
|
'reduce
|
||||||
|
'merge
|
||||||
|
(list 'merge
|
||||||
|
(list 'cond (list :save-button 'p)
|
||||||
|
(list 'try
|
||||||
|
(list 'if
|
||||||
|
(list 'some (key-names e) (list 'map 'name (list 'keys 'p)))
|
||||||
|
(list 'do
|
||||||
|
(list (symbol
|
||||||
|
(str "db/update-" (singularise (-> e :attrs :name)) "!"))
|
||||||
|
'db/*db*
|
||||||
|
'p)
|
||||||
|
{:message "Updated record"})
|
||||||
|
(list 'do
|
||||||
|
(list (symbol
|
||||||
|
(str "db/create-" (singularise (-> e :attrs :name)) "!"))
|
||||||
|
'db/*db*
|
||||||
|
'p)
|
||||||
|
{:message "Saved record"}))
|
||||||
|
`(catch Exception any#
|
||||||
|
{:error (.getMessage any#)})))
|
||||||
{:record
|
{:record
|
||||||
(list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) []
|
(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)))))
|
||||||
(symbol "db/*db*")
|
(symbol "db/*db*")
|
||||||
'p))}
|
'p))})
|
||||||
|
(cons 'list
|
||||||
(map
|
(map
|
||||||
(fn [p]
|
(fn [p]
|
||||||
(hash-map
|
(hash-map
|
||||||
(keyword (-> p :attrs :entity))
|
(keyword (-> p :attrs :entity))
|
||||||
(list (symbol (str "db/list-" (:entity (:attrs p)))) (symbol "db/*db*"))))
|
(list (symbol (str "db/list-" (:entity (:attrs p)))) (symbol "db/*db*"))))
|
||||||
(filter #(#{"entity" "link"} (:type (:attrs %)))
|
(filter #(#{"entity" "link"} (:type (:attrs %)))
|
||||||
(descendants-with-tag e :property))))
|
(descendants-with-tag e :property)))))
|
||||||
:list
|
:list
|
||||||
{:records
|
{:records
|
||||||
(list
|
(list
|
||||||
|
@ -231,6 +252,7 @@
|
||||||
;; (def e (child-with-tag a :entity))
|
;; (def e (child-with-tag a :entity))
|
||||||
;; (def f (child-with-tag e :form))
|
;; (def f (child-with-tag e :form))
|
||||||
;; (def n (path-part f e a))
|
;; (def n (path-part f e a))
|
||||||
|
;; (make-handler f e a)
|
||||||
;; (vector
|
;; (vector
|
||||||
;; 'p
|
;; 'p
|
||||||
;; (list 'merge
|
;; (list 'merge
|
||||||
|
|
|
@ -114,7 +114,6 @@
|
||||||
"\n"
|
"\n"
|
||||||
(flatten
|
(flatten
|
||||||
(list
|
(list
|
||||||
"{% endblock %}"
|
|
||||||
(emit-content filename spec entity application :foot))))))
|
(emit-content filename spec entity application :foot))))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,20 +237,23 @@
|
||||||
magnitude (try (read-string (:magnitude (:attrs farside))) (catch Exception _ 7))
|
magnitude (try (read-string (:magnitude (:attrs farside))) (catch Exception _ 7))
|
||||||
async? (and (number? magnitude) (> magnitude 1))
|
async? (and (number? magnitude) (> magnitude 1))
|
||||||
widget-name (safe-name (:name (:attrs property)) :sql)]
|
widget-name (safe-name (:name (:attrs property)) :sql)]
|
||||||
{:tag :div
|
{:tag :span
|
||||||
:attrs {:class "select-box" :farside farname :found (if farside "true" "false")}
|
:attrs {:class "select-box" :farside farname :found (if farside "true" "false")}
|
||||||
:content
|
:content
|
||||||
(apply
|
(apply
|
||||||
vector
|
vector
|
||||||
(remove
|
(remove
|
||||||
nil?
|
nil?
|
||||||
|
(flatten
|
||||||
(list
|
(list
|
||||||
(if
|
(if
|
||||||
async?
|
async?
|
||||||
|
(list
|
||||||
{:tag :input
|
{:tag :input
|
||||||
:attrs
|
:attrs
|
||||||
{:name (str widget-name "_search_box")
|
{:name (str widget-name "_search_box")
|
||||||
:onchange (str "$.getJSON(\"/auto/json/seach-strings-" (-> farside :attrs :name)
|
:onchange (str "$.getJSON(\"/auto/json/seach-strings-"
|
||||||
|
(-> farside :attrs :name)
|
||||||
"?"
|
"?"
|
||||||
(s/join (str "=\" + " widget-name "_search_box.text + \"&")
|
(s/join (str "=\" + " widget-name "_search_box.text + \"&")
|
||||||
(user-distinct-property-names farside))
|
(user-distinct-property-names farside))
|
||||||
|
@ -261,7 +263,8 @@
|
||||||
(first (key-names farside))
|
(first (key-names farside))
|
||||||
"\", [\""
|
"\", [\""
|
||||||
(s/join "\", \"" (user-distinct-property-names farside))
|
(s/join "\", \"" (user-distinct-property-names farside))
|
||||||
"\"], data);})")}})
|
"\"], data);})")}}
|
||||||
|
{:tag :br}))
|
||||||
{:tag :select
|
{:tag :select
|
||||||
:attrs (merge
|
:attrs (merge
|
||||||
{:id widget-name
|
{:id widget-name
|
||||||
|
@ -269,7 +272,7 @@
|
||||||
(if
|
(if
|
||||||
(= (:type (:attrs property)) "link")
|
(= (:type (:attrs property)) "link")
|
||||||
{:multiple "multiple"}))
|
{:multiple "multiple"}))
|
||||||
:content (apply vector (get-options property form entity application))})))}))
|
:content (apply vector (get-options property form entity application))}))))}))
|
||||||
|
|
||||||
|
|
||||||
(defn compose-if-member-of-tag
|
(defn compose-if-member-of-tag
|
||||||
|
@ -378,11 +381,9 @@
|
||||||
|
|
||||||
|
|
||||||
(defn compose-select-script-header [entity application]
|
(defn compose-select-script-header [entity application]
|
||||||
["{% block extra-head %}"
|
|
||||||
{:tag :script :attrs {:type "text/javascript"}
|
{:tag :script :attrs {:type "text/javascript"}
|
||||||
:content
|
:content
|
||||||
[(slurp "resources/js/select-widget-support.js")]}
|
[(slurp "resources/js/select-widget-support.js")]})
|
||||||
"{% endblock %}"])
|
|
||||||
|
|
||||||
|
|
||||||
(defn form-to-template
|
(defn form-to-template
|
||||||
|
@ -417,7 +418,7 @@
|
||||||
(delete-widget form entity application)))}]}}
|
(delete-widget form entity application)))}]}}
|
||||||
(if
|
(if
|
||||||
(some #(= "select" (widget-type % application)) (properties entity))
|
(some #(= "select" (widget-type % application)) (properties entity))
|
||||||
{:header (compose-select-script-header entity application)}
|
{:extra-head (compose-select-script-header entity application)}
|
||||||
{})))
|
{})))
|
||||||
|
|
||||||
|
|
||||||
|
@ -467,13 +468,15 @@
|
||||||
:content
|
:content
|
||||||
[{:tag :tr
|
[{:tag :tr
|
||||||
:content
|
:content
|
||||||
|
(conj
|
||||||
(apply
|
(apply
|
||||||
vector
|
vector
|
||||||
(map
|
(map
|
||||||
#(hash-map
|
#(hash-map
|
||||||
:content [(prompt %)]
|
:content [(prompt %)]
|
||||||
:tag :th)
|
:tag :th)
|
||||||
(children-with-tag list-spec :field)))}
|
(children-with-tag list-spec :field)))
|
||||||
|
{:tag :th :content [" "]})}
|
||||||
{:tag :tr
|
{:tag :tr
|
||||||
:content
|
:content
|
||||||
(apply
|
(apply
|
||||||
|
|
Loading…
Reference in a new issue