From b1ce23bfcf99b25c66c4b00268f3afd00e5cc304 Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 12 Mar 2025 10:56:16 -0700 Subject: [PATCH] minor cleanup --- src/clj/auto_ap/handler.clj | 2 -- src/clj/auto_ap/ssr/components/aside.clj | 29 ++++++++++++++++------- src/clj/auto_ap/ssr/transaction.clj | 30 +++++++++++++++++++----- src/clj/auto_ap/ssr/ui.clj | 4 ++-- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 5475cd2d..8f02a10b 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -70,8 +70,6 @@ :headers {} :body ""}) -(defn render-index [_] - (response/resource-response "index.html" {:root "public"})) (defn home-handler [{:keys [identity]}] (if identity diff --git a/src/clj/auto_ap/ssr/components/aside.clj b/src/clj/auto_ap/ssr/components/aside.clj index 5256ef9e..8865ac71 100644 --- a/src/clj/auto_ap/ssr/components/aside.clj +++ b/src/clj/auto_ap/ssr/components/aside.clj @@ -96,6 +96,8 @@ "sales" (#{::payment-routes/all-page ::payment-routes/pending-page ::payment-routes/cleared-page ::payment-routes/voided-page} (:matched-route request)) "payments" + (#{::transaction-routes/page ::transaction-routes/approved-page ::transaction-routes/unapproved-page ::transaction-routes/requires-feedback-page :transaction-insights} (:matched-route request)) + "transactions" (#{::ledger-routes/all-page ::ledger-routes/external-page ::ledger-routes/external-import-page ::ledger-routes/balance-sheet ::ledger-routes/cash-flows ::ledger-routes/profit-and-loss} (:matched-route request)) "ledger" :else @@ -255,14 +257,25 @@ (sub-menu- {:selector "transactions" :active? (= "transactions" selected)} - (menu-button- {:href (bidi/path-for ssr-routes/only-routes - ::transaction-routes/all-page)} "All") - (menu-button- {:href (bidi/path-for ssr-routes/only-routes - ::transaction-routes/unapproved-page)} "Unapproved") - (menu-button- {:href (bidi/path-for ssr-routes/only-routes - ::transaction-routes/requires-feedback-page)} "Client Review") - (menu-button- {:href (bidi/path-for ssr-routes/only-routes - ::transaction-routes/approved-page)} "Approved") + (menu-button- {:href (hu/url (bidi/path-for ssr-routes/only-routes + ::transaction-routes/page) + {:date-range "month"}) + :active? (= ::transaction-routes/page (:matched-route request)) + :hx-boost "true"} "All") + (menu-button- {:href (hu/url (bidi/path-for ssr-routes/only-routes + ::transaction-routes/unapproved-page) + {:date-range "month"}) + :active? (= ::transaction-routes/unapproved-page (:matched-route request)) + :hx-boost "true"} "Unapproved") + (menu-button- {:href (hu/url (bidi/path-for ssr-routes/only-routes + ::transaction-routes/requires-feedback-page) + {:date-range "month"}) + :active? (= ::transaction-routes/requires-feedback-page (:matched-route request)) + :hx-boost "true"} "Client Review") + (menu-button- {:href (hu/url (bidi/path-for ssr-routes/only-routes ::transaction-routes/approved-page) + {:date-range "month"}) + :active? (= ::transaction-routes/approved-page (:matched-route request)) + :hx-boost "true"} "Approved") (when (can? (:identity request) {:subject :transaction :activity :insights}) (menu-button- {:href (bidi/path-for ssr-routes/only-routes diff --git a/src/clj/auto_ap/ssr/transaction.clj b/src/clj/auto_ap/ssr/transaction.clj index 9a308144..fbba0ccb 100644 --- a/src/clj/auto_ap/ssr/transaction.clj +++ b/src/clj/auto_ap/ssr/transaction.clj @@ -4,26 +4,27 @@ :refer [add-sorter-fields apply-pagination apply-sort-4 conn merge-query observable-query pull-many]] [auto-ap.graphql.utils :refer [extract-client-ids]] + [auto-ap.logging :as alog] [auto-ap.permissions :refer [wrap-must]] [auto-ap.query-params :refer [wrap-copy-qp-pqp]] - [auto-ap.routes.transactions :as route] [auto-ap.routes.invoice :as invoice-routes] - [auto-ap.routes.payments :as payment-routes] [auto-ap.routes.ledger :as ledger-routes] + [auto-ap.routes.payments :as payment-routes] + [auto-ap.routes.transactions :as route] [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] [auto-ap.ssr-routes :as ssr-routes] [auto-ap.ssr.components :as com] [auto-ap.ssr.components.link-dropdown :refer [link-dropdown]] - [auto-ap.ssr.transaction.edit :as edit] [auto-ap.ssr.grid-page-helper :as helper :refer [wrap-apply-sort]] [auto-ap.ssr.hx :as hx] [auto-ap.ssr.ledger :refer [wrap-ensure-bank-account-belongs]] [auto-ap.ssr.pos.common :refer [date-range-field*]] [auto-ap.ssr.svg :as svg] + [auto-ap.ssr.transaction.edit :as edit] [auto-ap.ssr.utils :refer [apply-middleware-to-all-handlers clj-date-schema - entity-id html-response strip wrap-merge-prior-hx - wrap-schema-enforce]] + entity-id html-response strip wrap-implied-route-param + wrap-merge-prior-hx wrap-schema-enforce]] [auto-ap.time :as atime] [bidi.bidi :as bidi] [clj-time.coerce :as coerce] @@ -119,6 +120,7 @@ (exact-match-id* request)]]) (defn fetch-ids [db {:keys [query-params route-params] :as request}] + (alog/peek ::ROUTE_PARAMS route-params) (let [valid-clients (extract-client-ids (:clients request) (:client-id request) (:client-id query-params) @@ -169,7 +171,11 @@ (merge-query {:query {:in ['?vendor-id] :where ['[?e :transaction/vendor ?vendor-id]]} :args [(:db/id (:vendor args))]}) - + + (:status route-params) +(merge-query {:query {:in ['?status] + :where ['[?e :transaction/approval-status ?status]]} + :args [(:status route-params)]}) (:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c] '[?c :client/name ?sort-client]] @@ -403,6 +409,14 @@ (def page (helper/page-route grid-page)) +(defn wrap-status-from-source [handler] + (fn [{:keys [matched-current-page-route] :as request}] + (let [ request (cond-> request + (= ::route/unapproved-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/unapproved) + (= ::route/approved-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/approved) + (= ::route/requires-feedback-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/requires-feedback) + (= ::route/page matched-current-page-route) (assoc-in [:route-params :status] nil))] + (handler request)))) (def table (helper/table-route grid-page)) (def csv (helper/csv-route grid-page)) @@ -411,6 +425,9 @@ (merge edit/key->handler (apply-middleware-to-all-handlers {::route/page page + ::route/approved-page (-> page (wrap-implied-route-param :status :transaction-approval-status/approved)) + ::route/unapproved-page (-> page (wrap-implied-route-param :status :transaction-approval-status/unapproved)) + ::route/requires-feedback-page (-> page (wrap-implied-route-param :status :transaction-approval-status/requires-feedback)) ::route/table table ::route/csv csv ::route/bank-account-filter bank-account-filter} @@ -419,6 +436,7 @@ (wrap-copy-qp-pqp) (wrap-apply-sort grid-page) (wrap-ensure-bank-account-belongs) + (wrap-status-from-source) (wrap-merge-prior-hx) (wrap-schema-enforce :query-schema query-schema) (wrap-schema-enforce :hx-schema query-schema) diff --git a/src/clj/auto_ap/ssr/ui.clj b/src/clj/auto_ap/ssr/ui.clj index ac804ce4..f8a43ea9 100644 --- a/src/clj/auto_ap/ssr/ui.clj +++ b/src/clj/auto_ap/ssr/ui.clj @@ -42,12 +42,12 @@ [:script {:type "text/javascript", :src "https://cdn.yodlee.com/fastlink/v4/initialize.js", :async "async"}]] [:link {:rel "stylesheet" :href "https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.3.4/dist/css/datepicker.min.css"}] [:script {:type "text/javascript" :src "https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.3.4/dist/js/datepicker-full.min.js"}] - [:script {:src "https://unpkg.com/htmx.org/dist/ext/response-targets.js"}] + [:script {:src "https://unpkg.com/htmx.org/dist/ext/response-targets.js" :defer true}] [:script {:src "https://cdn.jsdelivr.net/npm/date-fns@3.6.0/cdn.min.js" :defer true}] [:script {:src "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js" :integrity "sha512-CQBWl4fJHWbryGE+Pc7UAxWMUMNMWzWxF4SQo9CgkJIN1kx6djDQZjh3Y8SZ1d+6I+1zze6Z7kHXO7q3UyZAWw==" :crossorigin "anonymous" :referrerpolicy "no-referrer"}] [:script {:src "https://unpkg.com/dropzone@5.9.3/dist/min/dropzone.min.js" :defer true}] - [:link {:rel "stylesheet" :href "https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" :type "text/css"}] + [:link {:rel "stylesheet" :href "https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" :type "text/css" :defer true}] [:script {:defer true :src "/js/alpine-vals.js"}] [:script {:defer true :src "https://cdn.jsdelivr.net/npm/@ryangjchandler/alpine-clipboard@2.x.x/dist/alpine-clipboard.js"}] [:script {:defer true :src "https://cdn.jsdelivr.net/npm/@alpinejs/focus@3.x.x/dist/cdn.min.js"}]