progress.

This commit is contained in:
2023-10-22 21:53:47 -07:00
parent dd5063c72d
commit 2f05197f5b

View File

@@ -15,6 +15,7 @@
[auto-ap.solr :as solr]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.form-cursor :as fc]
[auto-ap.ssr.grid-page-helper :as helper]
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.svg :as svg]
@@ -23,20 +24,17 @@
entity-id
html-response
many-entity
map->db-id-decoder
ref->enum-schema
ref->select-options
temp-id
validation-error
wrap-form-4xx
wrap-form-4xx-2
wrap-schema-decode]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[datomic.api :as dc]
[hiccup2.core :as hiccup]
[malli.core :as mc]
[auto-ap.ssr.form-cursor :as fc]
[clj-time.format :as f]))
[malli.core :as mc]))
(defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -222,18 +220,20 @@
(com/hidden {:name (fc/field-name)
:value (fc/field-value)}))
(fc/with-field :account-client-override/client
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:company-search)
:value (fc/field-value)
:value-fn :db/id ;; TODO hydration something here
:content-fn :client/name}))]
(com/validated-field {:errors (fc/field-errors)}
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:company-search)
:value (fc/field-value)
:value-fn :db/id ;; TODO hydration something here
:content-fn :client/name})))]
(fc/with-field :account-client-override/name
[:div.w-96
(com/text-input {:name (fc/field-name)
:class "w-full"
:value (fc/field-value)})])
(com/validated-field {:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:class "w-full"
:value (fc/field-value)}))])
[:div (com/a-icon-button {"_" (hiccup/raw "on click halt the event then transition the closest <.client-override />'s opacity to 0 then remove closest <.client-override />")} svg/x)]])
;; TODO each form:
@@ -269,43 +269,50 @@
(fc/with-field :account/numeric-code
(when (nil? (fc/field-value))
(com/field {:label "Numeric code"}
(com/text-input {:name (fc/field-name)
:autofocus true
:class "w-32"}))))
(com/validated-field {:label "Numeric code"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:autofocus true
:class "w-32"}))))
(fc/with-field :account/name
(com/field {:label "Name"}
(com/validated-field {:label "Name"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:autofocus true
:class "w-32"
:value (fc/field-value)})))
(fc/with-field :account/type
(com/field {:label "Account Type"}
(com/validated-field {:label "Account Type"
:errors (fc/field-errors)}
(com/select {:name (fc/field-name)
:class "w-36"
:id "type"
:value (some-> (fc/field-value) name)
:options (ref->select-options "account-type")})))
(fc/with-field :account/location
(com/field {:label "Location"}
(com/validated-field {:label "Location"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:class "w-16"
:value (fc/field-value)})))
(fc/with-field :account/invoice-allowance
(com/field {:label "Invoice Allowance"}
(com/validated-field {:label "Invoice Allowance"
:errors (fc/field-errors)}
(com/select {:name (fc/field-name)
:value (some-> (fc/field-value) name)
:class "w-36"
:options (ref->select-options "allowance")})))
(fc/with-field :account/vendor-allowance
(com/field {:label "Vendor Allowance"}
(com/validated-field {:label "Vendor Allowance"
:errors (fc/field-errors)}
(com/select {:name (fc/field-name)
:class "w-36"
:value (some-> (fc/field-value) name)
:options (ref->select-options "allowance")})))
(fc/with-field :account/applicability
(com/field {:label "Applicability"}
(com/validated-field {:label "Applicability"
:errors (fc/field-errors)}
(com/select {:name (fc/field-name)
:class "w-36"
:value (some-> (fc/field-value) name)
@@ -351,6 +358,20 @@
:admin-account-new-save))})
:headers {"hx-trigger" "modalopen"}))
(defn account-save-error [request]
;; TODO hydration
;; TODO consistency of error handling and passing, on all form examples
(let [entity (some-> request :last-form)]
(html-response (dialog* :account entity
:form-errors (:form-errors request)
:form-params (if (:db/id entity)
{:hx-put (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-save))}
{:hx-post (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-save))}))
:headers {"hx-retarget" "#edit-form fieldset"
"hx-reselect" "#edit-form fieldset"})))
(def account-schema (mc/schema
[:map
[:db/id {:optional true} [:maybe entity-id]]
@@ -366,7 +387,7 @@
(many-entity {}
[:db/id [:or entity-id temp-id]]
[:account-client-override/client [:or entity-id :string]]
[:account-client-override/name :string])]]]))
[:account-client-override/name [:string {:min 2}]])]]]))
(def key->handler
(apply-middleware-to-all-handlers
@@ -381,7 +402,7 @@
:admin-account-save (-> account-save
(wrap-schema-decode :form-schema account-schema)
(wrap-nested-form-params)
(wrap-form-4xx))
(wrap-form-4xx-2 account-save-error))
:admin-account-edit-dialog (-> account-edit-dialog
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
:admin-account-new-dialog account-new-dialog})