progress towards sales.

This commit is contained in:
2023-09-26 14:30:21 -07:00
parent 94ef7ebf03
commit 160c289f03
12 changed files with 299 additions and 73 deletions

View File

@@ -10,7 +10,9 @@
[clojure.string :as str]
[auto-ap.ssr.svg :as svg]
[unilog.context :as lc]
[com.brunobonacci.mulog :as mu]))
[com.brunobonacci.mulog :as mu]
[auto-ap.time :as atime]
[clj-time.core :as time]))
(defn row* [gridspec user entity {:keys [flash? delete-after-settle? params] :as options}]
(let [cells (->> gridspec
@@ -72,15 +74,16 @@
[entities total] ((:fetch-page grid-spec)
user
params)]
(com/data-grid-card {:id (:id grid-spec)
:title (:title grid-spec)
:route (:route grid-spec)
:start start
:per-page per-page
:total total
:subtitle [:div.flex.items-center.gap-2
[:span (format "Total %s: %d, " (:entity-name grid-spec) total)]
(sort-by-list grid-spec sort)]
:subtitle [:div.flex.items-center.gap-2
[:span (format "Total %s: %d, " (:entity-name grid-spec) total)]
(sort-by-list grid-spec sort)]
:action-buttons ((:action-buttons grid-spec) user params)
:rows (for [entity entities]
(row* grid-spec user entity {:flash? (= flash-id ((:id-fn grid-spec) entity)) :params params}))
@@ -174,9 +177,33 @@
(update :sort sort->query)
(url/map->query)))
(defn use-date-range [query-params date-range]
(condp = date-range
"week"
(assoc query-params
:start-date (atime/unparse-local (time/plus (time/now) (time/days -7)) atime/iso-date)
:end-date (atime/unparse-local (time/now) atime/iso-date))
"month"
(assoc query-params
:start-date (atime/unparse-local (time/plus (time/now) (time/months -1)) atime/iso-date)
:end-date (atime/unparse-local (time/now) atime/iso-date))
"year"
(assoc query-params
:start-date (atime/unparse-local (time/plus (time/now) (time/years -1)) atime/iso-date)
:end-date (atime/unparse-local (time/now) atime/iso-date))
"all"
(assoc query-params
:start-date (atime/unparse-local (time/plus (time/now) (time/years -3)) atime/iso-date)
:end-date (atime/unparse-local (time/now) atime/iso-date))
query-params))
(defn extract-params [grid-spec {:keys [query-params hx-query-params identity session] :as request}]
(let [{hx-start "start" hx-per-page "per-page" hx-sort "sort" } hx-query-params
{q-start "start" q-per-page "per-page" q-sort "sort" q-toggle-sort "toggle-sort" q-remove-sort "remove-sort"} query-params
{q-start "start" q-per-page "per-page" q-sort "sort" q-toggle-sort "toggle-sort" q-remove-sort "remove-sort" date-range "date-range"} query-params
raw-query-params (merge (or hx-query-params {}) query-params)
parsed-query-params (cond-> (into {} (map (fn [[k v]] [(keyword k) v]) raw-query-params))
@@ -184,11 +211,12 @@
q-start (assoc :start (some-> q-start not-empty (Long/parseLong )))
hx-per-page (assoc :per-page (some-> hx-per-page not-empty (Long/parseLong )))
q-per-page (assoc :per-page (some-> q-per-page not-empty (Long/parseLong )))
hx-sort (assoc :sort (doto (parse-sort grid-spec hx-sort) println))
q-sort (assoc :sort (doto (parse-sort grid-spec q-sort) println ))
hx-sort (assoc :sort (parse-sort grid-spec hx-sort))
q-sort (assoc :sort (parse-sort grid-spec q-sort))
(not-empty q-toggle-sort) (update :sort #(toggle-sort grid-spec % q-toggle-sort) )
(not-empty q-remove-sort) (update :sort (fn [s] (filter (comp (complement #{q-remove-sort}) :sort-key) s)) )
true (dissoc :toggle-sort :remove-sort))]
date-range (use-date-range date-range)
true (dissoc :toggle-sort :remove-sort :date-range))]
{:raw-query-params raw-query-params
:parsed-query-params parsed-query-params
:client-selection (:client-selection (:session request))
@@ -202,7 +230,9 @@
grid-spec
identity
params)
:headers {"hx-push-url" (str "?" (params->query-string params))})))
:headers {"hx-push-url" (str "?" (params->query-string params))}
:oob (when-let [oob-render (:oob-render grid-spec)]
(oob-render identity params)))))
(defn page [grid-spec {:keys [identity] :as request}]
(let [params (extract-params grid-spec request)]
@@ -210,7 +240,7 @@
request
(com/page {:nav (:nav grid-spec)
:page-specific (when-let [page-specific-nav (:page-specific-nav grid-spec)]
(page-specific-nav params))
[:div#page-specific-nav (page-specific-nav params)])
:client-selection (:client-selection (:session request))
:clients (:clients request)
:client (:client request)