summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/serve.fnl26
1 files changed, 20 insertions, 6 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl
index cabbee2..a0c5fc4 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -14,10 +14,6 @@
(local cache (require :lib.cache))
(local {: must : measure} (require :lib.utils))
-(local ozchai (require :parser.ozchai))
-(local ipuer (require :parser.ipuer))
-(local artoftea (require :parser.artoftea))
-
(when _G.unpack
(tset table :unpack _G.unpack))
@@ -81,6 +77,7 @@
(fn collect-form [params category]
{:query (str.trim (or (get-query-string params "query") ""))
:tags (filter #(~= "" $2) (or params.tags [category]))
+ :site (str.trim (or (get-query-string params "site") ""))
:min-price (get-query-number params "min-price")
:max-price (get-query-number params "max-price")
:price-per (= "on" (get-query-string params "price-per"))})
@@ -89,6 +86,7 @@
(and
(= "" form.query)
(= (# form.tags) 0)
+ (= "" form.site)
(not form.min-price)
(not form.max-price)
;; price-per is intentionally left out since it must not trigger search
@@ -108,6 +106,9 @@
form.tags))
"&"))
"")
+ (if (not (str.empty? form.site))
+ (.. "&site=" form.site)
+ "")
(if (and form.min-price (< 0 form.min-price))
(.. "&min-price=" (tostring form.min-price))
"")
@@ -146,7 +147,7 @@
"SELECT title FROM tags ORDER BY creation_time"
[]))))
-(fn query-products [{: query : tags : min-price : max-price : price-per} page]
+(fn query-products [{: query : tags : min-price : max-price : price-per : site} page]
(local tags (or tags []))
(var where-conds [])
@@ -166,6 +167,9 @@
(.. q "*")))
(str.split query " "))
" AND ")))
+ (when (not (str.empty? site))
+ (table.insert where-conds "products.site = ?")
+ (table.insert where-vars site))
(when (and min-price (< 0 min-price))
(if price-per
(table.insert where-conds "products.price_per >= ?")
@@ -352,6 +356,16 @@
[:input {:type :checkbox :id "price-per" :name "price-per"
:checked (if form.price-per "checked" nil)}]
[:label {:for "price-per"} "цена за грамм"]]
+ [:div {:class "form-tags"}
+ [:select {:class "form-tag" :name "site"}
+ [:option {:value ""} "~ Сайт ~"]
+ (table.unpack
+ (map
+ (fn [_ val]
+ [:option {:value val
+ :selected (if (= form.site val) "selected" nil)}
+ val])
+ [:ozchai :clubcha :ipuer :artoftea :chaekshop]))]]
[:button {:type :submit} "Искать"]]
paginator]])
@@ -406,7 +420,7 @@
(fn root-handler [{: path : query}]
(local cache-key (.. "page:" path "?" (serialize-query query)))
(local cached (cache.get db cache-key))
- (if cached
+ (if false
(values 200 {:content-type "text/html"} cached)
(do
(fn respond [query category]