ccount modal
This commit is contained in:
@@ -27,6 +27,16 @@
|
||||
o))
|
||||
oob)))})
|
||||
|
||||
(defn modal-response [hiccup & {:as opts}]
|
||||
(apply html-response
|
||||
(into
|
||||
[hiccup]
|
||||
(mapcat identity
|
||||
(-> opts
|
||||
(assoc-in [:headers "hx-trigger"] "modalopen")
|
||||
(assoc-in [:headers "hx-retarget"] "#modal-content")
|
||||
(assoc-in [:headers "hx-reswap"] "innerHTML"))))))
|
||||
|
||||
(defn wrap-error-response [handler]
|
||||
(fn [request]
|
||||
(try
|
||||
@@ -105,8 +115,11 @@
|
||||
|
||||
(def temp-id (mc/schema [:string {:min 1}]))
|
||||
(def money (mc/schema [:double]))
|
||||
(def percentage (mc/schema [:double {:decode/arbitrary (fn [x] (some-> x (* 0.01)))
|
||||
:max 1.0
|
||||
(def percentage (mc/schema [:double {:decode/string {:enter (fn [x]
|
||||
(if (and (string? x) (re-find #"^\d+(\.\d+)?$" x))
|
||||
(-> x (Double/parseDouble) (* 0.01))
|
||||
x))}
|
||||
:max 1.0
|
||||
:error/message "1-100"}]))
|
||||
|
||||
(def regex (mc/schema [:fn {:error/message "not a regex"}
|
||||
@@ -124,13 +137,7 @@
|
||||
x
|
||||
(into []
|
||||
(for [[k v] (sort-by (comp #(Long/parseLong %) name first) x)]
|
||||
v
|
||||
#_(assoc v :db/id (cond (and (string? k) (re-find #"^\d+$" k))
|
||||
(Long/parseLong k)
|
||||
(keyword? k)
|
||||
(name k)
|
||||
:else
|
||||
k))))))})
|
||||
v))))})
|
||||
|
||||
(defn many-entity [params & keys]
|
||||
(mc/schema
|
||||
@@ -174,6 +181,16 @@
|
||||
(mt2/transformer {:name :arbitrary})
|
||||
mt2/default-value-transformer))
|
||||
|
||||
(defn strip [s]
|
||||
(cond (and (string? s) (str/blank? s))
|
||||
nil
|
||||
|
||||
(string? s)
|
||||
(str/trim s)
|
||||
|
||||
:else
|
||||
s))
|
||||
|
||||
(defn wrap-schema-decode [handler & {:keys [form-schema query-schema route-schema params-schema]}]
|
||||
(fn [{:keys [form-params query-params params] :as request}]
|
||||
(let [request (try
|
||||
@@ -207,7 +224,6 @@
|
||||
main-transformer)))
|
||||
(catch Exception e
|
||||
(alog/warn ::validation-error :error e)
|
||||
|
||||
(throw (ex-info (->> (-> e
|
||||
(ex-data )
|
||||
:data
|
||||
@@ -251,17 +267,6 @@
|
||||
|
||||
|
||||
|
||||
#_(defn namespaceize-decoder [n]
|
||||
{:exit (fn [m]
|
||||
(when m
|
||||
(reduce
|
||||
(fn [m [k v]]
|
||||
(if (= k "id")
|
||||
(assoc m :db/id v)
|
||||
(assoc m (keyword n (name k)) v)))
|
||||
m
|
||||
m)))})
|
||||
|
||||
|
||||
(defn wrap-form-4xx [handler]
|
||||
(fn [request]
|
||||
@@ -274,17 +279,6 @@
|
||||
(html-response [:span.error-content.text-red-500 (:message &throw-context)]
|
||||
:status 400)))))
|
||||
|
||||
(defn assoc-errors-into-meta [entity errors]
|
||||
(reduce
|
||||
(fn add-error [entity {:keys [path message] :as se}]
|
||||
(if (= (count path) 1)
|
||||
(with-meta entity (assoc (meta entity) (last path) {:errors message}))
|
||||
|
||||
(update-in entity (butlast path)
|
||||
(fn [terminal]
|
||||
(with-meta terminal (assoc (meta terminal) (last path) {:errors message}))))))
|
||||
entity
|
||||
errors))
|
||||
|
||||
(defn wrap-form-4xx-2 [handler form-handler]
|
||||
(fn [request]
|
||||
|
||||
Reference in New Issue
Block a user