big ui improvemet

This commit is contained in:
Bryce
2023-10-21 07:37:05 -07:00
parent 2fc9a71577
commit aa14a310ab
6 changed files with 438 additions and 250 deletions

View File

@@ -196,7 +196,7 @@
:action-buttons (fn [request]
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-dialog))
:hx-target "#modal-holder"
:hx-target "#modal-content"
:hx-swap "innerHTML"
:color :primary}
"New Transaction Rule")])
@@ -204,7 +204,7 @@
[(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-dialog
:db/id (:db/id entity)))
:hx-target "#modal-holder"
:hx-target "#modal-content"
:hx-swap "innerHTML"}
svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
@@ -409,154 +409,153 @@
svg/x))))
;; TODO dialog is no longer closeable
(defn dialog* [& {:keys [ entity form-params form-errors]}]
(defn dialog* [& {:keys [entity form-params form-errors]}]
(com/modal
{:modal-class "max-w-4xl"}
(com/modal-card
{}
[:div.flex [:div.p-2 "Transaction Rule"] ]
[:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target "#modal-holder"
:hx-target-400 "#form-errors .error-content"
#_#_:x-trap "true"}
form-params)
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target"}
(fc/start-form entity form-errors
[:div.space-y-2
(when-let [id (:db/id entity)]
(com/hidden {:name "db/id"
:value id}))
{:modal-class "max-w-4xl"}
(com/modal-card
{}
[:div.flex [:div.p-2 "Transaction Rule"]]
[:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target "#modal-holder"
:hx-target-400 "#form-errors .error-content"
:x-trap "true"}
form-params)
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target"}
(fc/with-field :transaction-rule/client
(fc/start-form entity form-errors
[:div.space-y-2
(when-let [id (:db/id entity)]
(com/hidden {:name "db/id"
:value id}))
(com/validated-field
{:label "Client"
:errors (fc/field-errors)}
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:x-init "$el.focus()"
:error? (fc/error?)
:class "w-96"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :company-search)
:id (str "form-client-search")
:value (fc/field-value)
:value-fn (some-fn :db/id identity)
:content-fn (fn [c] (cond->> c
(nat-int? c) (dc/pull (dc/db conn) '[:client/name])
true :client/name))})]))
(fc/with-field :transaction-rule/client
(fc/with-field :transaction-rule/bank-account
(com/validated-field {:label "Bank Account"
:errors (fc/field-errors)}
[:div#bank-account-spot.w-96 {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-trigger (hx/trigger-field-change :name "transaction-rule/client"
:from "#edit-form")
:hx-swap "innerHTML"
:hx-ext "rename-params"
:hx-include "#edit-form"
:hx-vals (hx/vals {:name (fc/field-name)})
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"name" "name"})}
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity))
:name (fc/field-name)
:value (fc/field-value)})]))
(com/validated-field
{:label "Client"
:errors (fc/field-errors)}
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:x-init "$el.focus()"
:error? (fc/error?)
:class "w-96"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :company-search)
:id (str "form-client-search")
:value (fc/field-value)
:value-fn (some-fn :db/id identity)
:content-fn (fn [c] (cond->> c
(nat-int? c) (dc/pull (dc/db conn) '[:client/name])
true :client/name))})]))
(fc/with-field :transaction-rule/description
(com/validated-field {:label "Description"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:error? (fc/error?)
:placeholder "HOME DEPOT"
:class "w-96"
:value (fc/field-value)})))
(fc/with-field :transaction-rule/bank-account
(com/validated-field {:label "Bank Account"
:errors (fc/field-errors)}
[:div#bank-account-spot.w-96 {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-trigger (hx/trigger-field-change :name "transaction-rule/client"
:from "#edit-form")
:hx-swap "innerHTML"
:hx-ext "rename-params"
:hx-include "#edit-form"
:hx-vals (hx/vals {:name (fc/field-name)})
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"name" "name"})}
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity))
:name (fc/field-name)
:value (fc/field-value)})]))
(com/field {:label "Amount"}
[:div.flex.gap-2
(fc/with-field :transaction-rule/amount-gte
[:div.flex.flex-col
(com/money-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})
(com/errors {:errors (fc/field-errors)})])
(fc/with-field :transaction-rule/amount-lte
[:div.flex.flex-col
(com/money-input {:name (fc/field-name)
:placeholder "<="
:class "w-24"
:value (fc/field-value)})
(com/errors {:errors (fc/field-errors)})])])
(fc/with-field :transaction-rule/description
(com/validated-field {:label "Description"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:error? (fc/error?)
:placeholder "HOME DEPOT"
:class "w-96"
:value (fc/field-value)})))
(com/field {:label "Day of month"}
[:div.flex.gap-2
(fc/with-field :transaction-rule/dom-gte
(com/validated-field
{:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})))
(fc/with-field :transaction-rule/dom-lte
(com/validated-field
{:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})))])
(com/field {:label "Amount"}
[:div.flex.gap-2
(fc/with-field :transaction-rule/amount-gte
[:div.flex.flex-col
(com/money-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})
(com/errors {:errors (fc/field-errors)})])
(fc/with-field :transaction-rule/amount-lte
[:div.flex.flex-col
(com/money-input {:name (fc/field-name)
:placeholder "<="
:class "w-24"
:value (fc/field-value)})
(com/errors {:errors (fc/field-errors)})])])
[:h2.text-lg "Outcomes"]
(fc/with-field :transaction-rule/vendor
(com/validated-field {:label "Assign Vendor"
:errors (fc/field-errors)}
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
:id (str "form-vendor-search")
:value (fc/field-value)
:value-fn (some-fn :db/id identity)
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
(com/field {:label "Day of month"}
[:div.flex.gap-2
(fc/with-field :transaction-rule/dom-gte
(com/validated-field
{:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})))
(fc/with-field :transaction-rule/dom-lte
(com/validated-field
{:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})))])
(fc/with-field :transaction-rule/accounts
(list
(com/data-grid {:headers [(com/data-grid-header {}
"Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]
:id "transaction-rule-account-table"}
(when @fc/*current*
(doall (for [tra fc/*current*]
(fc/with-cursor tra
(transaction-rule-account-row* entity tra))))))
(com/errors {:errors (fc/field-errors)})))
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:hx-include "#edit-form"
:hx-ext "rename-params"
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")
:hx-target "#transaction-rule-account-table tbody"
:hx-swap "beforeend"}
"New account")
(fc/with-field :transaction-rule/transaction-approval-status
(com/validated-field {:label "Approval status"
:errors (fc/field-errors)}
(com/radio {:options (ref->radio-options "transaction-approval-status")
:value (fc/field-value)
:name (fc/field-name)
:orientation :horizontal})))
[:div#form-errors [:span.error-content
(com/errors {:errors (:errors fc/*form-errors*)})]]
(com/button {:color :primary :form "edit-form" :type "submit"}
"Save")])]]
[:div])))
[:h2.text-lg "Outcomes"]
(fc/with-field :transaction-rule/vendor
(com/validated-field {:label "Assign Vendor"
:errors (fc/field-errors)}
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
:id (str "form-vendor-search")
:value (fc/field-value)
:value-fn (some-fn :db/id identity)
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
(fc/with-field :transaction-rule/accounts
(list
(com/data-grid {:headers [(com/data-grid-header {}
"Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]
:id "transaction-rule-account-table"}
(when @fc/*current*
(doall (for [tra fc/*current*]
(fc/with-cursor tra
(transaction-rule-account-row* entity tra))))))
(com/errors {:errors (fc/field-errors)})))
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:hx-include "#edit-form"
:hx-ext "rename-params"
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")
:hx-target "#transaction-rule-account-table tbody"
:hx-swap "beforeend"}
"New account")
(fc/with-field :transaction-rule/transaction-approval-status
(com/validated-field {:label "Approval status"
:errors (fc/field-errors)}
(com/radio {:options (ref->radio-options "transaction-approval-status")
:value (fc/field-value)
:name (fc/field-name)
:orientation :horizontal})))
[:div#form-errors [:span.error-content
(com/errors {:errors (:errors fc/*form-errors*)})]]
(com/button {:color :primary :form "edit-form" :type "submit" :class "w-32"}
"Save")])]]
[:div])))
;; TODO Should forms have some kind of helper to render an individual field? saving