diff --git a/resources/public/js/htmx-disable.js b/resources/public/js/htmx-disable.js index 2920025f..97af300b 100644 --- a/resources/public/js/htmx-disable.js +++ b/resources/public/js/htmx-disable.js @@ -16,3 +16,7 @@ htmx.defineExtension('disable-submit', { */ } }) + +initDatepicker = function(elem) { +elem.dp = new Datepicker(elem, {format: "mm/dd/yyyy", autohide: true}); +} \ No newline at end of file diff --git a/src/clj/auto_ap/ssr/components/inputs.clj b/src/clj/auto_ap/ssr/components/inputs.clj index 3b069941..e9c9fc38 100644 --- a/src/clj/auto_ap/ssr/components/inputs.clj +++ b/src/clj/auto_ap/ssr/components/inputs.clj @@ -1,4 +1,5 @@ -(ns auto-ap.ssr.components.inputs) +(ns auto-ap.ssr.components.inputs + (:require [hiccup2.core :as hiccup])) (defn select- [params & children] (into @@ -37,13 +38,17 @@ ]) (defn date-input- [{:keys [size] :as params}] - [:input - (-> params - (update - :class str " bg-gray-50 border border-gray-300 text-gray-900 rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500") - (assoc :type "date") - (update :class #(str % (use-size size))) - (dissoc :size))]) + [:div + [:input + (-> params + (update + :class str " bg-gray-50 border border-gray-300 text-gray-900 rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500") + (assoc :type "text") + (assoc "_" (hiccup/raw "init initDatepicker(me)")) + (assoc "hx-on" (hiccup/raw "changeDate: htmx.trigger(this, \"change\") + htmx:beforeCleanupElement: this.dp.destroy()")) + (update :class #(str % (use-size size))) + (dissoc :size))]]) (defn field- [params & rest] (into diff --git a/src/clj/auto_ap/ssr/grid_page_helper.clj b/src/clj/auto_ap/ssr/grid_page_helper.clj index e444144f..480dbc46 100644 --- a/src/clj/auto_ap/ssr/grid_page_helper.clj +++ b/src/clj/auto_ap/ssr/grid_page_helper.clj @@ -9,8 +9,6 @@ [cemerick.url :as url] [clojure.string :as str] [auto-ap.ssr.svg :as svg] - [unilog.context :as lc] - [com.brunobonacci.mulog :as mu] [auto-ap.time :as atime] [clj-time.core :as time])) @@ -181,23 +179,23 @@ (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)) + :start-date (atime/unparse-local (time/plus (time/now) (time/days -7)) atime/normal-date) + :end-date (atime/unparse-local (time/now) atime/normal-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)) + :start-date (atime/unparse-local (time/plus (time/now) (time/months -1)) atime/normal-date) + :end-date (atime/unparse-local (time/now) atime/normal-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)) + :start-date (atime/unparse-local (time/plus (time/now) (time/years -1)) atime/normal-date) + :end-date (atime/unparse-local (time/now) atime/normal-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)) + :start-date (atime/unparse-local (time/plus (time/now) (time/years -3)) atime/normal-date) + :end-date (atime/unparse-local (time/now) atime/normal-date)) query-params)) diff --git a/src/clj/auto_ap/ssr/pos/sales_orders.clj b/src/clj/auto_ap/ssr/pos/sales_orders.clj index 24b95c91..77391e53 100644 --- a/src/clj/auto_ap/ssr/pos/sales_orders.clj +++ b/src/clj/auto_ap/ssr/pos/sales_orders.clj @@ -8,12 +8,10 @@ [auto-ap.ssr.grid-page-helper :as helper] [auto-ap.ssr.svg :as svg] [auto-ap.time :as atime] - [bidi.bidi :as bidi] - [clj-time.coerce :as coerce])) + [bidi.bidi :as bidi])) ;; TODO refunds ;; TODO expected deposits -;; TODO loading screen ;; always should be fast ;; make params parsing composable @@ -30,17 +28,27 @@ ] [:div.flex.space-x-1.items-baseline (com/date-input {:name "start-date" - :value (:start-date (:parsed-query-params params)) + :value (some-> params + :parsed-query-params + :start-date + (atime/parse atime/normal-date) + (atime/unparse-local + atime/normal-date)) :placeholder "Date" :size :small}) (com/date-input {:name "end-date" - :value (:end-date (:parsed-query-params params)) + :value (some-> params + :parsed-query-params + :end-date + (atime/parse atime/normal-date) + (atime/unparse-local + atime/normal-date)) :placeholder "Date" :size :small})]] )]) (defn filters [params] - [:form {"hx-trigger" "change delay:500ms, keyup from:.hot-filter delay:1000ms" + [:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms" "hx-get" (bidi/path-for ssr-routes/only-routes :pos-sales-table) "hx-target" "#sales-table" @@ -125,11 +133,11 @@ :date-range {:start (some-> args :parsed-query-params :start-date - (atime/parse atime/iso-date)) + (atime/parse atime/normal-date)) :end (some-> args :parsed-query-params :end-date - (atime/parse atime/iso-date))} + (atime/parse atime/normal-date))} :total-gte (some-> args :raw-query-params (get "total-gte") not-empty (#(if (string? %) (Double/parseDouble %) (double %)))) :total-lte (some-> args :raw-query-params (get "total-lte") not-empty (#(if (string? %) (Double/parseDouble %) (double %)))) :type-name (condp = (:payment-method (:parsed-query-params args)) @@ -146,11 +154,11 @@ :nav (com/main-aside-nav) :page-specific-nav filters :id-fn :db/id - :fetch-page (fn [user args] + :fetch-page (fn [_ args] (d-sales/get-graphql (args->graphql-params args))) :oob-render - (fn [user params] + (fn [_ params] [(assoc-in (date-range-field* params) [1 :hx-swap-oob] true)]) :breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes :company)} @@ -162,7 +170,7 @@ :title "Sales orders" :entity-name "Sales orders" :route :pos-sales-table - :action-buttons (fn [user args] + :action-buttons (fn [_ args] (let [{:keys [total tax]} (d-sales/summarize-graphql (args->graphql-params args))] [ (com/pill {:color :primary} @@ -171,17 +179,10 @@ (com/pill {:color :secondary} (format "Tax $%.2f" tax ) )])) - :row-buttons (fn [user e] - + :row-buttons (fn [_ e] (when (:sales-order/reference-link e) [(com/a-icon-button {:href (:sales-order/reference-link e)} - svg/external-link) - #_(when (is-admin? user) - (com/icon-button {:hx-delete (str (bidi/path-for ssr-routes/only-routes - :company-reports-delete - :request-method :delete)) - :hx-target "closest tr"} - svg/trash))])) + svg/external-link)])) :headers [ {:key "client" :name "Client" diff --git a/src/clj/auto_ap/ssr/ui.clj b/src/clj/auto_ap/ssr/ui.clj index ff836c55..b10c0e4f 100644 --- a/src/clj/auto_ap/ssr/ui.clj +++ b/src/clj/auto_ap/ssr/ui.clj @@ -21,7 +21,7 @@ [:title (str "Integreat | " page-name)] [:link {:href "/css/font.min.css", :rel "stylesheet"}] [:link {:rel "icon" :type "image/png" :href "/favicon.png"}] - [:link {:rel "stylesheet", :href "/css/react-datepicker.min.inc.css"}] + #_[:link {:rel "stylesheet", :href "/css/react-datepicker.min.inc.css"}] [:link {:rel "stylesheet", :href "/output.css"}] [:script {:src "https://unpkg.com/hyperscript.org@0.9.7/dist/_hyperscript.min.js"}] @@ -35,6 +35,9 @@ [:script {:src "https://unpkg.com/htmx.org/dist/ext/debug.js"}] [:script {:src "/js/htmx-disable.js"}] [:script {:type "text/javascript", :src "https://cdn.yodlee.com/fastlink/v4/initialize.js", :async "async"}]] + [:link {:rel "stylesheet" :href "https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker.min.css"}] + + [:script {:type "text/javascript" :src "https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/js/datepicker-full.min.js"}] [:script {:type "text/javascript", :src "https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/autoComplete.min.js"}] [:script {:src "https://unpkg.com/dropzone@5.9.3/dist/min/dropzone.min.js"}] [:link {:rel "stylesheet" :href "https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" :type "text/css"}]