cleans up grids
This commit is contained in:
@@ -1,45 +1,31 @@
|
||||
(ns auto-ap.ssr.users
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields
|
||||
apply-pagination
|
||||
apply-sort-3
|
||||
conn
|
||||
merge-query
|
||||
pull-attr
|
||||
pull-many
|
||||
query2]]
|
||||
[auto-ap.query-params :as query-params]
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query
|
||||
pull-attr pull-many query2]]
|
||||
[auto-ap.query-params :as query-params :refer [wrap-copy-qp-pqp]]
|
||||
[auto-ap.routes.auth :as auth]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[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.svg :as svg]
|
||||
[auto-ap.ssr.utils
|
||||
:refer [apply-middleware-to-all-handlers
|
||||
entity-id
|
||||
html-response
|
||||
main-transformer
|
||||
many-entity
|
||||
modal-response
|
||||
ref->enum-schema
|
||||
ref->select-options
|
||||
wrap-entity
|
||||
wrap-form-4xx-2
|
||||
wrap-schema-enforce]]
|
||||
:refer [apply-middleware-to-all-handlers default-grid-fields-schema
|
||||
entity-id html-response main-transformer many-entity
|
||||
modal-response ref->enum-schema ref->select-options wrap-entity
|
||||
wrap-form-4xx-2 wrap-merge-prior-hx wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[buddy.sign.jwt :as jwt]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as dc]
|
||||
[malli.core :as mc]
|
||||
[auto-ap.logging :as alog]))
|
||||
[malli.core :as mc]))
|
||||
|
||||
(defn filters [request]
|
||||
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
|
||||
@@ -53,7 +39,7 @@
|
||||
(com/text-input {:name "name"
|
||||
:id "name"
|
||||
:class "hot-filter"
|
||||
:value (:name (:parsed-query-params request))
|
||||
:value (:name (:query-params request))
|
||||
:placeholder "Johnny Testerson"
|
||||
:size :small}))
|
||||
|
||||
@@ -63,7 +49,7 @@
|
||||
:url (bidi/path-for ssr-routes/only-routes
|
||||
:company-search)
|
||||
:id (str "client-search")
|
||||
:value (:client (:parsed-query-params request))
|
||||
:value (:client (:query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn :client/name}))
|
||||
|
||||
@@ -71,13 +57,14 @@
|
||||
(com/text-input {:name "email"
|
||||
:id "email"
|
||||
:class "hot-filter"
|
||||
:value (:name (:parsed-query-params request))
|
||||
:value (:name (:query-params request))
|
||||
:placeholder "hello@friend.com"
|
||||
:size :small}))
|
||||
|
||||
(com/field {:label "Role"}
|
||||
(com/radio-card {:size :small
|
||||
:name "role"
|
||||
:value (:role (:query-params request))
|
||||
:options [{:value ""
|
||||
:content "All"}
|
||||
{:value "admin"
|
||||
@@ -93,6 +80,13 @@
|
||||
{:value "none"
|
||||
:content "None"}]}))]])
|
||||
|
||||
(def query-schema (mc/schema
|
||||
[:maybe
|
||||
(into [:map {}
|
||||
[:role {:optional true} [:maybe (ref->enum-schema "user-role")]]
|
||||
[:client {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :client/name]}]]] ]
|
||||
default-grid-fields-schema)]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:user/name
|
||||
:user/email
|
||||
@@ -103,7 +97,7 @@
|
||||
:user/clients [:client/code :db/id :client/locations :client/name]}])
|
||||
|
||||
(defn fetch-ids [db request]
|
||||
(let [query-params (:parsed-query-params request)
|
||||
(let [query-params (:query-params request)
|
||||
query (cond-> {:query {:find []
|
||||
:in '[$ ]
|
||||
:where '[]}
|
||||
@@ -121,16 +115,16 @@
|
||||
(merge-query {:query {:find []
|
||||
:in ['?ns]
|
||||
:where ['[?e :user/name ?sn]
|
||||
'[(clojure.string/upper-case ?sn) ?upper-sn]
|
||||
'[(clojure.string/includes? ?upper-sn ?ns)]]}
|
||||
'[(clojure.string/upper-case ?sn) ?upper-sn]
|
||||
'[(clojure.string/includes? ?upper-sn ?ns)]]}
|
||||
:args [(str/upper-case (:name query-params))]})
|
||||
|
||||
(some->> query-params :email not-empty)
|
||||
(merge-query {:query {:find []
|
||||
:in ['?es]
|
||||
:where ['[?e :user/email ?se]
|
||||
'[(clojure.string/upper-case ?se) ?upper-se]
|
||||
'[(clojure.string/includes? ?upper-se ?es)]]}
|
||||
'[(clojure.string/upper-case ?se) ?upper-se]
|
||||
'[(clojure.string/includes? ?upper-se ?es)]]}
|
||||
:args [(str/upper-case (:email query-params))]})
|
||||
|
||||
(some->> query-params :client :db/id)
|
||||
@@ -142,8 +136,7 @@
|
||||
(some->> query-params :role)
|
||||
(merge-query {:query {:find []
|
||||
:in ['?r]
|
||||
:where ['[?e :user/role ?r]
|
||||
'[?r :db/ident ?ri]]}
|
||||
:where ['[?e :user/role ?r] ]}
|
||||
:args [(some->> query-params :role)]})
|
||||
|
||||
|
||||
@@ -200,19 +193,12 @@
|
||||
(com/pill {:color :white}
|
||||
(format "%d more" remainder))))])
|
||||
|
||||
(defn parse-client [client]
|
||||
(let [client-id (Long/parseLong client)]
|
||||
(dc/pull (dc/db conn) '[:client/name :db/id] client-id)))
|
||||
|
||||
(def grid-page
|
||||
(helper/build {:id "user-table"
|
||||
:nav com/admin-aside-nav
|
||||
:page-specific-nav filters
|
||||
:fetch-page fetch-page
|
||||
:parse-query-params (comp
|
||||
(query-params/parse-key :role #(query-params/parse-keyword "user-role" %))
|
||||
(query-params/parse-key :client parse-client)
|
||||
(helper/default-parse-query-params grid-page))
|
||||
:row-buttons (fn [request entity]
|
||||
[(com/button {:hx-post (str (bidi/path-for ssr-routes/only-routes
|
||||
:user-impersonate))
|
||||
@@ -231,6 +217,7 @@
|
||||
:title "Users"
|
||||
:entity-name "User"
|
||||
:route :user-table
|
||||
:query-schema query-schema
|
||||
:headers [{:key "name"
|
||||
:name "Name"
|
||||
:sort-key "name"
|
||||
@@ -396,5 +383,10 @@
|
||||
:params-schema (mc/schema [:map [:db/id entity-id]])))}
|
||||
(fn [h]
|
||||
(-> h
|
||||
(wrap-copy-qp-pqp)
|
||||
(wrap-apply-sort grid-page)
|
||||
(wrap-merge-prior-hx)
|
||||
(wrap-schema-enforce :query-schema query-schema)
|
||||
(wrap-schema-enforce :hx-schema query-schema)
|
||||
(wrap-admin)
|
||||
(wrap-client-redirect-unauthenticated)))))
|
||||
|
||||
Reference in New Issue
Block a user