progress on updating users

This commit is contained in:
Bryce
2023-10-22 06:27:55 -07:00
parent 998d29690e
commit a6032e2be2
5 changed files with 109 additions and 105 deletions

View File

@@ -59,19 +59,19 @@
(defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
"hx-get" (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-table)
:admin-transaction-rule-table)
"hx-target" "#transaction-rule-table"
"hx-indicator" "#transaction-rule-table"}
[:fieldset.space-y-6
[:fieldset.space-y-6
(com/field {:label "Vendor"}
(com/typeahead {:name "vendor"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:vendor-search)
:id (str "vendor-search")
:value [(:db/id (:vendor (:parsed-query-params request)))
(:vendor/name (:vendor (:parsed-query-params request)))]}))
(com/typeahead-2 {:name "vendor"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:vendor-search)
:id (str "vendor-search")
:value [(:db/id (:vendor (:parsed-query-params request)))
(:vendor/name (:vendor (:parsed-query-params request)))]}))
(com/field {:label "Note"}
(com/text-input {:name "note"
:id "note"
@@ -193,7 +193,7 @@
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-dialog))
:hx-target "#modal-content"
:hx-swap "innerHTML"
:hx-swap "outerHTML"
:color :primary}
"New Transaction Rule")])
:row-buttons (fn [request entity]
@@ -201,7 +201,7 @@
:admin-transaction-rule-edit-dialog
:db/id (:db/id entity)))
:hx-target "#modal-content"
:hx-swap "innerHTML"}
:hx-swap "outerHTML"}
svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
:admin)}
@@ -220,7 +220,8 @@
{:key "bank-account"
:name "Bank account"
:sort-key "bank-account"
:render #(-> % :transaction-rule/bank-account :bank-account/name)}
:render #(-> % :transaction-rule/bank-account :bank-account/name)
:show-starting "lg"}
{:key "description"
:name "Description"
:sort-key "description"
@@ -233,7 +234,8 @@
(com/pill {:color :red} (format "more than $%.2f" amount-gte)))
(when amount-lte
(com/pill {:color :primary} (format "less than $%.2f" amount-lte)))])}
(com/pill {:color :primary} (format "less than $%.2f" amount-lte)))])
:show-starting "md"}
{:key "note"
:name "Note"
:sort-key "note"
@@ -401,16 +403,17 @@
(defn dialog* [& {:keys [entity form-params form-errors]}]
(com/modal
{:modal-class "max-w-2xl"}
(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"
:class "group/form"}
form-params)
[: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"
:class "group/form"}
form-params)
(com/modal-card
{}
[:div.flex [:div.p-2 "Transaction Rule"]]
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target"
:x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client entity))
(:transaction-rule/client entity))})}
@@ -448,43 +451,42 @@
(fc/with-field :transaction-rule/client
(com/validated-field
(-> {:label "Client"
:errors (fc/field-errors)
:x-show "clientFilter"}
(hx/alpine-appear))
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:error? (fc/error?)
:class "w-96"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :company-search)
:x-model "clientId"
: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))})]))
(-> {:label "Client"
:errors (fc/field-errors)
:x-show "clientFilter"}
(hx/alpine-appear))
[:div.w-96
(com/typeahead-2 {:name (fc/field-name)
:error? (fc/error?)
:class "w-96"
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :company-search)
:x-model "clientId"
: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/bank-account
(com/validated-field
(-> {:label "Bank Account"
:errors (fc/field-errors)
:x-show "bankAccountFilter"
}
hx/alpine-appear)
[:div.w-96
[:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-trigger "changed"
:hx-target "next *"
:hx-include "#bank-account-changer"
:hx-swap "innerHTML"
(-> {:label "Bank Account"
:errors (fc/field-errors)
:x-show "bankAccountFilter"}
hx/alpine-appear)
[:div.w-96
[:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-trigger "changed"
:hx-target "next *"
:hx-include "#bank-account-changer"
:hx-swap "innerHTML"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity))
:name (fc/field-name)
:value (fc/field-value)})]))
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
(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"
:x-show "amountFilter"}
@@ -511,18 +513,18 @@
[: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)})))
{: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)})))])]
{:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name)
:placeholder ">="
:class "w-24"
:value (fc/field-value)})))])]
[:h2.text-lg "Outcomes"]
(fc/with-field :transaction-rule/vendor
@@ -549,24 +551,24 @@
(doall (for [tra fc/*current*]
(fc/with-cursor tra
(transaction-rule-account-row* entity tra)))))
(com/data-grid-row
{:class "new-row"}
(com/data-grid-cell {:colspan 4
:class "bg-gray-100"}
[:div.flex.justify-center
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:color :secondary
: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 "#edit-form .new-row"
:hx-swap "beforebegin"}
"New account")])))
(com/data-grid-row
{:class "new-row"}
(com/data-grid-cell {:colspan 4
:class "bg-gray-100"}
[:div.flex.justify-center
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:color :secondary
: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 "#edit-form .new-row"
:hx-swap "beforebegin"}
"New account")])))
(com/errors {:errors (fc/field-errors)})))
(fc/with-field :transaction-rule/transaction-approval-status
(com/validated-field {:label "Approval status"
:errors (fc/field-errors)}
@@ -578,12 +580,11 @@
[:div#form-errors (when (:errors fc/*form-errors*)
[:span.error-content
(com/errors {:errors (:errors fc/*form-errors*)})])]
(com/button {:color :primary :form "edit-form" :type "submit" :class (cond-> "w-32"
(seq form-errors) (->
(hh/add-class "animate-shake")))}
"Save")])]]
[:div])))
(com/errors {:errors (:errors fc/*form-errors*)})])]])]
[:div (com/button {:color :primary :form "edit-form" :type "submit" :class (cond-> "w-32"
(seq form-errors) (->
(hh/add-class "animate-shake")))}
"Save")])]))
;; TODO Should forms have some kind of helper to render an individual field? saving

View File

@@ -3,15 +3,15 @@
[auto-ap.ssr.hx :as hx]))
(defn modal- [params & children]
[:div#modal-content {:class "flex items-center justify-between pb-2"}
[:div#modal-content {:class ""}
children])
(defn modal-card- [params header content footer]
[:div#modal-card params
[:div {:class "relative bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content"}
[:div {:class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content w-full"}
[:div {:class "flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600"} header]
[:div {:class "p-6 space-y-6"}
[:div {:class "p-6 space-y-6 overflow-scroll "}
content]
[:div footer]]])
(when footer [:div {:class "p-4 "} footer])]])
;; fade-in-settle slide-up-settle duration-300 transition-all

View File

@@ -77,13 +77,12 @@ c.clearChoices();
(str (:url params) "?q="))
:value {:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))}
:search ""
:active 0
:elements (if (:value params)
:active -1
:elements (if ((:value-fn params first) (:value params))
[{:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))}]
[])})
:x-modelable "value.value"
:x-model (:x-model params)
}
:x-model (:x-model params)}
[:a {:class (-> (hh/add-class (or (:class params) "") default-input-classes)
(hh/add-class "cursor-pointer"))
"@click.prevent" "open = !open;"
@@ -100,16 +99,15 @@ c.clearChoices();
(dissoc :placeholder)
(dissoc :x-model)
(assoc
"x-ref" "hidden"
:type "hidden"
":value" "value.value"
:x-init (hiccup/raw (str "$watch('value', v => $dispatch('change')); "))))]
"x-ref" "hidden"
:type "hidden"
":value" "value.value"
:x-init (hiccup/raw (str "$watch('value', v => $dispatch('change')); "))))]
[:div.flex.w-full.justify-items-stretch
[:span.flex-grow.text-left {"x-text" "value.label"}]
[:div {:class "w-3 h-3 m-1 inline ml-1 justify-self-end text-gray-500 self-center"}
svg/drop-down]]]
[:ul.dropdown-contents {:class "absolute bg-gray-50 dark:bg-gray-600 rounded-lg shadow-lg py-1 w-max z-10 mt-1"
"@keydown.escape" "open = false; value = {value: '', label: '' }"
"x-transition:enter" "ease-[cubic-bezier(.3,2.3,.6,1)] duration-200"

View File

@@ -206,7 +206,7 @@
(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:user-edit-dialog
:db/id (:db/id entity)))
:hx-target "#modal-holder"
:hx-target "#modal-content"
:hx-swap "outerHTML"}
svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
@@ -265,7 +265,7 @@
(html-response
(row* identity user {:flash? true})
:headers {"hx-trigger" "closeModal"
:headers {"hx-trigger" "modalclose"
"hx-retarget" (format "#user-table tr[data-id=\"%d\"]" (:db/id user))})))
(defn user-edit-dialog [request]
@@ -315,7 +315,8 @@
[:div#form-errors [:span.error-content]]
(com/button {:color :primary :type "submit"}
"Save")]
[:div])]]))))
[:div])]])
:headers {"hx-trigger" "modalopen"})))
(def key->handler
(apply-middleware-to-all-handlers