more cleanup.

This commit is contained in:
2023-10-28 20:27:00 -07:00
parent 855c23f4ae
commit e8a419fb3c
9 changed files with 142 additions and 121 deletions

View File

@@ -31,10 +31,9 @@
@apply opacity-100 !important;
@apply scale-100 !important;
@apply -translate-x-1/2 !important;
}
.htmx-added.swipe-left-swap , .htmx-added .swipe-left-swap{
.swipe-left-swap {
@apply opacity-100;
@apply scale-100;
@apply translate-x-0;

File diff suppressed because one or more lines are too long

View File

@@ -13,6 +13,7 @@
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils :refer [extract-client-ids]]
[auto-ap.query-params :as query-params]
[auto-ap.routes.admin.transaction-rules :as route]
[auto-ap.routes.utils
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
[auto-ap.ssr-routes :as ssr-routes]
@@ -51,7 +52,7 @@
(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)
::route/table)
"hx-target" "#entity-table"
"hx-indicator" "#entity-table"}
@@ -183,30 +184,25 @@
(query-params/parse-key :vendor #(dc/pull (dc/db conn) '[:vendor/name :db/id] (Long/parseLong %)))
(helper/default-parse-query-params grid-page))
:action-buttons (fn [request]
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-dialog))
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/new-dialog))
:color :primary}
"New Transaction Rule")])
:row-buttons (fn [request entity]
[
(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-execute-results
:db/id (:db/id entity)))}
[(com/icon-button {:hx-get (bidi/path-for ssr-routes/only-routes
::route/execute-dialog
:db/id (:db/id entity))}
svg/play)
(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-dialog
:db/id (:db/id entity)))}
(com/icon-button {:hx-get (bidi/path-for ssr-routes/only-routes
::route/edit-dialog
:db/id (:db/id entity))}
svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
:admin)}
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes :admin)}
"Admin"]
[:a {:href (bidi/path-for ssr-routes/only-routes
:admin-transaction-rules)}
[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
"Transaction Rules"]]
:title "Rules"
:entity-name "Rule"
:route :admin-transaction-rule-table
:route ::route/table
:headers [{:key "client"
:name "Client"
:sort-key "client"
@@ -284,7 +280,7 @@
[:transaction-rule/bank-account]
:form form-params)))
(defn transaction-rule-save [{:keys [form-params request-method identity] :as request}]
(defn save [{:keys [form-params request-method identity] :as request}]
(validate-transaction-rule form-params)
(let [entity (cond-> form-params
(= :post request-method) (assoc :db/id "new")
@@ -307,13 +303,15 @@
(def transaction-read '[{:transaction/client [:client/name]
:transaction/bank-account [:bank-account/name]}
:transaction/description-original
:db/id
[:transaction/date :xform clj-time.coerce/from-date]])
(defn transaction-rule-test-table* [{{:transaction-rule/keys [description client bank-account amount-lte amount-gte dom-lte dom-gte yodlee-merchant]}
:entity
clients :clients
checkboxes? :checkboxes?}]
checkboxes? :checkboxes?
only-uncoded? :only-uncoded?}]
(let [valid-clients (extract-client-ids clients
client)
@@ -366,20 +364,26 @@
'[(>= ?dom ?dom-gte)]]}
:args [dom-gte]})
only-uncoded?
(merge-query {:query {:where ['[or [?e :transaction/approval-status :transaction-approval-status/unapproved]
[(missing? $ ?e :transaction/approval-status)]]]}})
true
(merge-query {:query {:where ['[?e :transaction/id]]}}))
results (->>
(query2 query)
(map first))]
[:div
[:h2.my-4.text-lg.flex "Matching transactions" [:div.ml-4.relative (com/badge {:class "text-[0.6rem]"} (let [cnt (count results)]
(if (>= cnt 99)
"99+"
cnt)))]]
[:div#transaction-test-results
[:h2.my-4.text-lg.flex {:x-data (hx/json {:resultCount (count results)})} "Matching transactions"
[:div.ml-4.relative (com/badge {:class "text-[0.6rem]"} (let [cnt (count results)]
(if (>= cnt 99)
"99+"
cnt)))]
[:div.flex.justify-end.flex-1 [:div.gutter]]]
(com/data-grid
{:headers [(when checkboxes?
(com/data-grid-checkbox-header {}))
(com/data-grid-checkbox-header {:name "all"}))
(com/data-grid-header {} "Client")
(com/data-grid-header {} "Bank")
(com/data-grid-header {} "Date")
@@ -388,20 +392,20 @@
(com/data-grid-row
{}
(when checkboxes?
(com/data-grid-cell {} (com/checkbox {})))
(com/data-grid-cell {} (com/checkbox {:name "transaction-id" :value (:db/id r)})))
(com/data-grid-cell {} (-> r :transaction/client :client/name))
(com/data-grid-cell {} (-> r :transaction/bank-account :bank-account/name))
(com/data-grid-cell {} (some-> r :transaction/date (atime/unparse-local atime/normal-date)))
(com/data-grid-cell {} (some-> r :transaction/description-original )))))]))
(defn transaction-rule-test [{:keys [form-params request-method identity] :as request
(defn test [{:keys [form-params request-method identity] :as request
entity :form-params}]
(validate-transaction-rule form-params)
(html-response
(com/stacked-modal-card
1
{}
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"] [:div.ml-4.relative (com/badge {} 100 #_(count results))]]
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"] ]
(transaction-rule-test-table* {:entity entity
:clients (:clients request)})
[:div.flex.justify-between
@@ -410,11 +414,11 @@
:class "w-32"}
"Back")
(com/button (cond-> {:color :primary
:hx-vals (hx/json (:raw-form-params request))
:hx-include "#my-form"
:class "w-32"
}
(:db/id form-params) (assoc :hx-put (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save))
(not (:db/id form-params)) (assoc :hx-post (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save)))
(:db/id form-params) (assoc :hx-put (bidi/path-for ssr-routes/only-routes ::route/save))
(not (:db/id form-params)) (assoc :hx-post (bidi/path-for ssr-routes/only-routes ::route/save)))
"Save rule")])
:headers (-> {}
(assoc "hx-trigger-after-settle" "modalnext")
@@ -422,6 +426,8 @@
(assoc "hx-reswap" "beforeend"))))
;; TODO only uncoded
(defn- location-select*
[{:keys [ name account-location client-locations value]}]
@@ -476,7 +482,7 @@
[:div {:hx-trigger "changed"
:hx-target "next div"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId, value: event.detail.accountId}" account-name)
:hx-get (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-account-typeahead))
:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/account-typeahead))
:x-init "$watch('clientId', cid => $dispatch('changed', $data));"}]
(account-typeahead* {:value (fc/field-value)
:client-id client-id
@@ -492,7 +498,7 @@
:hx-target "next *"
:hx-swap "outerHTML"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId || '', 'account-id': event.detail.accountId || '', value: event.detail.location}" (fc/field-name) )
:hx-get (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-location-select)
:hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select)
:x-init "$watch('clientId', cid => $dispatch('changed', $data)); $watch('accountId', cid => $dispatch('changed', $data) )"}]
(location-select* {:name (fc/field-name)
:account-location (:account/location (cond->> (:transaction-rule-account/account @account)
@@ -531,7 +537,7 @@
:x-trap "true"
(if (:db/id entity)
:hx-put
:hx-post) (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-edit-save))}
:hx-post) (str (bidi/path-for ssr-routes/only-routes ::route/save))}
[:fieldset {:class "hx-disable"
:x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client form-params))
(:transaction-rule/client form-params)
@@ -664,7 +670,7 @@
(fc/cursor-map #(transaction-rule-account-row* % (:transaction-rule/client form-params) client-locations))
(com/data-grid-new-row {:colspan 4
:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
::route/new-account)
:index (count (fc/field-value))
:tr-params (hx/bind-alpine-vals {} {:client-id "clientId"})}
"New account")))))
@@ -676,15 +682,13 @@
:value (fc/field-value)
:name (fc/field-name)
:size :small
:orientation :horizontal})))
]]]
:orientation :horizontal})))]]]
[:div
(com/form-errors {:errors (:errors fc/*form-errors*)})
[:div.flex.justify-end
(com/validated-save-button {:errors form-errors :color :secondary
:hx-post (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-test)
:hx-post (bidi/path-for ssr-routes/only-routes ::route/test)
:hx-include "#my-form"}
"Test rule")
@@ -742,7 +746,7 @@
[:transaction-rule-account/location [:string {:min 1 :error/message "required"}]]
[:transaction-rule-account/percentage percentage])]]))
(defn transaction-dialog [{:keys [entity form-params form-errors]}]
(defn edit-dialog [{:keys [entity form-params form-errors]}]
(modal-response (dialog* {:entity entity
:form-params (or (when (seq form-params)
form-params)
@@ -751,16 +755,31 @@
{})
:form-errors form-errors})))
(defn transaction-rule-execute-results [{:keys [entity clients]}]
(defn check-badges [{query-params :query-params}]
(html-response
[:div (if (not-empty (:all query-params))
(com/pill {:color :secondary}
[:span "All " [:span {:x-text "resultCount" :x-data "{}"}] " transactions"])
(com/pill {:color :primary}
(str (count (:transaction-id query-params)) " transactions")))]))
(defn execute-dialog [{:keys [entity clients]}]
(modal-response
(com/modal{}
(com/stacked-modal-card
0
{}
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"]]
(transaction-rule-test-table* {:entity entity
:clients clients
:checkboxes? true})
[:div#my-form
{:hx-get (bidi/path-for ssr-routes/only-routes ::route/check-badges)
:hx-trigger "change"
:hx-target "#transaction-test-results .gutter"
:hx-include "this"}
(transaction-rule-test-table* {:entity entity
:clients clients
:checkboxes? true
:only-uncoded? true})]
[:div.flex.justify-end (com/validated-save-button {:form "my-form"} "Code transactions")]))
:headers (-> {}
(assoc "hx-trigger-after-settle" "modalnext")
@@ -772,56 +791,60 @@
(def key->handler
(apply-middleware-to-all-handlers
(->>
{:admin-transaction-rules (helper/page-route grid-page)
:admin-transaction-rule-table (helper/table-route grid-page)
:admin-transaction-rule-new-account (-> new-account
(wrap-schema-decode :query-schema [:map
[:client-id {:optional true}
[:maybe entity-id]]
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
:admin-transaction-rule-location-select (-> location-select
(wrap-schema-decode :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
[:account-id {:optional true}
[:maybe entity-id]]]))
:admin-transaction-rule-account-typeahead (-> account-typeahead
(wrap-schema-decode :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
[:value {:optional true}
[:maybe entity-id]]]))
:admin-transaction-rule-save (-> transaction-rule-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read))))
{::route/page (helper/page-route grid-page)
::route/table (helper/table-route grid-page)
::route/new-account (-> new-account
(wrap-schema-decode :query-schema [:map
[:client-id {:optional true}
[:maybe entity-id]]
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
::route/location-select (-> location-select
(wrap-schema-decode :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
[:account-id {:optional true}
[:maybe entity-id]]]))
::route/account-typeahead (-> account-typeahead
(wrap-schema-decode :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
[:value {:optional true}
[:maybe entity-id]]]))
::route/save (-> save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> edit-dialog
(wrap-entity [:form-params :db/id] default-read))))
:admin-transaction-rule-test (-> transaction-rule-test
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read))))
::route/test (-> test
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> edit-dialog
(wrap-entity [:form-params :db/id] default-read))))
:admin-transaction-rule-execute-results (-> transaction-rule-execute-results
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
:admin-transaction-rule-filled-account (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read))))
:admin-transaction-rule-edit-dialog (-> transaction-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
:admin-transaction-rule-new-dialog transaction-dialog})
::route/check-badges (-> check-badges
(wrap-schema-decode :query-schema [:map
[:transaction-id {:optional true}
[:maybe [:vector {:decode/arbitrary (fn [x]
(if (sequential? x)
x
[x]))}
entity-id]]]
[:all {:optional true} [:maybe :string]]]))
::route/execute-dialog (-> execute-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
::route/edit-dialog (-> edit-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
::route/new-dialog edit-dialog})
(fn [h]
(-> h
(wrap-admin)

View File

@@ -36,7 +36,7 @@
(defn checkbox-header- [params & rest]
[:th {:scope "col", :class "p-4"}
[:div {:class "flex items-center"}
[:input {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes}]
[:input {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes :name (:name params) :value (:value params)}]
[:label {:for "checkbox-all", :class "sr-only"} "checkbox"]]])
(defn data-grid- [{:keys [headers thead-params id]} & rest]

View File

@@ -204,5 +204,5 @@
[:input {:type "hidden" :value value :name name}])
(defn checkbox- [params & rest]
[:input {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))}
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})
rest])

View File

@@ -12,17 +12,9 @@
\"foo[bar][][baz]\"
=> [\"foo\" \"bar\" \"\" \"baz\"]"
[param-name]
(let [[_ k ks] (re-matches #"(?s)(.*?)((?:(\[.*?\])|\(.*?\))*)" (name param-name))
keys (if ks (map second (re-seq #"(\[.*?\]|\(.*?\))" ks)))]
(cons k
(map (fn [k]
(let [[_ indexed-match] (re-matches k "\((.*?)\)")
[_ keyed-match] (re-matches k "\[(.*?)\]")]
(if indexed-match
[:index indexed-match]
[:key indexed-match])))))))
(let [[_ k ks] (re-matches #"(?s)(.*?)((?:\[.*?\])*)" (name param-name))
keys (if ks (map second (re-seq #"\[(.*?)\]" ks)))]
(cons k keys)))
(defn- assoc-vec [m k v]
(let [m (if (contains? m k) m (assoc m k []))]

View File

@@ -0,0 +1,16 @@
(ns auto-ap.routes.admin.transaction-rules)
(def routes {"" {:get ::page
:put ::save
:post ::save}
"/table" ::table
"/account/filled" ::dialog-filled
"/account/new" ::new-account
"/account/location-select" ::location-select
"/account/typeahead" ::account-typeahead
"/test" ::test
"/new" {:get ::new-dialog}
[[#"\d+" :db/id] "/edit"] ::edit-dialog
[[#"\d+" :db/id] "/run"] ::execute-dialog
"/check-badges" ::check-badges
})

View File

@@ -0,0 +1,2 @@
(ns auto-ap.ssr.admin.transaction-rules)

View File

@@ -1,4 +1,5 @@
(ns auto-ap.ssr-routes)
(ns auto-ap.ssr-routes
(:require [auto-ap.routes.admin.transaction-rules :as tr-routes]))
(def routes {"impersonate" :impersonate
"logout" :logout
@@ -33,19 +34,7 @@
"/new" {:get :admin-job-start-dialog}
"/subform" :admin-job-subform}
"/ezcater-xls" :admin-ezcater-xls
"/transaction-rule" {"" {:get :admin-transaction-rules
:put :admin-transaction-rule-save
:post :admin-transaction-rule-save}
"/table" :admin-transaction-rule-table
"/account/filled" :admin-transaction-rule-filled-account
"/account/new" :admin-transaction-rule-new-account
"/account/location-select" :admin-transaction-rule-location-select
"/account/typeahead" :admin-transaction-rule-account-typeahead
"/test" :admin-transaction-rule-test
"/new" {:get :admin-transaction-rule-new-dialog}
[[#"\d+" :db/id] "/edit"] :admin-transaction-rule-edit-dialog
[[#"\d+" :db/id] "/run"] :admin-transaction-rule-execute-results
}}
"/transaction-rule" tr-routes/routes}
"transaction" {"/insights" {"" :transaction-insights
"/table" :transaction-insight-table
["/code/" [#"\d+" :transaction-id]] {:post :transaction-insight-code}