Add vendor pre-population for bulk code and individual edit forms

- Add vendor-changed HTMX handlers for both bulk code and individual edit
- Pre-populate default account at 100% when vendor is selected and no accounts exist
- Fix render-accounts-section to render from step-params correctly
- Change bulk code vendor-changed from hx-get to hx-post to include form data
- Add routes for vendor-changed endpoints
- Update e2e tests to cover vendor pre-population
- Run lein cljfmt fix across codebase
This commit is contained in:
2026-05-21 14:45:19 -07:00
parent 8bd0cee1b1
commit ba87805d4c
210 changed files with 8694 additions and 9627 deletions

View File

@@ -15,84 +15,77 @@
(defn hourly-changes []
(let [tx-instant-attr (:db/id (dc/pull (dc/db conn) '[:db/id] :db/txInstant))
tx-lookup (->>
(dc/tx-range
(dc/log conn)
(coerce/to-date (time/plus (time/now) (time/hours -24)))
(coerce/to-date (time/now)))
(map (fn extract-tx-instant [tx]
(let [tx-id (->> (:data tx)
(map (fn [d]
(:tx d)))
first)
tx-instant (->> tx
:data
(filter (fn [d]
(and (= (:e d) tx-id)
(= tx-instant-attr (:a d)))))
(map :v)
first)]
tx-instant)))
(group-by (fn hours-ago [d]
(time/in-hours (time/interval (coerce/to-date-time d) (time/now)))
))
)]
tx-lookup (->>
(dc/tx-range
(dc/log conn)
(coerce/to-date (time/plus (time/now) (time/hours -24)))
(coerce/to-date (time/now)))
(map (fn extract-tx-instant [tx]
(let [tx-id (->> (:data tx)
(map (fn [d]
(:tx d)))
first)
tx-instant (->> tx
:data
(filter (fn [d]
(and (= (:e d) tx-id)
(= tx-instant-attr (:a d)))))
(map :v)
first)]
tx-instant)))
(group-by (fn hours-ago [d]
(time/in-hours (time/interval (coerce/to-date-time d) (time/now))))))]
(for [h (range 24)]
(count (tx-lookup h [])))))
(defn page [request]
(base-page
request
(com/page {:nav com/admin-aside-nav
:client-selection (:client-selection request)
:clients (:clients request)
:client (:client request)
:identity (:identity request)}
(com/breadcrumbs {} [:a {:href (bidi/path-for ssr-routes/only-routes :auto-ap.routes.admin/page)}
"Admin"])
[:div.flex.space-x-4
(com/content-card {:class "w-1/4"}
[:div {:class "flex flex-col px-4 py-3 space-y-3"}
[:div
[:h1.text-2xl.mb-3.font-bold "Growth in clients"]
[:div
[:div {:class "w-full h-64"
:id "client-chart"
:data-chart (hx/json {
:labels ["2 years ago" "1 year ago" "today"],
:series [(for [n [2 1 0]
:let [start (time/plus (time/now) (time/years (- n)))]]
(->> (dc/q '[:find (count ?c)
:in $
:where [?c :client/code]]
(dc/as-of (dc/db conn) (coerce/to-date start)))
first
first))]})}]
[:script {:lang "javascript"}
(hiccup/raw
"new Chartist.Bar('#client-chart', JSON.parse(document.getElementById('client-chart').getAttribute('data-chart')))")]]]])
(base-page
request
(com/page {:nav com/admin-aside-nav
:client-selection (:client-selection request)
:clients (:clients request)
:client (:client request)
:identity (:identity request)}
(com/breadcrumbs {} [:a {:href (bidi/path-for ssr-routes/only-routes :auto-ap.routes.admin/page)}
"Admin"])
[:div.flex.space-x-4
(com/content-card {:class "w-1/4"}
[:div {:class "flex flex-col px-4 py-3 space-y-3"}
[:div
[:h1.text-2xl.mb-3.font-bold "Growth in clients"]
[:div
[:div {:class "w-full h-64"
:id "client-chart"
:data-chart (hx/json {:labels ["2 years ago" "1 year ago" "today"],
:series [(for [n [2 1 0]
:let [start (time/plus (time/now) (time/years (- n)))]]
(->> (dc/q '[:find (count ?c)
:in $
:where [?c :client/code]]
(dc/as-of (dc/db conn) (coerce/to-date start)))
first
first))]})}]
[:script {:lang "javascript"}
(hiccup/raw
"new Chartist.Bar('#client-chart', JSON.parse(document.getElementById('client-chart').getAttribute('data-chart')))")]]]])
(com/content-card {:class "w-1/2"}
[:div {:class "flex flex-col px-4 py-3 space-y-3"}
[:div
[:h1.text-2xl.mb-3.font-bold "Changes by hour"]
[:div
[:div {:class "w-full h-64"
:id "changes"
:data-chart (hx/json {
:labels (for [n (range -24 0)]
(format "%d" n)),
:series [(hourly-changes)]})}]
[:script {:lang "javascript"}
(hiccup/raw
"new Chartist.Line('#changes', JSON.parse(document.getElementById('changes').getAttribute('data-chart')))")]]]])]
)
"Admin")
)
(com/content-card {:class "w-1/2"}
[:div {:class "flex flex-col px-4 py-3 space-y-3"}
[:div
[:h1.text-2xl.mb-3.font-bold "Changes by hour"]
[:div
[:div {:class "w-full h-64"
:id "changes"
:data-chart (hx/json {:labels (for [n (range -24 0)]
(format "%d" n)),
:series [(hourly-changes)]})}]
[:script {:lang "javascript"}
(hiccup/raw
"new Chartist.Line('#changes', JSON.parse(document.getElementById('changes').getAttribute('data-chart')))")]]]])])
"Admin"))
(def key->handler
{
:auto-ap.routes.admin/page (wrap-client-redirect-unauthenticated (wrap-admin page))
})
{:auto-ap.routes.admin/page (wrap-client-redirect-unauthenticated (wrap-admin page))})