Periods selector
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -10,6 +10,7 @@
|
||||
[auto-ap.ssr.components.navbar :as navbar]
|
||||
[auto-ap.ssr.components.page :as page]
|
||||
[auto-ap.ssr.components.paginator :as paginator]
|
||||
[auto-ap.ssr.components.periods :as periods]
|
||||
[auto-ap.ssr.components.radio :as radio]
|
||||
[auto-ap.ssr.components.tabs :as tabs]
|
||||
[auto-ap.ssr.components.tags :as tags]))
|
||||
@@ -89,3 +90,5 @@
|
||||
(def paginator paginator/paginator-)
|
||||
(def data-grid-card data-grid/data-grid-card-)
|
||||
|
||||
(def periods-dropdown periods/periods-dropdown-)
|
||||
|
||||
|
||||
@@ -121,17 +121,7 @@
|
||||
:raw? (:raw? grid-spec)
|
||||
:title [:div.flex.gap-2 (if (string? (:title grid-spec))
|
||||
(:title grid-spec)
|
||||
((:title grid-spec) request))
|
||||
(when (:csv-route grid-spec)
|
||||
(com/a-button {:href (hu/url (bidi/path-for ssr-routes/only-routes (:csv-route grid-spec))
|
||||
(dissoc (update (filter-vals #(not (nil? %))
|
||||
(m/encode (:query-schema grid-spec)
|
||||
(:query-params request)
|
||||
main-transformer))
|
||||
"sort" sort->query)
|
||||
"selected" "all-selected"))
|
||||
:color :secondary-light}
|
||||
[:div.w-4.h-4 svg/download]))]
|
||||
((:title grid-spec) request)) ]
|
||||
:route (:route grid-spec)
|
||||
:start start
|
||||
:per-page per-page
|
||||
@@ -150,7 +140,16 @@
|
||||
" selected"]
|
||||
[:div.w-3.h-3
|
||||
(com/link {"@click" "selected=[]; all_selected=false"}
|
||||
svg/x)]])]))
|
||||
svg/x)]])])
|
||||
(:csv-route grid-spec) (cons (com/a-button {:href (hu/url (bidi/path-for ssr-routes/only-routes (:csv-route grid-spec))
|
||||
(dissoc (update (filter-vals #(not (nil? %))
|
||||
(m/encode (:query-schema grid-spec)
|
||||
(:query-params request)
|
||||
main-transformer))
|
||||
"sort" sort->query)
|
||||
"selected" "all-selected"))
|
||||
:color :secondary-light}
|
||||
[:div.w-4.h-4 svg/download])))
|
||||
:rows
|
||||
(let [break-table-fn (some-> grid-spec :break-table ( create-break-table-fn grid-spec))]
|
||||
(for [entity entities
|
||||
|
||||
@@ -152,53 +152,7 @@
|
||||
(fc/with-field :periods
|
||||
(com/validated-inline-field {:label "Periods"
|
||||
:errors (fc/field-errors)}
|
||||
[:div {:x-data (hx/json {:periods (map (fn [p]
|
||||
{:start (atime/unparse-local (:start p) atime/normal-date)
|
||||
:end (atime/unparse-local (:end p) atime/normal-date)})
|
||||
(fc/field-value))
|
||||
:source_date (-> (fc/field-value)
|
||||
first
|
||||
:end
|
||||
(atime/unparse-local atime/normal-date))})
|
||||
|
||||
:x-init "$watch('periods', ds => source_date= ds.length > 0 ? ds[0].end : null)"}
|
||||
[:template {:x-for "(v,n) in periods"}
|
||||
[:div
|
||||
(fc/with-field 0
|
||||
(fc/with-field :start
|
||||
[:input {:type "hidden"
|
||||
":name" "'periods[' + n + '][start]'"
|
||||
:x-model "v.start"}]))
|
||||
(fc/with-field 0
|
||||
(fc/with-field :end
|
||||
[:input {:type "hidden"
|
||||
":name" "'periods[' + n + '][end]'"
|
||||
:x-model "v.end"}]))]]
|
||||
(com/a-button {"x-tooltip.on.click.theme.dropdown.placement.bottom.interactive" "{content: ()=> $refs.tooltip.innerHTML, allowHTML: true, appendTo: $root}"
|
||||
:indicator? false}
|
||||
[:template {:x-if "periods.length == 0"}
|
||||
[:span.text-left.text-gray-400 "None selected"]]
|
||||
[:template { :x-if "periods.length < 3 && periods.length > 0"}
|
||||
[:span.inline-flex.gap-2
|
||||
[:template {:x-for "p in periods"}
|
||||
(com/pill {:color :secondary}
|
||||
[:span {:x-text "p.start"}]
|
||||
" - "
|
||||
[:span {:x-text "p.end"}])]]]
|
||||
[:template {:x-if "periods.length >= 3"}
|
||||
(com/pill {:color :secondary}
|
||||
[:span {:x-text "periods.length"}]
|
||||
" periods selected")]
|
||||
[:div {:class "w-3 h-3 m-1 inline ml-1 justify-self-end text-gray-500 self-center"}
|
||||
svg/drop-down])
|
||||
[:template {:x-ref "tooltip"}
|
||||
[:div.p-4 {:class "bg-gray-100 dark:bg-gray-600 rounded-lg shadow-2xl w-max z-50 ring-1 p-4"}
|
||||
[:div.flex.flex-col.gap-2
|
||||
(com/calendar-input {:placeholder "12/21/2020" :x-model "source_date"})
|
||||
(com/a-button {"@click" "periods=getFourWeekPeriodsPeriods(source_date)"} "13 periods")
|
||||
(com/a-button {"@click" "periods=[calendarYearPeriod(source_date)]"} "Calendar year")
|
||||
(com/a-button {"@click" "periods=[lastYearPeriod(source_date)]"} "Full year")
|
||||
(com/a-button {"@click" "periods=[]"} "Clear")]]]]))
|
||||
(com/periods-dropdown {:value (fc/field-value)})))
|
||||
|
||||
(com/button {:color :primary :class "w-32"}
|
||||
"Run")
|
||||
|
||||
@@ -442,10 +442,10 @@ args
|
||||
:parse-query-params (fn [p]
|
||||
(mc/decode query-schema p main-transformer))
|
||||
:action-buttons (fn [request]
|
||||
[(com/button {:color :primary
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::route/new)}
|
||||
"Add journal entry")])
|
||||
[(when-not (:external? (:route-params request)) (com/button {:color :primary
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::route/new)}
|
||||
"Add journal entry"))])
|
||||
:row-buttons (fn [request entity]
|
||||
[(when (and (= :invoice-status/unpaid (:invoice/status entity))
|
||||
(can? (:identity request) {:subject :invoice :activity :delete}))
|
||||
|
||||
@@ -139,68 +139,7 @@
|
||||
:table table-contents
|
||||
:warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))}))))])
|
||||
|
||||
(defn- periods-dropdown []
|
||||
[:div {:x-data (hx/json {:periods (map (fn [p]
|
||||
{:start (atime/unparse-local (:start p) atime/normal-date)
|
||||
:end (atime/unparse-local (:end p) atime/normal-date)})
|
||||
(fc/field-value))
|
||||
:source_date (-> (fc/field-value)
|
||||
first
|
||||
:end
|
||||
(atime/unparse-local atime/normal-date))})
|
||||
|
||||
:x-init "$watch('periods', ds => source_date= ds.length > 0 ? ds[0].end : null)"}
|
||||
[:template {:x-for "(v,n) in periods"}
|
||||
[:div
|
||||
[:input {:type "hidden"
|
||||
":name" "'periods[' + n + '][start]'"
|
||||
:x-model "v.start"}]
|
||||
[:input {:type "hidden"
|
||||
":name" "'periods[' + n + '][end]'"
|
||||
:x-model "v.end"}]]]
|
||||
(com/a-button {"x-tooltip.on.click.theme.dropdown.placement.bottom.interactive" "{content: ()=> $refs.tooltip.innerHTML, allowHTML: true, appendTo: $root}"
|
||||
:indicator? false}
|
||||
[:template {:x-if "periods.length == 0"}
|
||||
[:span.text-left.text-gray-400 "None selected"]]
|
||||
[:template {:x-if "periods.length < 3 && periods.length > 0"}
|
||||
[:span.inline-flex.gap-2
|
||||
[:template {:x-for "p in periods"}
|
||||
(com/pill {:color :secondary}
|
||||
[:span {:x-text "p.start"}]
|
||||
" - "
|
||||
[:span {:x-text "p.end"}])]]]
|
||||
[:template {:x-if "periods.length >= 3"}
|
||||
(com/pill {:color :secondary}
|
||||
[:span {:x-text "periods.length"}]
|
||||
" periods selected")]
|
||||
[:div {:class "w-3 h-3 m-1 inline ml-1 justify-self-end text-gray-500 self-center"}
|
||||
svg/drop-down])
|
||||
[:template {:x-ref "tooltip"}
|
||||
[:div.p-4.gap-2 {:class "bg-gray-100 dark:bg-gray-600 rounded-lg shadow-2xl w-max z-50 ring-1 p-4 w-[700px] "}
|
||||
[:div.flex.flex-col.gap-2
|
||||
(com/tabs
|
||||
{:tabs [{:name "Quick"
|
||||
:content [:div.flex.flex.gap-2
|
||||
(com/calendar-input {:placeholder "12/21/2020" :x-model "source_date"})
|
||||
[:div.flex.flex-col.gap-2
|
||||
(com/a-button {"@click" "periods=getFourWeekPeriodsPeriods(source_date)"} "13 periods")
|
||||
(com/a-button {"@click" "periods=[calendarYearPeriod(source_date)]"} "Calendar year")
|
||||
(com/a-button {"@click" "periods=getLastMonthPeriods()"} "Last Month")
|
||||
(com/a-button {"@click" "periods=[]"} "Clear")]]}
|
||||
{:name "Advanced"
|
||||
:content [:div.flex.flex-col.gap-2 {:class "max-h-[500px] overflow-scroll"}
|
||||
[:template {:x-for "(p, i) in periods" ":key" "i"}
|
||||
[:div.flex.gap-2
|
||||
(com/text-input { :x-model "p.start" })
|
||||
(com/text-input { :x-model "p.end" })
|
||||
(com/a-icon-button {"@click.prevent.stop" "periods=periods.filter((_, i2) => i !== i2)"} svg/x)]
|
||||
#_(com/pill {:color :secondary}
|
||||
[:span {:x-text "p.start"}]
|
||||
" - "
|
||||
[:span {:x-text "p.end"}])]
|
||||
(com/button {"@click.prevent.stop" "periods.push({start: '', end: ''})" :class "w-32"} "Add new period")
|
||||
]}]
|
||||
:active "Quick"}) ]]]])
|
||||
|
||||
(defn form* [request & children]
|
||||
(let [params (or (:query-params request) {})]
|
||||
@@ -229,7 +168,7 @@
|
||||
(fc/with-field :periods
|
||||
(com/validated-inline-field {:label "Periods"
|
||||
:errors (fc/field-errors)}
|
||||
(periods-dropdown)))
|
||||
(com/periods-dropdown {:value (fc/field-value)})))
|
||||
(fc/with-field :column-per-location
|
||||
(com/toggle {:name (fc/field-name)
|
||||
:checked (fc/field-value)}
|
||||
|
||||
Reference in New Issue
Block a user