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

@@ -1356,6 +1356,10 @@ input:checked + .toggle-bg {
max-height: 100%; max-height: 100%;
} }
.max-h-\[90vh\] {
max-height: 90vh;
}
.w-1\/2 { .w-1\/2 {
width: 50%; width: 50%;
} }

View File

@@ -59,19 +59,19 @@
(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"
"hx-get" (bidi/path-for ssr-routes/only-routes "hx-get" (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-table) :admin-transaction-rule-table)
"hx-target" "#transaction-rule-table" "hx-target" "#transaction-rule-table"
"hx-indicator" "#transaction-rule-table"} "hx-indicator" "#transaction-rule-table"}
[:fieldset.space-y-6 [:fieldset.space-y-6
(com/field {:label "Vendor"} (com/field {:label "Vendor"}
(com/typeahead {:name "vendor" (com/typeahead-2 {:name "vendor"
:placeholder "Search..." :placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :url (bidi/path-for ssr-routes/only-routes
:vendor-search) :vendor-search)
:id (str "vendor-search") :id (str "vendor-search")
:value [(:db/id (:vendor (:parsed-query-params request))) :value [(:db/id (:vendor (:parsed-query-params request)))
(:vendor/name (:vendor (:parsed-query-params request)))]})) (:vendor/name (:vendor (:parsed-query-params request)))]}))
(com/field {:label "Note"} (com/field {:label "Note"}
(com/text-input {:name "note" (com/text-input {:name "note"
:id "note" :id "note"
@@ -193,7 +193,7 @@
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes [(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-dialog)) :admin-transaction-rule-new-dialog))
:hx-target "#modal-content" :hx-target "#modal-content"
:hx-swap "innerHTML" :hx-swap "outerHTML"
:color :primary} :color :primary}
"New Transaction Rule")]) "New Transaction Rule")])
:row-buttons (fn [request entity] :row-buttons (fn [request entity]
@@ -201,7 +201,7 @@
:admin-transaction-rule-edit-dialog :admin-transaction-rule-edit-dialog
:db/id (:db/id entity))) :db/id (:db/id entity)))
:hx-target "#modal-content" :hx-target "#modal-content"
:hx-swap "innerHTML"} :hx-swap "outerHTML"}
svg/pencil)]) svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes :breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
:admin)} :admin)}
@@ -220,7 +220,8 @@
{:key "bank-account" {:key "bank-account"
:name "Bank account" :name "Bank account"
:sort-key "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" {:key "description"
:name "Description" :name "Description"
:sort-key "description" :sort-key "description"
@@ -233,7 +234,8 @@
(com/pill {:color :red} (format "more than $%.2f" amount-gte))) (com/pill {:color :red} (format "more than $%.2f" amount-gte)))
(when amount-lte (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" {:key "note"
:name "Note" :name "Note"
:sort-key "note" :sort-key "note"
@@ -401,16 +403,17 @@
(defn dialog* [& {:keys [entity form-params form-errors]}] (defn dialog* [& {:keys [entity form-params form-errors]}]
(com/modal (com/modal
{:modal-class "max-w-2xl"} {:modal-class "max-w-2xl"}
(com/modal-card
{} [:form#edit-form (merge {:hx-ext "response-targets"
[:div.flex [:div.p-2 "Transaction Rule"]] :hx-swap "outerHTML swap:300ms"
[:form#edit-form (merge {:hx-ext "response-targets" :hx-target "#modal-holder"
:hx-swap "outerHTML swap:300ms" :hx-target-400 "#form-errors .error-content"
:hx-target "#modal-holder" :x-trap "true"
:hx-target-400 "#form-errors .error-content" :class "group/form"}
:x-trap "true" form-params)
:class "group/form"} (com/modal-card
form-params) {}
[:div.flex [:div.p-2 "Transaction Rule"]]
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target" [:fieldset {:class "hx-disable" :hx-disinherit "hx-target"
:x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client entity)) :x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client entity))
(:transaction-rule/client entity))})} (:transaction-rule/client entity))})}
@@ -448,43 +451,42 @@
(fc/with-field :transaction-rule/client (fc/with-field :transaction-rule/client
(com/validated-field (com/validated-field
(-> {:label "Client" (-> {:label "Client"
:errors (fc/field-errors) :errors (fc/field-errors)
:x-show "clientFilter"} :x-show "clientFilter"}
(hx/alpine-appear)) (hx/alpine-appear))
[:div.w-96 [:div.w-96
(com/typeahead-2 {:name (fc/field-name) (com/typeahead-2 {:name (fc/field-name)
:error? (fc/error?) :error? (fc/error?)
:class "w-96" :class "w-96"
:placeholder "Search..." :placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :company-search) :url (bidi/path-for ssr-routes/only-routes :company-search)
:x-model "clientId" :x-model "clientId"
:value (fc/field-value) :value (fc/field-value)
:value-fn (some-fn :db/id identity) :value-fn (some-fn :db/id identity)
:content-fn (fn [c] (cond->> c :content-fn (fn [c] (cond->> c
(nat-int? c) (dc/pull (dc/db conn) '[:client/name]) (nat-int? c) (dc/pull (dc/db conn) '[:client/name])
true :client/name))})])) true :client/name))})]))
(fc/with-field :transaction-rule/bank-account (fc/with-field :transaction-rule/bank-account
(com/validated-field (com/validated-field
(-> {:label "Bank Account" (-> {:label "Bank Account"
:errors (fc/field-errors) :errors (fc/field-errors)
:x-show "bankAccountFilter" :x-show "bankAccountFilter"}
} hx/alpine-appear)
hx/alpine-appear) [:div.w-96
[:div.w-96 [:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
[:div#bank-account-changer {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead) :hx-trigger "changed"
:hx-trigger "changed" :hx-target "next *"
:hx-target "next *" :hx-include "#bank-account-changer"
:hx-include "#bank-account-changer" :hx-swap "innerHTML"
:hx-swap "innerHTML"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name)) :hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}] :x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity)) (bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity))
:name (fc/field-name) :name (fc/field-name)
:value (fc/field-value)})])) :value (fc/field-value)})]))
(com/field (-> {:label "Amount" (com/field (-> {:label "Amount"
:x-show "amountFilter"} :x-show "amountFilter"}
@@ -511,18 +513,18 @@
[:div.flex.gap-2 [:div.flex.gap-2
(fc/with-field :transaction-rule/dom-gte (fc/with-field :transaction-rule/dom-gte
(com/validated-field (com/validated-field
{:errors (fc/field-errors)} {:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name) (com/int-input {:name (fc/field-name)
:placeholder ">=" :placeholder ">="
:class "w-24" :class "w-24"
:value (fc/field-value)}))) :value (fc/field-value)})))
(fc/with-field :transaction-rule/dom-lte (fc/with-field :transaction-rule/dom-lte
(com/validated-field (com/validated-field
{:errors (fc/field-errors)} {:errors (fc/field-errors)}
(com/int-input {:name (fc/field-name) (com/int-input {:name (fc/field-name)
:placeholder ">=" :placeholder ">="
:class "w-24" :class "w-24"
:value (fc/field-value)})))])] :value (fc/field-value)})))])]
[:h2.text-lg "Outcomes"] [:h2.text-lg "Outcomes"]
(fc/with-field :transaction-rule/vendor (fc/with-field :transaction-rule/vendor
@@ -550,21 +552,21 @@
(fc/with-cursor tra (fc/with-cursor tra
(transaction-rule-account-row* entity tra))))) (transaction-rule-account-row* entity tra)))))
(com/data-grid-row (com/data-grid-row
{:class "new-row"} {:class "new-row"}
(com/data-grid-cell {:colspan 4 (com/data-grid-cell {:colspan 4
:class "bg-gray-100"} :class "bg-gray-100"}
[:div.flex.justify-center [:div.flex.justify-center
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes (com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account) :admin-transaction-rule-new-account)
:color :secondary :color :secondary
:hx-include "#edit-form" :hx-include "#edit-form"
:hx-ext "rename-params" :hx-ext "rename-params"
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id" :hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"}) "index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}") :hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")
:hx-target "#edit-form .new-row" :hx-target "#edit-form .new-row"
:hx-swap "beforebegin"} :hx-swap "beforebegin"}
"New account")]))) "New account")])))
(com/errors {:errors (fc/field-errors)}))) (com/errors {:errors (fc/field-errors)})))
(fc/with-field :transaction-rule/transaction-approval-status (fc/with-field :transaction-rule/transaction-approval-status
@@ -578,12 +580,11 @@
[:div#form-errors (when (:errors fc/*form-errors*) [:div#form-errors (when (:errors fc/*form-errors*)
[:span.error-content [:span.error-content
(com/errors {:errors (:errors fc/*form-errors*)})])] (com/errors {:errors (:errors fc/*form-errors*)})])]])]
(com/button {:color :primary :form "edit-form" :type "submit" :class (cond-> "w-32" [:div (com/button {:color :primary :form "edit-form" :type "submit" :class (cond-> "w-32"
(seq form-errors) (-> (seq form-errors) (->
(hh/add-class "animate-shake")))} (hh/add-class "animate-shake")))}
"Save")])]] "Save")])]))
[:div])))
;; TODO Should forms have some kind of helper to render an individual field? saving ;; 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])) [auto-ap.ssr.hx :as hx]))
(defn modal- [params & children] (defn modal- [params & children]
[:div#modal-content {:class "flex items-center justify-between pb-2"} [:div#modal-content {:class ""}
children]) children])
(defn modal-card- [params header content footer] (defn modal-card- [params header content footer]
[:div#modal-card params [: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 "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] content]
[:div footer]]]) (when footer [:div {:class "p-4 "} footer])]])
;; fade-in-settle slide-up-settle duration-300 transition-all ;; fade-in-settle slide-up-settle duration-300 transition-all

View File

@@ -77,13 +77,12 @@ c.clearChoices();
(str (:url params) "?q=")) (str (:url params) "?q="))
:value {:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))} :value {:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))}
:search "" :search ""
:active 0 :active -1
:elements (if (:value params) :elements (if ((:value-fn params first) (:value params))
[{:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))}] [{:value ((:value-fn params first) (:value params)) :label ((:content-fn params second) (:value params))}]
[])}) [])})
:x-modelable "value.value" :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) [:a {:class (-> (hh/add-class (or (:class params) "") default-input-classes)
(hh/add-class "cursor-pointer")) (hh/add-class "cursor-pointer"))
"@click.prevent" "open = !open;" "@click.prevent" "open = !open;"
@@ -100,16 +99,15 @@ c.clearChoices();
(dissoc :placeholder) (dissoc :placeholder)
(dissoc :x-model) (dissoc :x-model)
(assoc (assoc
"x-ref" "hidden" "x-ref" "hidden"
:type "hidden" :type "hidden"
":value" "value.value" ":value" "value.value"
:x-init (hiccup/raw (str "$watch('value', v => $dispatch('change')); "))))] :x-init (hiccup/raw (str "$watch('value', v => $dispatch('change')); "))))]
[:div.flex.w-full.justify-items-stretch [:div.flex.w-full.justify-items-stretch
[:span.flex-grow.text-left {"x-text" "value.label"}] [: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"} [:div {:class "w-3 h-3 m-1 inline ml-1 justify-self-end text-gray-500 self-center"}
svg/drop-down]]] 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" [: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: '' }" "@keydown.escape" "open = false; value = {value: '', label: '' }"
"x-transition:enter" "ease-[cubic-bezier(.3,2.3,.6,1)] duration-200" "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 (com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:user-edit-dialog :user-edit-dialog
:db/id (:db/id entity))) :db/id (:db/id entity)))
:hx-target "#modal-holder" :hx-target "#modal-content"
:hx-swap "outerHTML"} :hx-swap "outerHTML"}
svg/pencil)]) svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes :breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
@@ -265,7 +265,7 @@
(html-response (html-response
(row* identity user {:flash? true}) (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))}))) "hx-retarget" (format "#user-table tr[data-id=\"%d\"]" (:db/id user))})))
(defn user-edit-dialog [request] (defn user-edit-dialog [request]
@@ -315,7 +315,8 @@
[:div#form-errors [:span.error-content]] [:div#form-errors [:span.error-content]]
(com/button {:color :primary :type "submit"} (com/button {:color :primary :type "submit"}
"Save")] "Save")]
[:div])]])))) [:div])]])
:headers {"hx-trigger" "modalopen"})))
(def key->handler (def key->handler
(apply-middleware-to-all-handlers (apply-middleware-to-all-handlers