Added drill-down in lists.
This commit is contained in:
parent
e879b8b628
commit
40fc3a99cc
|
@ -281,7 +281,8 @@
|
||||||
" ||', '|| "
|
" ||', '|| "
|
||||||
(compose-convenience-entity-field field entity application))
|
(compose-convenience-entity-field field entity application))
|
||||||
" AS "
|
" AS "
|
||||||
(field-name field)))
|
(field-name field)
|
||||||
|
"_expanded"))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-convenience-view
|
(defn emit-convenience-view
|
||||||
|
@ -290,59 +291,62 @@
|
||||||
[entity application]
|
[entity application]
|
||||||
(let [view-name (safe-name (str "lv_" (:table (:attrs entity))) :sql)
|
(let [view-name (safe-name (str "lv_" (:table (:attrs entity))) :sql)
|
||||||
entity-fields (filter
|
entity-fields (filter
|
||||||
#(= (:type (:attrs %)) "entity")
|
#(= (:type (:attrs %)) "entity")
|
||||||
(properties entity))]
|
(properties entity))]
|
||||||
(s/join
|
(s/join
|
||||||
"\n"
|
"\n"
|
||||||
(remove
|
(remove
|
||||||
nil?
|
nil?
|
||||||
(flatten
|
(flatten
|
||||||
(list
|
(list
|
||||||
(emit-header
|
(emit-header
|
||||||
"--"
|
"--"
|
||||||
(str "convenience view " view-name " of entity " (:name (:attrs entity)) " for lists, et cetera"))
|
(str "convenience view " view-name " of entity " (:name (:attrs entity)) " for lists, et cetera"))
|
||||||
(s/join
|
(s/join
|
||||||
" "
|
" "
|
||||||
(list "CREATE VIEW" view-name "AS"))
|
(list "CREATE VIEW" view-name "AS"))
|
||||||
(str
|
(str
|
||||||
"SELECT "
|
"SELECT "
|
||||||
(s/join
|
(s/join
|
||||||
",\n\t"
|
",\n\t"
|
||||||
(map
|
(flatten
|
||||||
#(if
|
(map
|
||||||
(= (:type (:attrs %)) "entity")
|
#(if
|
||||||
(emit-convenience-entity-field % entity application)
|
(= (:type (:attrs %)) "entity")
|
||||||
(str (safe-name entity) "." (field-name %)))
|
(list
|
||||||
(filter
|
(emit-convenience-entity-field % entity application)
|
||||||
#(not (= (:type (:attrs %)) "link"))
|
(str (safe-name entity) "." (field-name %)))
|
||||||
(all-properties entity) ))))
|
(str (safe-name entity) "." (field-name %)))
|
||||||
(str
|
(filter
|
||||||
"FROM " (s/join ", " (set (compose-convenience-view-select-list entity application true))))
|
#(not (= (:type (:attrs %)) "link"))
|
||||||
(if
|
(all-properties entity) )))))
|
||||||
(not (empty? entity-fields))
|
(str
|
||||||
(str
|
"FROM " (s/join ", " (set (compose-convenience-view-select-list entity application true))))
|
||||||
"WHERE "
|
(if
|
||||||
(s/join
|
(not (empty? entity-fields))
|
||||||
"\n\tAND "
|
(str
|
||||||
(map
|
"WHERE "
|
||||||
(fn [f]
|
(s/join
|
||||||
(let
|
"\n\tAND "
|
||||||
[farside (child
|
(map
|
||||||
application
|
(fn [f]
|
||||||
#(and
|
(let
|
||||||
(entity? %)
|
[farside (child
|
||||||
(= (:name (:attrs %)) (:entity (:attrs f)))))]
|
application
|
||||||
(str
|
#(and
|
||||||
(safe-name (:table (:attrs entity)) :sql)
|
(entity? %)
|
||||||
"."
|
(= (:name (:attrs %)) (:entity (:attrs f)))))]
|
||||||
(field-name f)
|
(str
|
||||||
" = "
|
(safe-name (:table (:attrs entity)) :sql)
|
||||||
(safe-name (:table (:attrs farside)) :sql)
|
"."
|
||||||
"."
|
(field-name f)
|
||||||
(safe-name (first (key-names farside)) :sql))))
|
" = "
|
||||||
entity-fields))))
|
(safe-name (:table (:attrs farside)) :sql)
|
||||||
";"
|
"."
|
||||||
(emit-permissions-grant view-name :SELECT (permissions entity application))))))))
|
(safe-name (first (key-names farside)) :sql))))
|
||||||
|
entity-fields))))
|
||||||
|
";"
|
||||||
|
(emit-permissions-grant view-name :SELECT (permissions entity application))))))))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-referential-integrity-link
|
(defn emit-referential-integrity-link
|
||||||
|
|
|
@ -362,6 +362,7 @@
|
||||||
taken from this `application`. If `page` is nil, generate a default page
|
taken from this `application`. If `page` is nil, generate a default page
|
||||||
template for the entity."
|
template for the entity."
|
||||||
[page entity application]
|
[page entity application]
|
||||||
|
;; TODO
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -416,7 +417,21 @@
|
||||||
:value "Search"}}]})))}]})
|
:value "Search"}}]})))}]})
|
||||||
|
|
||||||
|
|
||||||
(defn- list-tbody
|
(defn edit-link
|
||||||
|
[entity application parameters]
|
||||||
|
(str
|
||||||
|
(editor-name entity application)
|
||||||
|
"?"
|
||||||
|
(s/join
|
||||||
|
"&"
|
||||||
|
(map
|
||||||
|
#(let [n (:name (:attrs %1))]
|
||||||
|
(str n "={{ record." %2 " }}"))
|
||||||
|
(key-names entity)
|
||||||
|
parameters))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn list-tbody
|
||||||
"Return a table body element for the list view for this `list-spec` of this `entity` within
|
"Return a table body element for the list view for this `list-spec` of this `entity` within
|
||||||
this `application`."
|
this `application`."
|
||||||
[list-spec entity application]
|
[list-spec entity application]
|
||||||
|
@ -430,22 +445,26 @@
|
||||||
(concat
|
(concat
|
||||||
(map
|
(map
|
||||||
(fn [field]
|
(fn [field]
|
||||||
{:tag :td :content [(str "{{ record." (:property (:attrs field)) " }}")]})
|
{:tag :td :content
|
||||||
|
(let
|
||||||
|
[p (first (filter #(= (:name (:attrs %)) (:property (:attrs field))) (all-properties entity)))
|
||||||
|
e (first
|
||||||
|
(filter
|
||||||
|
#(= (:name (:attrs %)) (:entity (:attrs p)))
|
||||||
|
(children-with-tag application :entity)))
|
||||||
|
c (str "{{ record." (:property (:attrs field)) " }}")]
|
||||||
|
(if
|
||||||
|
(= (:type (:attrs p)) "entity")
|
||||||
|
[{:tag :a
|
||||||
|
:attrs {:href (edit-link e application (list (:name (:attrs p))))}
|
||||||
|
:content [(str "{{ record." (:property (:attrs field)) "_expanded }}")]}]
|
||||||
|
[c]))})
|
||||||
(fields list-spec))
|
(fields list-spec))
|
||||||
[{:tag :td
|
[{:tag :td
|
||||||
:content
|
:content
|
||||||
[{:tag :a
|
[{:tag :a
|
||||||
:attrs
|
:attrs
|
||||||
{:href
|
{:href (edit-link entity application (key-names entity))}
|
||||||
(str
|
|
||||||
(editor-name entity application)
|
|
||||||
"?"
|
|
||||||
(s/join
|
|
||||||
"&"
|
|
||||||
(map
|
|
||||||
#(let [n (:name (:attrs %))]
|
|
||||||
(str n "={{ record." n "}}"))
|
|
||||||
(children (first (filter #(= (:tag %) :key) (children entity)))))))}
|
|
||||||
:content ["View"]}]}]))}
|
:content ["View"]}]}]))}
|
||||||
"{% endfor %}"]})
|
"{% endfor %}"]})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue