Makes reports page work with new tailwind
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
(ns auto-ap.ssr.components.aside
|
||||
(:require [auto-ap.ssr.svg :as svg]
|
||||
[hiccup2.core :as hiccup]))
|
||||
[hiccup2.core :as hiccup]
|
||||
[bidi.bidi :as bidi]
|
||||
[auto-ap.ssr-routes :as ssr-routes]))
|
||||
|
||||
(defn menu-button- [params & children]
|
||||
[:a (-> params
|
||||
@@ -188,7 +190,9 @@
|
||||
[:ul {:class "space-y-2"}
|
||||
|
||||
[:li
|
||||
(menu-button- {:icon svg/report}
|
||||
(menu-button- {:icon svg/report
|
||||
:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-reports)}
|
||||
"Reports")]
|
||||
[:li
|
||||
(menu-button- {:icon svg/bank}
|
||||
@@ -198,5 +202,8 @@
|
||||
"Vendors")]
|
||||
|
||||
[:li
|
||||
(menu-button- {:icon svg/government-building}
|
||||
"1099 Vendor Info")]])
|
||||
(menu-button- {:icon svg/government-building
|
||||
:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-1099)}
|
||||
"1099 Vendor Info"
|
||||
)]])
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
(defn icon-button- [params & children]
|
||||
(into
|
||||
[:button (update params :class str " inline-flex items-center justify-center bg-white dark:bg-gray-600 items-center p-3 text-sm font-medium border border-gray-300 dark:border-gray-700 text-center text-gray-500 hover:text-gray-800 rounded-lg dark:text-gray-400 dark:hover:text-gray-100")
|
||||
[:div.htmx-indicator.flex.items-center
|
||||
(svg/spinner {:class "inline w-4 h-4 text-white"})]
|
||||
[:div.htmx-indicator-hidden.inline-flex.gap-2.items-center.justify-center (into [:div.h-4.w-4] children)]]))
|
||||
|
||||
(defn a-icon-button- [params & children]
|
||||
(into
|
||||
[:a (update params :class str " inline-flex items-center justify-center bg-white dark:bg-gray-600 items-center p-3 text-sm font-medium border border-gray-300 dark:border-gray-700 text-center text-gray-500 hover:text-gray-800 rounded-lg dark:text-gray-400 dark:hover:text-gray-100")
|
||||
[:div.h-4.w-4 children]]))
|
||||
|
||||
(defn save-button- [params & children]
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
(ns auto-ap.ssr.components.data-grid)
|
||||
(ns auto-ap.ssr.components.data-grid
|
||||
(:require
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components.card :refer [content-card-]]
|
||||
[auto-ap.ssr.components.paginator :refer [paginator-]]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(defn header- [params & rest]
|
||||
(into [:th.px-4.py-3 {:scope "col" :class (:class params)} ] rest))
|
||||
|
||||
|
||||
(defn row- [params & rest]
|
||||
(into [:tr {:class (cond-> "border-b dark:border-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700"
|
||||
|
||||
(:class params) (str " " (:class params)))}] rest))
|
||||
(into [:tr (update params
|
||||
:class str " border-b dark:border-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700")] rest))
|
||||
|
||||
(defn cell- [params & rest]
|
||||
(into [:td.px-4.py-2 {:class (:class params)}] rest))
|
||||
@@ -32,3 +36,50 @@
|
||||
(into
|
||||
[:tbody]
|
||||
rest)])
|
||||
|
||||
(defn data-grid-card- [{:keys [id
|
||||
route
|
||||
title
|
||||
entity-name
|
||||
action-buttons
|
||||
total
|
||||
start
|
||||
per-page
|
||||
flash-id
|
||||
headers
|
||||
rows] :as params}]
|
||||
[:div {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
route
|
||||
:request-method :get)
|
||||
:hx-trigger "clientSelected from:body"
|
||||
:hx-swap "outerHTML swap:300ms"
|
||||
:id id}
|
||||
(content-card-
|
||||
{}
|
||||
[:div {:class "flex flex-col px-4 py-3 space-y-3 lg:flex-row lg:items-center lg:justify-between lg:space-y-0 lg:space-x-4 text-gray-800 dark:text-gray-100"}
|
||||
[:div
|
||||
[:h1.text-2xl.mb-3.font-bold title]
|
||||
[:div {:class "flex items-center flex-1 space-x-4"}
|
||||
[:h5
|
||||
[:span (format "Total %s:" entity-name)]
|
||||
[:span {:class "dark:text-white pl-4"} total]]]]
|
||||
(into [:div {:class "flex flex-col flex-shrink-0 space-y-3 md:flex-row md:items-center lg:justify-end md:space-y-0 md:space-x-3"}
|
||||
]
|
||||
action-buttons)]
|
||||
[:div {:class "overflow-x-auto"}
|
||||
(data-grid- {:headers headers
|
||||
}
|
||||
rows
|
||||
|
||||
)]
|
||||
(paginator- {:start start
|
||||
:end (Math/min (+ start per-page) total)
|
||||
:per-page per-page
|
||||
:total total
|
||||
:a-params (fn [page]
|
||||
{:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
route
|
||||
:request-method :get)
|
||||
"?start=" (* page per-page))
|
||||
:hx-target (str "#" id)
|
||||
:hx-swap "outerHTML show:#app:top"})}))])
|
||||
|
||||
61
src/clj/auto_ap/ssr/components/paginator.clj
Normal file
61
src/clj/auto_ap/ssr/components/paginator.clj
Normal file
@@ -0,0 +1,61 @@
|
||||
(ns auto-ap.ssr.components.paginator)
|
||||
|
||||
(defn bound [x y z]
|
||||
(cond
|
||||
(< z x)
|
||||
x
|
||||
(< y x)
|
||||
x
|
||||
(> y z)
|
||||
z
|
||||
:else
|
||||
y))
|
||||
|
||||
(def elipsis-button
|
||||
[:p {:href "#", :class "flex items-center justify-center px-3 py-2 text-sm leading-tight text-gray-500 bg-white border border-gray-300 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400"} "..."])
|
||||
|
||||
(defn paginator-internal- [{:keys [start per-page end total a-params]}]
|
||||
(let [per-page (or per-page 20)
|
||||
max-buttons 5
|
||||
buttons-before (Math/floor (/ max-buttons 2))
|
||||
total-pages (long (Math/max (long 1) (long (Math/ceil (/ total per-page)))))
|
||||
current-page (long (Math/floor (/ start per-page)))
|
||||
first-page-button (bound 0 (- current-page buttons-before) (- total-pages max-buttons))
|
||||
all-buttons (into [] (for [x (range total-pages)]
|
||||
[:li
|
||||
[:a (-> (a-params x)
|
||||
(update
|
||||
:class #(cond-> %
|
||||
true (str " flex items-center justify-center px-3 py-2 text-sm leading-tight border ")
|
||||
|
||||
(= current-page x)
|
||||
(str " text-primary-600 bg-primary-50 border-primary-300 hover:bg-primary-100 hover:text-primary-700 dark:border-gray-700 dark:bg-gray-700 dark:text-white")
|
||||
|
||||
(not= current-page x)
|
||||
(str " text-gray-500 bg-white border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white")))
|
||||
(assoc :href "#"))
|
||||
(inc x)]]))
|
||||
|
||||
|
||||
last-page-button (Math/min (long total-pages) (long (+ max-buttons first-page-button)))
|
||||
|
||||
extended-last-page-button (when (not= last-page-button total-pages)
|
||||
(list
|
||||
elipsis-button
|
||||
(last all-buttons)))
|
||||
|
||||
extended-first-page-button (when (not= first-page-button 0)
|
||||
(list
|
||||
(first all-buttons)
|
||||
elipsis-button))]
|
||||
[:nav
|
||||
[:ul {:class "inline-flex items-stretch -space-x-px"}
|
||||
extended-first-page-button
|
||||
(apply list (subvec all-buttons first-page-button last-page-button))
|
||||
extended-last-page-button]]))
|
||||
|
||||
(defn paginator- [{:keys [start per-page end total a-params] :as params}]
|
||||
[:nav {:class "flex flex-col items-start justify-between p-4 space-y-3 md:flex-row md:items-center md:space-y-0", :aria-label "Table navigation"}
|
||||
[:span {:class "text-sm font-normal text-gray-500 dark:text-gray-400"}
|
||||
[:span {:class "font-semibold text-gray-900 dark:text-white"} (str (inc start)) "-" (str end) " of " (str total)]]
|
||||
(paginator-internal- params)])
|
||||
Reference in New Issue
Block a user