diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/fetch.fnl | 8 | ||||
| -rw-r--r-- | bin/serve.fnl | 51 |
2 files changed, 46 insertions, 13 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index 0551d76..a5f8d63 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -33,6 +33,7 @@ image TEXT NOT NULL, price REAL NOT NULL, weight REAL NOT NULL, + volume REAL NOT NULL, price_per REAL NOT NULL, archived BOOL NOT NULL, creation_time DATETIME NOT NULL @@ -102,7 +103,7 @@ (local sql (.. "INSERT OR REPLACE INTO products VALUES " (array.join - (map (fn [_ _] "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + (map (fn [_ _] "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") products) ", "))) (local creation-time (now)) @@ -118,6 +119,7 @@ (or product.image "") (or product.price 0) (or product.weight 0) + (or product.volume 0) (or product.price-per 0) (or product.archived false) creation-time])) @@ -152,8 +154,8 @@ ;; replace with with-tx (local tx (must (luna.db.begin db))) (must (luna.db.exec-tx tx "DELETE FROM product_tags;" [])) -(each [_ parser (pairs [ozchai gorkovchay chaekshop clubcha artoftea ipuer - moychay])] +(each [_ parser (pairs [ozchai clubcha ipuer artoftea chaekshop moychay + gorkovchay])] (store-products tx (parser.products))) (cache.clear-tx tx "page:") (must (luna.db.commit tx)) diff --git a/bin/serve.fnl b/bin/serve.fnl index 68dea35..c22becb 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -94,6 +94,8 @@ :sort (or (query-string params "sort") "") :min-price (query-number params "min-price") :max-price (query-number params "max-price") + :min-volume (query-number params "min-volume") + :max-volume (query-number params "max-volume") :price-per (= "on" (query-string params "price-per"))}) (fn form-empty? [form] @@ -103,6 +105,8 @@ (= "" form.site) (not form.min-price) (not form.max-price) + (not form.min-volume) + (not form.max-volume) ;; price-per and sort are intentionally left out since they must not ;; trigger search by itself )) @@ -132,6 +136,12 @@ (if form.price-per "&price-per=on" "") + (if (and form.min-volume (< 0 form.min-volume)) + (.. "&min-volume=" (tostring form.min-volume)) + "") + (if (and form.max-volume (< 0 form.max-volume)) + (.. "&max-volume=" (tostring form.max-volume)) + "") (if form.sort (.. "&sort=" form.sort) ""))) @@ -205,7 +215,8 @@ LIMIT 1" [])) 1 1)) -(fn query-products [{: query : tags : min-price : max-price : price-per : site : sort} page] +(fn query-products [{: query : tags : min-price : max-price : price-per + : min-volume : max-volume : site : sort} page] (local tags (or tags [])) (local where-conds []) (local sort-criteria []) @@ -240,6 +251,14 @@ (table.insert where-conds "products.price_per <= ?") (table.insert where-conds "products.price <= ?")) (table.insert query-args max-price)) + (when (and min-volume (< 0 min-volume)) + (table.insert where-conds "products.volume >= ?") + (table.insert query-args min-volume)) + (when (and max-volume (< 0 max-volume)) + (table.insert where-conds + "(products.volume <= ? AND products.volume != 0)") + (table.insert query-args max-volume)) + (local where-sql (if (< 0 (# where-conds)) (.. "AND " (array.join where-conds "\nAND ")) @@ -396,6 +415,8 @@ (item "/teaware" "Посуда")]) (fn aside-template [form path aside-content] + (local teaware? (array.contains form.tags "Посуда")) + [:aside {:class "aside"} [:div {:class "aside-content"} (if (or (not (form-empty? form)) (~= path "/")) @@ -422,15 +443,24 @@ "selected" nil)} tag]) (all-tags)))]] - [:div {:class "form-price"} - [:input {:type :number :name :min-price :min "1" + [:div {:class "form-range"} + [:input {:type :number :name "min-price" :min "1" :placeholder "От ₽" :value (tostring form.min-price)}] - [:input {:type :number :name :max-price :min "1" + [:input {:type :number :name "max-price" :min "1" :placeholder "До ₽" :value (tostring form.max-price)}]] - [:div {:class "form-price-per"} - [:input {:type :checkbox :id "price-per" :name "price-per" - :checked (if form.price-per "checked" nil)}] - [:label {:for "price-per"} "цена за грамм"]] + (if teaware? + [:div {:class "form-range"} + [:input {:type :number :name "min-volume" :min "1" + :placeholder "От мл" :value (tostring form.min-volume)}] + [:input {:type :number :name "max-volume" :min "1" + :placeholder "До мл" :value (tostring form.max-volume)}]] + "") + (if (not teaware?) + [:div {:class "form-price-per"} + [:input {:type :checkbox :id "price-per" :name "price-per" + :checked (if form.price-per "checked" nil)}] + [:label {:for "price-per"} "цена за грамм"]] + "") [:div {} [:select {:name "site"} [:option {:value ""} "~ Сайт ~"] @@ -440,7 +470,8 @@ [:option {:value val :selected (if (= form.site val) "selected" nil)} (. (require (.. "parser." val)) :title)]) - [:ozchai :clubcha :ipuer :artoftea :chaekshop :moychay]))]] + [:ozchai :clubcha :ipuer :artoftea :chaekshop :moychay + :gorkovchay]))]] [:div {} [:select {:name "sort"} [:option {:value ""} "~ Порядок ~"] @@ -586,7 +617,7 @@ (.. "<!DOCTYPE html>\n" (html.render (base-template form path [:div {} "Страница не найдена!"]) - true))))))) + true))))))) (fn robots-handler [] (values 200 {:content-type "text/plain"} |
