From d49b5729a000530cba851114f098b8c6a2fad4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 15 Aug 2021 19:44:14 +0200 Subject: Fix paginator buttons forgetting future clause. --- module/calp/html/view/search.scm | 28 ++++++++++++++++++++++++---- module/calp/server/routes.scm | 30 ++++++++++++++++-------------- 2 files changed, 40 insertions(+), 18 deletions(-) (limited to 'module') diff --git a/module/calp/html/view/search.scm b/module/calp/html/view/search.scm index fd5000df..c356baec 100644 --- a/module/calp/html/view/search.scm +++ b/module/calp/html/view/search.scm @@ -3,15 +3,25 @@ :use-module (vcomponent) :use-module (vcomponent search) :use-module ((ice-9 pretty-print) :select (pretty-print)) + :use-module ((web uri-query) :select (encode-query-parameters)) :use-module ((calp html components) :select (xhtml-doc include-css)) :use-module ((calp html vcomponent) :select (compact-event-list)) ) +;; Display the result of a search term, but doesn't do any searching +;; on its own. +;; +;; @var{errors} : #f or SXML object to display instead of search result +;; @var{has-query?} : Does search-term actually contain anything, or should +;; it be handled as a blank query? +;; @var{search-term} : What was searched, as an SEXP +;; @var{search-result} : The list of matched events +;; @var{page} : Which page we are on +;; @var{paginator} : A paginator object (define-public (search-result-page - errors - has-query? search-term search-result page paginator q=) + errors has-query? search-term search-result page paginator) (xhtml-doc (@ (lang sv)) (head (title "Search results") @@ -38,5 +48,15 @@ paginator (lambda (p) (if (= p page) `(span ,p) - `(a (@ (href "?" ,q= "&p=" ,p)) ,p))) - (lambda (p) `(a (@ (href "?" ,q= "&p=" ,p)) "»"))))))))) + `(a (@ (href + "?" + ,(encode-query-parameters + `((p . ,p) + (q . ,search-term))))) + ,p))) + (lambda (p) `(a (@ (href + "?" + ,(encode-query-parameters + `((p . ,p) + (q . ,search-term))))) + "»"))))))))) diff --git a/module/calp/server/routes.scm b/module/calp/server/routes.scm index 512e6ac5..95488fc9 100644 --- a/module/calp/server/routes.scm +++ b/module/calp/server/routes.scm @@ -363,18 +363,17 @@ (GET "/search" (q p onlyfuture) (define search-term - (if onlyfuture - `(and (date/-time<=? ,(current-datetime) (prop event 'DTSTART)) - ,(and=> q prepare-string)) - (and=> q prepare-string))) - - ;; keep original string for links below. Should guarantee that it's correct. - (define q= (if (not q) - "" (find (lambda (s) - (and (<= 2 (string-length s)) - (string=? "q=" (string-take s 2)))) - (string-split r:query #\&)))) - + (if (and q (not (string-null? q))) + (if onlyfuture + `(and (date/-time<=? ,(current-datetime) (prop event 'DTSTART)) + ,(and=> q prepare-string)) + (and=> q prepare-string)) + ;; NOTE This causes the paginator buttons to search for literally two quote marks, + ;; But oh well. + "")) + + ;; get-query-page handles paginator cache, meaning that + ;; a new one is only allocated when needed (define paginator (get-query-page search-term)) (define page (string->number (or p "0"))) @@ -395,7 +394,9 @@ (define location (build-relative-ref path: r:path ; host: r:host port: r:port - query: (format #f "~a&p=~a" q= page-number))) + query: (encode-query-parameters + `((p . ,page-number) + (q . ,search-term))))) (return (build-response code: 307 headers: `((location . ,location))))))) @@ -409,7 +410,8 @@ (sxml->xml (search-result-page error - q search-term search-result page paginator q=)))))) + (and=> q (negate string-null?)) + search-term search-result page paginator)))))) ;; NOTE this only handles files with extensions. Limited, but since this ;; is mostly for development, and something like nginx should be used in -- cgit v1.2.3