Work on list paging - not complete, but promising
This commit is contained in:
parent
48c8b6445b
commit
96c273ee06
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -11,3 +11,7 @@ pom.xml.asc
|
||||||
.hg/
|
.hg/
|
||||||
|
|
||||||
resources/auto/
|
resources/auto/
|
||||||
|
|
||||||
|
generated/resources/sql/
|
||||||
|
|
||||||
|
generated/src/clj/youyesyet/routes/
|
||||||
|
|
|
@ -69,7 +69,9 @@
|
||||||
(vector 'r)
|
(vector 'r)
|
||||||
(list 'let (vector
|
(list 'let (vector
|
||||||
'p
|
'p
|
||||||
(list 'support/massage-params (list :params 'r)))
|
(list 'merge
|
||||||
|
{:offset 0 :limit 25}
|
||||||
|
(list 'support/massage-params (list :params 'r))))
|
||||||
;; TODO: we must take key params out of just params,
|
;; 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
|
;; 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
|
;; load the form in the first place, but just accepting values of other params would
|
||||||
|
@ -86,6 +88,8 @@
|
||||||
(reduce
|
(reduce
|
||||||
merge
|
merge
|
||||||
{:record
|
{:record
|
||||||
|
;; TODO: this breaks. We need to check for the presence of the
|
||||||
|
;; actual key in the params.
|
||||||
(list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) []
|
(list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) []
|
||||||
(list
|
(list
|
||||||
(symbol
|
(symbol
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
{:tag :div
|
{:tag :div
|
||||||
:attrs {:class "big-link-container"}
|
:attrs {:class "big-link-container"}
|
||||||
:content
|
:content
|
||||||
[{:tag :a :attrs {:href url}
|
[{:tag :a :attrs {:href url :class "big-link"}
|
||||||
:content (if
|
:content (if
|
||||||
(vector? content)
|
(vector? content)
|
||||||
content
|
content
|
||||||
|
@ -62,22 +62,24 @@
|
||||||
([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]
|
||||||
(let [content (:content
|
(let [content
|
||||||
(first
|
(:content
|
||||||
(or (children-with-tag spec k)
|
(first
|
||||||
(children-with-tag entity k)
|
(or (children-with-tag spec k)
|
||||||
(children-with-tag
|
(children-with-tag entity k)
|
||||||
(first
|
(children-with-tag
|
||||||
(children-with-tag application :content))
|
(child-with-tag application :content)
|
||||||
k))))]
|
k))))]
|
||||||
(if
|
(if
|
||||||
content
|
content
|
||||||
(list
|
(flatten
|
||||||
|
(list
|
||||||
(str "{% block " (name k) " %}")
|
(str "{% block " (name k) " %}")
|
||||||
(map
|
(doall
|
||||||
|
(map
|
||||||
#(with-out-str (x/emit-element %))
|
#(with-out-str (x/emit-element %))
|
||||||
content)
|
content))
|
||||||
"{% endblock %}")))))
|
"{% endblock %}"))))))
|
||||||
|
|
||||||
|
|
||||||
(defn file-header
|
(defn file-header
|
||||||
|
@ -448,7 +450,7 @@
|
||||||
:content
|
:content
|
||||||
[{:tag :input
|
[{:tag :input
|
||||||
:attrs {:type "submit"
|
:attrs {:type "submit"
|
||||||
:id "search"
|
:id "search-widget"
|
||||||
:value "Search"}}]})))}]})
|
:value "Search"}}]})))}]})
|
||||||
|
|
||||||
|
|
||||||
|
@ -504,35 +506,6 @@
|
||||||
"{% endfor %}"]})
|
"{% endfor %}"]})
|
||||||
|
|
||||||
|
|
||||||
(defn- list-page-control
|
|
||||||
"What this needs to do is emit an HTML control which, when selected, requests the
|
|
||||||
next or previous page keeping the same search parameters; so it essentially needs
|
|
||||||
to be a submit button, not a link."
|
|
||||||
[forward?]
|
|
||||||
{:tag :div
|
|
||||||
:attrs {:class (if forward? "big-link-container" "back-link-container")}
|
|
||||||
:content
|
|
||||||
[{:tag :input
|
|
||||||
:attrs {:id "page"
|
|
||||||
:name "page"
|
|
||||||
:disabled (if
|
|
||||||
forward?
|
|
||||||
false
|
|
||||||
"{% ifequal offset 0 %} false {% else %} true {% endifequal %}")
|
|
||||||
;; TODO: real thought needs to happen on doing i18n for this!
|
|
||||||
:value (if forward? "Next" "Previous")}}]})
|
|
||||||
|
|
||||||
|
|
||||||
(defn- list-tfoot
|
|
||||||
"Return a table footer element for the list view for this `list-spec` of this `entity` within
|
|
||||||
this `application`."
|
|
||||||
[list-spec entity application]
|
|
||||||
{:tag :tfoot
|
|
||||||
:content
|
|
||||||
[(list-page-control false)
|
|
||||||
(list-page-control true)]})
|
|
||||||
|
|
||||||
|
|
||||||
(defn list-to-template
|
(defn list-to-template
|
||||||
"Generate a template as specified by this `list` element for this `entity`,
|
"Generate a template as specified by this `list` element for this `entity`,
|
||||||
taken from this `application`. If `list` is nill, generate a default list
|
taken from this `application`. If `list` is nill, generate a default list
|
||||||
|
@ -544,7 +517,22 @@
|
||||||
(:name (:attrs entity))
|
(:name (:attrs entity))
|
||||||
"-"
|
"-"
|
||||||
(:name (:attrs list-spec)))]
|
(:name (:attrs list-spec)))]
|
||||||
{:big-links
|
{:back-links
|
||||||
|
{:tag :div
|
||||||
|
:content
|
||||||
|
[
|
||||||
|
{:tag :div :attrs {:class "back-link-container"}
|
||||||
|
:content
|
||||||
|
["{% ifunequal offset 0 %}"
|
||||||
|
{:tag :a :attrs {:id "prev-selector" :class "back-link"}
|
||||||
|
:content ["Previous"]}
|
||||||
|
"{% else %}"
|
||||||
|
{:tag :a
|
||||||
|
:attrs {:id "back-link" :class "back-link" :href "{{servlet-context}}/admin"}
|
||||||
|
:content ["Back"]}
|
||||||
|
"{% endifunequal %}"]}
|
||||||
|
]}
|
||||||
|
:big-links
|
||||||
{:tag :div
|
{:tag :div
|
||||||
:content
|
:content
|
||||||
[{:tag :div :attrs {:class "big-link-container"}
|
[{:tag :div :attrs {:class "big-link-container"}
|
||||||
|
@ -558,25 +546,36 @@
|
||||||
:action (str "{{servlet-context}}/" form-name)
|
:action (str "{{servlet-context}}/" form-name)
|
||||||
:method "POST"}
|
:method "POST"}
|
||||||
:content
|
:content
|
||||||
[
|
[(csrf-widget)
|
||||||
(csrf-widget)
|
{:tag :input :attrs {:id "offset" :type "hidden" :value "{{params.offset|default:0}}"}}
|
||||||
{:tag :input :attrs {:id "offset" :type "hidden" :value "{{offset|0}}"}}
|
{:tag :input :attrs {:id "limit" :type "hidden" :value "{{params.limit|default:50}}"}}
|
||||||
{:tag :input :attrs {:id "limit" :type "hidden" :value "{{limit|50}}"}}
|
|
||||||
(big-link (str "Add a new " (pretty-name entity)) (editor-name entity application))
|
|
||||||
{:tag :table
|
{:tag :table
|
||||||
:attrs {:caption (:name (:attrs entity))}
|
:attrs {:caption (:name (:attrs entity))}
|
||||||
:content
|
:content
|
||||||
[(list-thead list-spec entity application)
|
[(list-thead list-spec entity application)
|
||||||
(list-tbody list-spec entity application)
|
(list-tbody list-spec entity application)
|
||||||
(list-tfoot list-spec entity application)]}]}
|
]}]}
|
||||||
:extra-script
|
:extra-script
|
||||||
(str "var form = document.getElementById('" form-name "');
|
(str "
|
||||||
|
var form = document.getElementById('" form-name "');
|
||||||
var ow = document.getElementById('offset');
|
var ow = document.getElementById('offset');
|
||||||
var lw = document.getElementById('limit');
|
var lw = document.getElementById('limit');
|
||||||
|
form.addEventListener('submit', function() {
|
||||||
|
ow.value='0';
|
||||||
|
});
|
||||||
|
|
||||||
|
{% ifunequal offset 0 %}
|
||||||
|
document.getElementById('prev-selector').addEventListener('click', function () {
|
||||||
|
ow.value=(parseInt(ow.value)-parseInt(lw.value));
|
||||||
|
console.log('Updated offset to ' + ow.value);
|
||||||
|
form.submit();
|
||||||
|
});
|
||||||
|
{% endifunequal %}
|
||||||
|
|
||||||
document.getElementById('next-selector').addEventListener('click', function () {
|
document.getElementById('next-selector').addEventListener('click', function () {
|
||||||
ow.text=(parseInt(ow.text)+parseInt(lw.text));
|
ow.value=(parseInt(ow.value)+parseInt(lw.value));
|
||||||
//form.submit();
|
console.log('Updated offset to ' + ow.value);
|
||||||
|
form.submit();
|
||||||
});")}))
|
});")}))
|
||||||
|
|
||||||
|
|
||||||
|
@ -621,15 +620,16 @@
|
||||||
(let
|
(let
|
||||||
[first-class-entities
|
[first-class-entities
|
||||||
(sort-by
|
(sort-by
|
||||||
#(:name (:attrs %))
|
#(:name (:attrs %))
|
||||||
(filter
|
(filter
|
||||||
#(children-with-tag % :list)
|
#(children-with-tag % :list)
|
||||||
(children-with-tag application :entity)))]
|
(children-with-tag application :entity)))]
|
||||||
{:content
|
{:application-index
|
||||||
{:tag :dl
|
{:content
|
||||||
:attrs {:class "index"}
|
{:tag :dl
|
||||||
:content
|
:attrs {:class "index"}
|
||||||
(apply
|
:content
|
||||||
|
(apply
|
||||||
vector
|
vector
|
||||||
(interleave
|
(interleave
|
||||||
(map
|
(map
|
||||||
|
@ -651,60 +651,55 @@
|
||||||
:tag :p
|
:tag :p
|
||||||
:content (:content d)))
|
:content (:content d)))
|
||||||
(children-with-tag % :documentation))))
|
(children-with-tag % :documentation))))
|
||||||
first-class-entities)))}}))
|
first-class-entities)))}}}))
|
||||||
|
|
||||||
|
|
||||||
(defn write-template-file
|
(defn write-template-file
|
||||||
[filename template application]
|
[filename template application]
|
||||||
(if
|
(let [filepath (str *output-path* "resources/templates/auto/" filename)]
|
||||||
template
|
(if
|
||||||
(try
|
template
|
||||||
(spit
|
(try
|
||||||
(str *output-path* filename)
|
(do
|
||||||
(s/join
|
(spit
|
||||||
"\n"
|
filepath
|
||||||
(flatten
|
(s/join
|
||||||
(list
|
|
||||||
(file-header filename application)
|
|
||||||
(doall
|
|
||||||
(map
|
|
||||||
#(let [content (template %)]
|
|
||||||
(list
|
|
||||||
(str "{% block " (name %) " %}")
|
|
||||||
(cond (string? content)
|
|
||||||
content
|
|
||||||
(map? content)
|
|
||||||
(with-out-str
|
|
||||||
(x/emit-element content))
|
|
||||||
true
|
|
||||||
(str "<!-- don't know what to do with '" content "' -->"))
|
|
||||||
"{% endblock %}")
|
|
||||||
(keys template))))
|
|
||||||
(file-footer filename application)))))
|
|
||||||
(catch Exception any
|
|
||||||
(spit
|
|
||||||
filepath
|
|
||||||
(s/join
|
|
||||||
"\n"
|
"\n"
|
||||||
(list
|
(flatten
|
||||||
|
(list
|
||||||
(file-header filename application)
|
(file-header filename application)
|
||||||
(with-out-str
|
(doall
|
||||||
(x/emit-element template))
|
(map
|
||||||
(file-footer filename application))))
|
#(let [content (template %)]
|
||||||
(if (> *verbosity* 0) (println "\tGenerated " filepath))
|
(list
|
||||||
|
(str "{% block " (name %) " %}")
|
||||||
|
(cond (string? content)
|
||||||
|
content
|
||||||
|
(map? content)
|
||||||
|
(with-out-str
|
||||||
|
(x/emit-element content))
|
||||||
|
true
|
||||||
|
(str "<!-- don't know what to do with '" content "' -->"))
|
||||||
|
"{% endblock %}"))
|
||||||
|
(keys template)))
|
||||||
|
(file-footer filename application)))))
|
||||||
|
(if (> *verbosity* 0) (println "\tGenerated " filepath)))
|
||||||
(catch Exception any
|
(catch Exception any
|
||||||
(let [report (str
|
(let [report (str
|
||||||
"ERROR: Exception "
|
"ERROR: Exception "
|
||||||
(.getName (.getClass any))
|
(.getName (.getClass any))
|
||||||
(.getMessage any)
|
(.getMessage any)
|
||||||
" while printing "
|
" while printing "
|
||||||
filename)]
|
filepath)]
|
||||||
(spit
|
(try
|
||||||
filepath
|
(spit
|
||||||
(with-out-str
|
filepath
|
||||||
(println (str "<!-- " report "-->"))
|
(with-out-str
|
||||||
(p/pprint template)))
|
(println (str "<!-- " report "-->"))
|
||||||
(println report)))))
|
(p/pprint template)))
|
||||||
|
(catch Exception _ nil))
|
||||||
|
(println report)
|
||||||
|
(throw any)))))
|
||||||
(str filepath)))
|
(str filepath)))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue