Searching lists works; paging lists still doesn't, but is closer.

This commit is contained in:
Simon Brooke 2018-07-15 21:03:13 +01:00
parent 7dfff9f9ee
commit 8d32850b8f
3 changed files with 74 additions and 77 deletions

View file

@ -140,7 +140,7 @@
(let [entity-name (safe-name (:name (:attrs entity)) :sql)
pretty-name (singularise entity-name)
query-name (str "search-strings-" entity-name)
signature ":? :1"
signature ":? :*"
properties (remove #(#{"link"}(:type (:attrs %))) (all-properties entity))]
(hash-map
(keyword query-name)
@ -168,12 +168,12 @@
string?
(map
#(str
"(if (:" (-> % :attrs :name) " params) \"OR "
(case (base-type % application)
"(if (:" (-> % :attrs :name) " params) (str \"OR "
(case (-> % :attrs :type)
("string" "text")
(str
(safe-name (-> % :attrs :name) :sql)
" LIKE '%:" (-> % :attrs :name) "%'")
" LIKE '%\" (:" (-> % :attrs :name) " params) \"%'")
("date" "time" "timestamp")
(str
(safe-name (-> % :attrs :name) :sql)
@ -181,12 +181,12 @@
"entity"
(str
(safe-name (-> % :attrs :name) :sql)
"_expanded LIKE '%:" (-> % :attrs :name) "%'")
"_expanded LIKE '%\" (:" (-> % :attrs :name) " params) \"%'")
(str
(safe-name (-> % :attrs :name) :sql)
" = :"
(-> % :attrs :name)))
"\")")
"\"))")
properties))))
(order-by-clause entity "lv_")
"--~ (if (:offset params) \"OFFSET :offset \")"

View file

@ -149,6 +149,8 @@
'some
(set (map #(keyword (-> % :attrs :name)) (all-properties e)))
(list 'keys 'params))
(list 'do
(list (symbol "log/debug") (list (symbol (str "db/search-strings-" (:name (:attrs e)) "-sqlvec")) 'params))
(list
'support/do-or-log-error
(list
@ -162,7 +164,9 @@
:error-return {:warnings [(str
"Error while searching "
(singularise (:name (:attrs e)))
" records")]})
" records")]}))
(list 'do
(list (symbol "log/debug") (list (symbol (str "db/list-" (:name (:attrs e)) "-sqlvec")) 'params))
(list
'support/do-or-log-error
(list
@ -178,7 +182,7 @@
:error-return {:warnings [(str
"Error while fetching "
(singularise (:name (:attrs e)))
" records")]})))
" records")]}))))
(list 'if
(list :warnings 'records)
'records

View file

@ -665,11 +665,7 @@
"time" "time"
"text")
base-name (:property (:attrs field))
search-name (safe-name
(if
(= (:type (:attrs property)) "entity")
(str base-name "_expanded") base-name)
:sql)]
search-name (safe-name base-name :sql)]
(hash-map
:tag :th
:content
@ -728,18 +724,10 @@
{:back-links
{:tag :div
:content
[
{:tag :div :attrs {:class "back-link-container"}
[{:tag :div :attrs {:class "back-link-container"}
:content
["{% ifequal params.offset \"0\" %}"
{:tag :a
:attrs {:id "back-link" :class "back-link" :href "{{servlet-context}}/admin"}
:content ["Back"]}
"{% else %}"
{:tag :a :attrs {:id "prev-selector" :class "back-link"}
:content ["Previous"]}
"{% endifunequal %}"]}
]}
[{:tag :a :attrs {:id "prev-selector" :class "back-link"}
:content ["Previous"]}]}]}
:big-links
{:tag :div
:content
@ -765,8 +753,8 @@
:method "POST"}
:content
[(csrf-widget)
{:tag :input :attrs {:id "offset" :type "hidden" :value "{{params.offset|default:0}}"}}
{:tag :input :attrs {:id "limit" :type "hidden" :value "{{params.limit|default:50}}"}}
{:tag :input :attrs {:id "offset" :name "offset" :type "hidden" :value "{{params.offset|default:0}}"}}
{:tag :input :attrs {:id "limit" :name "limit" :type "hidden" :value "{{params.limit|default:50}}"}}
{:tag :table
:attrs {:caption (:name (:attrs entity))}
:content
@ -782,13 +770,18 @@
ow.value='0';
});
{% ifunequal params.offset \"0\" %}
document.getElementById('prev-selector').addEventListener('click', function () {
var prevSelector = document.getElementById('prev-selector');
if (prevSelector != null) {
prevSelector.addEventListener('click', function () {
if (parseInt(ow.value)===0) {
window.location = '{{servlet-context}}/admin';
} else {
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 () {
ow.value=(parseInt(ow.value)+parseInt(lw.value));