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.solr :as solr]
[auto-ap.ssr-routes :as ssr-routes] [auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com] [auto-ap.ssr.components :as com]
[auto-ap.ssr.form-cursor :as fc]
[auto-ap.ssr.grid-page-helper :as helper] [auto-ap.ssr.grid-page-helper :as helper]
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]] [auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.svg :as svg] [auto-ap.ssr.svg :as svg]
@@ -23,20 +24,17 @@
entity-id entity-id
html-response html-response
many-entity many-entity
map->db-id-decoder
ref->enum-schema ref->enum-schema
ref->select-options ref->select-options
temp-id temp-id
validation-error validation-error
wrap-form-4xx wrap-form-4xx-2
wrap-schema-decode]] wrap-schema-decode]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[clojure.string :as str] [clojure.string :as str]
[datomic.api :as dc] [datomic.api :as dc]
[hiccup2.core :as hiccup] [hiccup2.core :as hiccup]
[malli.core :as mc] [malli.core :as mc]))
[auto-ap.ssr.form-cursor :as fc]
[clj-time.format :as f]))
(defn filters [request] (defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms" [:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -222,18 +220,20 @@
(com/hidden {:name (fc/field-name) (com/hidden {:name (fc/field-name)
:value (fc/field-value)})) :value (fc/field-value)}))
(fc/with-field :account-client-override/client (fc/with-field :account-client-override/client
(com/typeahead-2 {:name (fc/field-name) (com/validated-field {:errors (fc/field-errors)}
:placeholder "Search..." (com/typeahead-2 {:name (fc/field-name)
:url (bidi/path-for ssr-routes/only-routes :placeholder "Search..."
:company-search) :url (bidi/path-for ssr-routes/only-routes
:value (fc/field-value) :company-search)
:value-fn :db/id ;; TODO hydration something here :value (fc/field-value)
:content-fn :client/name}))] :value-fn :db/id ;; TODO hydration something here
:content-fn :client/name})))]
(fc/with-field :account-client-override/name (fc/with-field :account-client-override/name
[:div.w-96 [:div.w-96
(com/text-input {:name (fc/field-name) (com/validated-field {:errors (fc/field-errors)}
:class "w-full" (com/text-input {:name (fc/field-name)
:value (fc/field-value)})]) :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)]]) [: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: ;; TODO each form:
@@ -269,43 +269,50 @@
(fc/with-field :account/numeric-code (fc/with-field :account/numeric-code
(when (nil? (fc/field-value)) (when (nil? (fc/field-value))
(com/field {:label "Numeric code"} (com/validated-field {:label "Numeric code"
(com/text-input {:name (fc/field-name) :errors (fc/field-errors)}
:autofocus true (com/text-input {:name (fc/field-name)
:class "w-32"})))) :autofocus true
:class "w-32"}))))
(fc/with-field :account/name (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) (com/text-input {:name (fc/field-name)
:autofocus true :autofocus true
:class "w-32" :class "w-32"
:value (fc/field-value)}))) :value (fc/field-value)})))
(fc/with-field :account/type (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) (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:id "type" :id "type"
:value (some-> (fc/field-value) name) :value (some-> (fc/field-value) name)
:options (ref->select-options "account-type")}))) :options (ref->select-options "account-type")})))
(fc/with-field :account/location (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) (com/text-input {:name (fc/field-name)
:class "w-16" :class "w-16"
:value (fc/field-value)}))) :value (fc/field-value)})))
(fc/with-field :account/invoice-allowance (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) (com/select {:name (fc/field-name)
:value (some-> (fc/field-value) name) :value (some-> (fc/field-value) name)
:class "w-36" :class "w-36"
:options (ref->select-options "allowance")}))) :options (ref->select-options "allowance")})))
(fc/with-field :account/vendor-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) (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:value (some-> (fc/field-value) name) :value (some-> (fc/field-value) name)
:options (ref->select-options "allowance")}))) :options (ref->select-options "allowance")})))
(fc/with-field :account/applicability (fc/with-field :account/applicability
(com/field {:label "Applicability"} (com/validated-field {:label "Applicability"
:errors (fc/field-errors)}
(com/select {:name (fc/field-name) (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:value (some-> (fc/field-value) name) :value (some-> (fc/field-value) name)
@@ -351,6 +358,20 @@
:admin-account-new-save))}) :admin-account-new-save))})
:headers {"hx-trigger" "modalopen"})) :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 (def account-schema (mc/schema
[:map [:map
[:db/id {:optional true} [:maybe entity-id]] [:db/id {:optional true} [:maybe entity-id]]
@@ -366,7 +387,7 @@
(many-entity {} (many-entity {}
[:db/id [:or entity-id temp-id]] [:db/id [:or entity-id temp-id]]
[:account-client-override/client [:or entity-id :string]] [:account-client-override/client [:or entity-id :string]]
[:account-client-override/name :string])]]])) [:account-client-override/name [:string {:min 2}]])]]]))
(def key->handler (def key->handler
(apply-middleware-to-all-handlers (apply-middleware-to-all-handlers
@@ -381,7 +402,7 @@
:admin-account-save (-> account-save :admin-account-save (-> account-save
(wrap-schema-decode :form-schema account-schema) (wrap-schema-decode :form-schema account-schema)
(wrap-nested-form-params) (wrap-nested-form-params)
(wrap-form-4xx)) (wrap-form-4xx-2 account-save-error))
:admin-account-edit-dialog (-> account-edit-dialog :admin-account-edit-dialog (-> account-edit-dialog
(wrap-schema-decode :route-schema [:map [:db/id entity-id]])) (wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
:admin-account-new-dialog account-new-dialog}) :admin-account-new-dialog account-new-dialog})