supports date filter.
This commit is contained in:
@@ -3,36 +3,62 @@
|
|||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[auto-ap.entities.invoice :as invoice]
|
[auto-ap.entities.invoice :as invoice]
|
||||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||||
[auto-ap.views.utils :refer [bind-field date-picker]]))
|
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
|
||||||
|
[cljs-time.core :as t]
|
||||||
|
[re-frame.core :as re-frame]))
|
||||||
|
|
||||||
|
(defn dispatch-change [on-change-event start end]
|
||||||
|
(fn [_]
|
||||||
|
(re-frame/dispatch (into on-change-event [[:start] start]) )
|
||||||
|
(re-frame/dispatch (into on-change-event [[:end] end]))))
|
||||||
|
|
||||||
(defn date-range-filter [{:keys [value on-change-event]}]
|
(defn date-range-filter [{:keys [value on-change-event]}]
|
||||||
[:div.field
|
[:div
|
||||||
[:div.control
|
[:div.field.has-addons
|
||||||
[:div.columns.is-variable.is-1
|
[:p.control [:a.button.is-small {:on-click
|
||||||
[:div.column
|
(dispatch-change on-change-event
|
||||||
[bind-field
|
(date->str (t/minus (local-now) (t/period :days 7)) standard)
|
||||||
[date-picker {:class-name "input is-fullwidth"
|
(date->str (local-now) standard))}
|
||||||
:class "input"
|
"Week" ]]
|
||||||
:format-week-number (fn [] "")
|
[:p.control [:a.button.is-small {:on-click
|
||||||
:previous-month-button-label ""
|
(dispatch-change on-change-event
|
||||||
:placeholder "Start Date mm/dd/yyyy"
|
(date->str (t/minus (local-now) (t/period :months 1)) standard)
|
||||||
:next-month-button-label ""
|
(date->str (local-now) standard))}
|
||||||
:next-month-label ""
|
"Month" ]]
|
||||||
:event on-change-event
|
[:p.control [:a.button.is-small {:on-click
|
||||||
:type "date"
|
(dispatch-change on-change-event
|
||||||
:field [:start]
|
(date->str (t/minus (local-now) (t/period :years 1)) standard)
|
||||||
:subscription value}]]]
|
(date->str (local-now) standard))}
|
||||||
[:div.column.is-narrow " to "]
|
"Year"]]
|
||||||
[:div.column
|
[:p.control [:a.button.is-small {:on-click
|
||||||
[bind-field
|
(dispatch-change on-change-event
|
||||||
[date-picker {:class-name "input is-fullwidth"
|
nil
|
||||||
:class "input"
|
nil)}
|
||||||
:format-week-number (fn [] "")
|
"All"]]]
|
||||||
:previous-month-button-label ""
|
[:div.field.has-addons
|
||||||
:placeholder "Start Date mm/dd/yyyy"
|
[:div.control
|
||||||
:next-month-button-label ""
|
[bind-field
|
||||||
:event on-change-event
|
[date-picker {:class-name "input is-fullwidth"
|
||||||
:next-month-label ""
|
:class "input"
|
||||||
:type "date"
|
:format-week-number (fn [] "")
|
||||||
:field [:end]
|
:previous-month-button-label ""
|
||||||
:subscription value}]]]]]])
|
:placeholder-text "Start"
|
||||||
|
:next-month-button-label ""
|
||||||
|
:next-month-label ""
|
||||||
|
:event on-change-event
|
||||||
|
:type "date"
|
||||||
|
:field [:start]
|
||||||
|
:subscription value}]]]
|
||||||
|
[:div.control
|
||||||
|
[bind-field
|
||||||
|
[date-picker {:class-name "input is-fullwidth"
|
||||||
|
:class "input"
|
||||||
|
:format-week-number (fn [] "")
|
||||||
|
:previous-month-button-label ""
|
||||||
|
:placeholder-text "End"
|
||||||
|
:next-month-button-label ""
|
||||||
|
:event on-change-event
|
||||||
|
:next-month-label ""
|
||||||
|
:type "date"
|
||||||
|
:field [:end]
|
||||||
|
:subscription value}]]]]])
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[cljs-time.format :as format]
|
[cljs-time.format :as format]
|
||||||
[goog.i18n.NumberFormat.Format]
|
[goog.i18n.NumberFormat.Format]
|
||||||
[cljs-time.core :as t])
|
[cljs-time.core :as t]
|
||||||
|
[clojure.string :as str])
|
||||||
(:import
|
(:import
|
||||||
(goog.i18n NumberFormat)
|
(goog.i18n NumberFormat)
|
||||||
(goog.i18n.NumberFormat Format)))
|
(goog.i18n.NumberFormat Format)))
|
||||||
@@ -76,7 +77,10 @@
|
|||||||
|
|
||||||
(defn dispatch-date-change [event]
|
(defn dispatch-date-change [event]
|
||||||
(fn [e g]
|
(fn [e g]
|
||||||
(re-frame/dispatch (conj event (date->str (time/from-default-time-zone (c/from-date e)) standard)))))
|
(re-frame/dispatch (conj event
|
||||||
|
(if (str/blank? e)
|
||||||
|
e
|
||||||
|
(date->str (time/from-default-time-zone (c/from-date e)) standard))))))
|
||||||
|
|
||||||
(defmulti do-bind (fn [a {:keys [type] :as x}]
|
(defmulti do-bind (fn [a {:keys [type] :as x}]
|
||||||
type))
|
type))
|
||||||
@@ -163,7 +167,9 @@
|
|||||||
event (if (keyword? event) [event] event)
|
event (if (keyword? event) [event] event)
|
||||||
selected (get-in subscription field)
|
selected (get-in subscription field)
|
||||||
x (str->date selected standard)
|
x (str->date selected standard)
|
||||||
selected (if (string? selected) (c/to-date (time/to-default-time-zone (time/from-default-time-zone x))) selected )
|
selected (if (string? selected)
|
||||||
|
(c/to-date (time/to-default-time-zone (time/from-default-time-zone x)))
|
||||||
|
selected )
|
||||||
keys (assoc keys
|
keys (assoc keys
|
||||||
:on-change (dispatch-date-change (conj event field))
|
:on-change (dispatch-date-change (conj event field))
|
||||||
:selected selected
|
:selected selected
|
||||||
|
|||||||
Reference in New Issue
Block a user