diff --git a/src/clj/auto_ap/ssr/admin/clients.clj b/src/clj/auto_ap/ssr/admin/clients.clj index 36002d2e..5db650fc 100644 --- a/src/clj/auto_ap/ssr/admin/clients.clj +++ b/src/clj/auto_ap/ssr/admin/clients.clj @@ -6,9 +6,8 @@ [auto-ap.graphql.utils :refer [extract-client-ids]] [auto-ap.logging :as alog] [auto-ap.routes.admin.clients :as route] - [auto-ap.routes.queries :as q] [auto-ap.routes.indicators :as indicators] - [auto-ap.ssr.indicators :as i] + [auto-ap.routes.queries :as q] [auto-ap.routes.utils :refer [wrap-admin wrap-client-redirect-unauthenticated]] [auto-ap.solr :as solr] @@ -19,15 +18,16 @@ [auto-ap.ssr.components :as com] [auto-ap.ssr.components.multi-modal :as mm] [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.hiccup-helper :as hh] [auto-ap.ssr.hx :as hx] + [auto-ap.ssr.indicators :as i] [auto-ap.ssr.svg :as svg] [auto-ap.ssr.utils :refer [apply-middleware-to-all-handlers entity-id - form-validation-error html-response many-entity - modal-response ref->enum-schema strip temp-id wrap-entity - wrap-schema-enforce]] + form-validation-error html-response main-transformer + many-entity modal-response ref->enum-schema strip temp-id + wrap-entity wrap-schema-enforce]] [auto-ap.time :as atime] [bidi.bidi :as bidi] [cheshire.core :as cheshire] @@ -50,6 +50,20 @@ ;; TODO a few bug fixes from slack ;; TOOD check pinecone +(def query-schema (mc/schema + [:maybe [:map + [:sort {:optional true} [:maybe [:any]]] + [:per-page {:optional true :default 25} [:maybe :int]] + [:start {:optional true :default 0} [:maybe :int]] + [:code {:optional true} [:maybe {:decode/string strip} :string]] + [:name {:optional true} [:maybe {:decode/string strip} :string]] + [:group {:optional true} [:maybe {:decode/string strip} :string]] + [:select {:optional true :default "all"} [:maybe + + + [:enum + "" "all" "only-mine"]]] ]])) + (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 @@ -72,7 +86,22 @@ :class "hot-filter" :value (:code (:parsed-query-params request)) :placeholder "BRLC" - :size :small}))]]) + :size :small})) + (com/field {:label "Group"} + (com/text-input {:name "group" + :id "group" + :class "hot-filter" + :value (:group (:parsed-query-params request)) + :placeholder "NTG" + :size :small})) + (com/field {:label "Select"} + (com/radio-card {:size :small + :name "select" + :value (:select (:query-params request)) + :options [{:value "" + :content "All"} + {:value "only-mine" + :content "Only mine"} ]}))]]) (def default-read '[:db/id :client/name @@ -121,8 +150,8 @@ (defn fetch-ids [db request] (let [query-params (:parsed-query-params request) - valid-clients (extract-client-ids (:clients request) - (:client request) + valid-clients (extract-client-ids #_(:clients request) + (map first (dc/q '[:find ?c :where [?c :client/code]] (dc/db conn))) (:client-id query-params) (when (:client-code query-params) [:client/code (:client-code query-params)])) @@ -134,6 +163,16 @@ "code" ['[?e :client/code ?sort-code]]} query-params) + (= "only-mine" (:select query-params)) + (merge-query {:query {:in ['?uid] + :where ['[?uid :user/clients ?e]]} + :args [(:db/id (:identity request))]}) + + (:group query-params) + (merge-query {:query {:in ['?g] + :where ['[?e :client/groups ?g]]} + :args [(clojure.string/upper-case (:group query-params))]}) + (not (str/blank? (some-> query-params :code))) (merge-query {:query {:in ['?code] @@ -175,7 +214,8 @@ :nav com/admin-aside-nav :page-specific-nav filters :fetch-page fetch-page - :parse-query-params (helper/default-parse-query-params grid-page) + :parse-query-params (fn [p] + (mc/decode query-schema p main-transformer)) :action-buttons (fn [_] [(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/new-dialog)) :color :primary} @@ -900,8 +940,8 @@ :value (fc/field-value) :options (sort-by second (dc/q '[:find ?ia ?inn - :in $ - :where [?ia :intuit-bank-account/name ?inn] ] + :in $ + :where [?ia :intuit-bank-account/name ?inn]] (dc/db conn)))}))) (fc/with-field :bank-account/use-date-instead-of-post-date? (com/checkbox {:name (fc/field-name) @@ -975,8 +1015,8 @@ ;; todo do date coercion in the input (atime/unparse-local atime/normal-date))})]) [:div#days-indicator - (i/days-ago* (some-> (fc/field-value))) ]]) - + (i/days-ago* (some-> (fc/field-value)))]]) + (fc/with-field :bank-account/include-in-reports (com/checkbox {:name (fc/field-name) @@ -1085,7 +1125,7 @@ ;; todo do date coercion in the input (atime/unparse-local atime/normal-date))})]) [:div#days-indicator - (i/days-ago* (some-> (fc/field-value))) ]]) + (i/days-ago* (some-> (fc/field-value)))]]) (fc/with-field :bank-account/include-in-reports (com/checkbox {:name (fc/field-name) @@ -1093,7 +1133,7 @@ :checked (fc/field-value)} "Include in reports")) - [:div + [:div (fc/with-field :bank-account/visible (com/checkbox {:name (fc/field-name) :value (boolean (fc/field-value)) @@ -1863,5 +1903,7 @@ (mm/wrap-wizard client-wizard))} (fn [h] (-> h + (wrap-apply-sort grid-page) + (wrap-schema-enforce :query-schema query-schema) (wrap-admin) - (wrap-client-redirect-unauthenticated))))) \ No newline at end of file + (wrap-client-redirect-unauthenticated)))))