cleans up grids

This commit is contained in:
2024-11-18 19:41:54 -08:00
parent ad06418a69
commit a8c7c7eb8e
31 changed files with 842 additions and 714 deletions

View File

@@ -1,47 +1,39 @@
(ns auto-ap.ssr.admin.accounts
(:require
[auto-ap.datomic
:refer [add-sorter-fields
apply-pagination
apply-sort-3
audit-transact
conn
merge-query
pull-attr
pull-many
query2]]
[auto-ap.query-params :as query-params]
:refer [add-sorter-fields apply-pagination apply-sort-3 audit-transact
conn merge-query pull-attr pull-many query2]]
[auto-ap.query-params :as query-params :refer [wrap-copy-qp-pqp]]
[auto-ap.routes.utils
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
[auto-ap.solr :as solr]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.form-cursor :as fc]
[auto-ap.ssr.grid-page-helper :as helper]
[auto-ap.ssr.grid-page-helper :as helper :refer [wrap-apply-sort]]
[auto-ap.ssr.hx :as hx]
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.payments :refer [wrap-status-from-source]]
[auto-ap.ssr.svg :as svg]
[auto-ap.ssr.utils
:refer [apply-middleware-to-all-handlers
entity-id
field-validation-error
form-validation-error
html-response
main-transformer
many-entity
modal-response
ref->enum-schema
ref->select-options
strip
temp-id
wrap-entity
wrap-form-4xx-2
:refer [apply-middleware-to-all-handlers clj-date-schema
default-grid-fields-schema entity-id field-validation-error
form-validation-error html-response main-transformer many-entity
modal-response ref->enum-schema ref->select-options strip temp-id
wrap-entity wrap-form-4xx-2 wrap-merge-prior-hx
wrap-schema-enforce]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[datomic.api :as dc]
[malli.core :as mc]))
(def query-schema (mc/schema
[:maybe
(into [:map {:date-range [:date-range :start-date :end-date]}
[:type {:optional true} [:maybe (ref->enum-schema "account-type")]]
[:name {:optional true} [:maybe [:string {:decode/string strip}]]]
[:code {:optional true} [:maybe nat-int?]]]
default-grid-fields-schema)]))
(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
@@ -54,7 +46,7 @@
(com/text-input {:name "name"
:id "name"
:class "hot-filter"
:value (:name (:parsed-query-params request))
:value (:name (:query-params request))
:placeholder "Cash"
:size :small}))
@@ -62,12 +54,13 @@
(com/text-input {:name "code"
:id "code"
:class "hot-filter"
:value (:code (:parsed-query-params request))
:value (:code (:query-params request))
:placeholder "11101"
:size :small}))
(com/field {:label "Type"}
(com/radio-card {:size :small
:name "type"
:value (:type (:query-params request))
:options [{:value ""
:content "All"}
{:value "dividend"
@@ -99,7 +92,7 @@
:db/id]}])
(defn fetch-ids [db request]
(let [query-params (:parsed-query-params request)
(let [query-params (:query-params request)
query (cond-> {:query {:find []
:in '[$]
:where '[]}
@@ -127,10 +120,8 @@
(some->> query-params :type)
(merge-query {:query {:find []
:in ['?rir]
:where ['[?e :account/type ?r]
'[?r :db/ident ?ri]
'[(name ?ri) ?rir] ]}
:in ['?r]
:where ['[?e :account/type ?r] ]}
:args [(some->> query-params :type)]})
true
@@ -161,9 +152,6 @@
:nav com/admin-aside-nav
:page-specific-nav filters
:fetch-page fetch-page
:parse-query-params (comp
(query-params/parse-key :code query-params/parse-long)
(helper/default-parse-query-params grid-page))
:action-buttons (fn [_]
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-account-new-dialog))
@@ -183,6 +171,7 @@
"Accounts"]]
:title "Accounts"
:entity-name "Account"
:query-schema query-schema
:route :admin-account-table
:headers [{:key "code"
:name "Code"
@@ -431,25 +420,31 @@
(def key->handler
(apply-middleware-to-all-handlers
(->>
{:admin-accounts (helper/page-route grid-page)
:admin-account-table (helper/table-route grid-page)
:admin-account-client-override-new (-> new-client-override
(wrap-schema-enforce :query-schema [:map
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
:admin-account-save (-> account-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (wrap-entity account-dialog [:form-params :db/id] default-read)))
:admin-account-edit-dialog (-> account-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]]))
:admin-account-new-dialog account-dialog})
(fn [h]
(-> h
(wrap-admin)
(wrap-client-redirect-unauthenticated)))))
(apply-middleware-to-all-handlers
(->>
{:admin-accounts (helper/page-route grid-page)
:admin-account-table (helper/table-route grid-page)
:admin-account-client-override-new (-> new-client-override
(wrap-schema-enforce :query-schema [:map
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
:admin-account-save (-> account-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (wrap-entity account-dialog [:form-params :db/id] default-read)))
:admin-account-edit-dialog (-> account-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]]))
:admin-account-new-dialog account-dialog})
(fn [h]
(-> h
(wrap-copy-qp-pqp)
(wrap-apply-sort grid-page)
(wrap-merge-prior-hx)
(wrap-status-from-source)
(wrap-schema-enforce :query-schema query-schema)
(wrap-schema-enforce :hx-schema query-schema)
(wrap-admin)
(wrap-client-redirect-unauthenticated)))))