Simplifying filters
This commit is contained in:
141
src/cljs/auto_ap/views/pages/transactions/side_bar.cljs
Normal file
141
src/cljs/auto_ap/views/pages/transactions/side_bar.cljs
Normal file
@@ -0,0 +1,141 @@
|
||||
(ns auto-ap.views.pages.transactions.side-bar
|
||||
(:require [auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [active-when]]
|
||||
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
|
||||
[auto-ap.views.components.number-filter :refer [number-filter]]
|
||||
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||
[bidi.bidi :as bidi]
|
||||
[re-frame.core :as re-frame]))
|
||||
(re-frame/reg-sub
|
||||
::filters
|
||||
(fn [db ]
|
||||
(::filters db {})))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::filter
|
||||
:<- [::filters]
|
||||
(fn [filters [_ which]]
|
||||
(filters which)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::filter-params
|
||||
:<- [::filters]
|
||||
:<- [::subs/active-page]
|
||||
(fn [[filters ap]]
|
||||
{:vendor-id (:id (:vendor filters))
|
||||
:date-range (:date-range filters)
|
||||
:bank-account-id (:id (:bank-account filters))
|
||||
:amount-gte (:amount-gte (:amount-range filters))
|
||||
:amount-lte (:amount-lte (:amount-range filters))
|
||||
:description (:settled (:description filters))
|
||||
:approval-status (condp = ap
|
||||
:transactions nil
|
||||
:unapproved-transactions :unapproved
|
||||
:requires-feedback-transactions :requires-feedback
|
||||
:excluded-transactions :excluded
|
||||
:approved-transactions :approved)}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::filter-changed
|
||||
(fn [{:keys [db]} [_ & params]]
|
||||
(let [[a b c] params
|
||||
[which val] (if (= 3 (count params))
|
||||
[(into [a] b) c]
|
||||
[[a] b])]
|
||||
{:dispatch [:auto-ap.views.pages.transactions/params-change]
|
||||
:db (assoc-in db (into [::filters] which) val)})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::description-settled
|
||||
[(re-frame/path [::filters :description])]
|
||||
(fn [{:keys [db]} [_ description]]
|
||||
{:db (assoc db :settled description)
|
||||
:dispatch [::filter-changed :description [:settled] description]}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::description-changed
|
||||
[(re-frame/path [::filters :description])]
|
||||
(fn [{:keys [db]} [_ description]]
|
||||
{:dispatch-debounce
|
||||
{:event [::description-settled description]
|
||||
:time 500
|
||||
:key ::description}
|
||||
:db (assoc db :raw description)}))
|
||||
|
||||
(defn side-bar []
|
||||
(let [ap @(re-frame/subscribe [::subs/active-page])
|
||||
user @(re-frame/subscribe [::subs/user])]
|
||||
[:div
|
||||
[:div [:p.menu-label "Type"]
|
||||
[:ul.menu-list
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :transactions)
|
||||
:class [(active-when ap = :transactions)]}
|
||||
[:span {:class "icon" :style {:font-size "25px"}}]
|
||||
[:span {:class "name"} "All"]]]
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :unapproved-transactions)
|
||||
:class [(active-when ap = :unapproved-transactions)]}
|
||||
[:span {:class "icon icon-task-list-text-1" :style {:font-size "25px"}}]
|
||||
[:span {:class "name"} "Unapproved"]]]
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :requires-feedback-transactions)
|
||||
:class [(active-when ap = :requires-feedback-transactions)]}
|
||||
|
||||
[:span {:class "icon icon-task-list-question" :style {:font-size "25px"}}]
|
||||
|
||||
[:span {:class "name"} "Client Review"]]]
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :approved-transactions)
|
||||
:class [(active-when ap = :approved-transactions)]}
|
||||
|
||||
[:span {:class "icon icon-task-list-check-1" :style {:font-size "25px"}}]
|
||||
|
||||
[:span {:class "name"} "Approved"]]]
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :excluded-transactions)
|
||||
:class [(active-when ap = :excluded-transactions)]}
|
||||
|
||||
[:span {:class "icon icon-task-list-disable" :style {:font-size "25px"}}]
|
||||
|
||||
[:span {:class "name"} "Excluded"]]]
|
||||
]]
|
||||
[:p.menu-label "Bank Account"]
|
||||
[:div
|
||||
[bank-account-filter
|
||||
{:on-change-event [::filter-changed :bank-account]
|
||||
:value @(re-frame/subscribe [::filter :bank-account])
|
||||
:bank-accounts @(re-frame/subscribe [::subs/bank-accounts])}]]
|
||||
|
||||
[:p.menu-label "Date Range"]
|
||||
[:div
|
||||
[date-range-filter
|
||||
{:on-change-event [::filter-changed :date-range]
|
||||
:value @(re-frame/subscribe [::filter :date-range])}]]
|
||||
|
||||
[:p.menu-label "Amount"]
|
||||
[:div
|
||||
[number-filter
|
||||
{:on-change-event [::filter-changed :amount-range]
|
||||
:value @(re-frame/subscribe [::filter :amount-range])}]]
|
||||
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
:on-change #(re-frame/dispatch [::filter-changed :vendor %])
|
||||
:match->text :name
|
||||
:type "typeahead-entity"
|
||||
:value @(re-frame/subscribe [::filter :vendor])}]]
|
||||
|
||||
[:p.menu-label "Description"]
|
||||
[:div
|
||||
[:div.field
|
||||
[:div.control [:input.input {:placeholder "CHECK 123 ABC"
|
||||
:value (:raw @(re-frame/subscribe [::filter :description]))
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::description-changed (.. e -target -value) ]))} ]]]]]))
|
||||
|
||||
@@ -36,102 +36,110 @@
|
||||
:on-success [::editing-matches-found which]
|
||||
:on-error [::editing-matches-failed which]}} ))
|
||||
|
||||
(defn table [{:keys [id transaction-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(let [opc (fn [p]
|
||||
(on-params-change (merge @params p )))]
|
||||
(fn [{:keys [id transaction-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort]} @params
|
||||
{:keys [transactions start end count total]} @transaction-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "25%" "33%")]
|
||||
[:div
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
(re-frame/reg-sub
|
||||
::table-params
|
||||
(fn [db]
|
||||
(::table-params db)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)
|
||||
:dispatch [:auto-ap.views.pages.transactions/params-change]}))
|
||||
|
||||
(defn table [{:keys [id transaction-page status]}]
|
||||
(let [{:keys [sort]} @(re-frame/subscribe [::table-params])
|
||||
{:keys [transactions start end count total]} @transaction-page
|
||||
opc (fn [e] (re-frame/dispatch [::params-changed e]))
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "25%" "33%")]
|
||||
[:div
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change opc}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:class "has-text-right"
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"]
|
||||
[:th {:width percentage-size} "Bank account"]
|
||||
[:th {:style {:width "14em"}} "" ]]]
|
||||
[:tbody
|
||||
(if (:loading @status)
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
(for [{:keys [client account vendor approval-status payment status bank-account description-original date amount id yodlee-merchant ] :as i} (:transactions @transaction-page)]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
[:td (:name client)])
|
||||
[:td (cond vendor
|
||||
(:name vendor)
|
||||
yodlee-merchant
|
||||
[:i.has-text-grey (str "Merchant '" (:name yodlee-merchant) "'")]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:class "has-text-right"
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"]
|
||||
[:th {:width percentage-size} "Bank account"]
|
||||
[:th {:style {:width "14em"}} "" ]]]
|
||||
[:tbody
|
||||
(if (:loading @status)
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
(for [{:keys [client account vendor approval-status payment status bank-account description-original date amount id yodlee-merchant ] :as i} (:transactions @transaction-page)]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td (cond vendor
|
||||
(:name vendor)
|
||||
yodlee-merchant
|
||||
[:i.has-text-grey (str "Merchant '" (:name yodlee-merchant) "'")]
|
||||
|
||||
:else
|
||||
[:i.has-text-grey (str description-original)])]
|
||||
#_[:td description-original]
|
||||
[:td (date->str date) ]
|
||||
[:td.has-text-right (nf amount )]
|
||||
[:td status]
|
||||
[:td (:name bank-account )]
|
||||
[:td.expandable
|
||||
[:div.buttons
|
||||
[drop-down {:id [::expense-accounts id ]
|
||||
:header [:a.button {:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
|
||||
:tab-index "0"}
|
||||
[:span.icon-saving-bank-1]]}
|
||||
[drop-down-contents
|
||||
[:div
|
||||
[:span.dropdown-item description-original ]]]]
|
||||
[:a.button {:on-click (dispatch-event [::intend-to-edit i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
(when payment
|
||||
[:a.tag {:href (:s3-url payment) :target "_new"}
|
||||
#_[:i.fa.fa-money-check]
|
||||
[:span.icon [:i.fa.fa-money]]
|
||||
(str " " (:check-number payment) " (" (gstring/format "$%.2f" amount ) ")")])]]
|
||||
]))]]]))))
|
||||
:else
|
||||
[:i.has-text-grey (str description-original)])]
|
||||
#_[:td description-original]
|
||||
[:td (date->str date) ]
|
||||
[:td.has-text-right (nf amount )]
|
||||
[:td status]
|
||||
[:td (:name bank-account )]
|
||||
[:td.expandable
|
||||
[:div.buttons
|
||||
[drop-down {:id [::expense-accounts id ]
|
||||
:header [:a.button {:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
|
||||
:tab-index "0"}
|
||||
[:span.icon-saving-bank-1]]}
|
||||
[drop-down-contents
|
||||
[:div
|
||||
[:span.dropdown-item description-original ]]]]
|
||||
[:a.button {:on-click (dispatch-event [::intend-to-edit i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
(when payment
|
||||
[:a.tag {:href (:s3-url payment) :target "_new"}
|
||||
#_[:i.fa.fa-money-check]
|
||||
[:span.icon [:i.fa.fa-money]]
|
||||
(str " " (:check-number payment) " (" (gstring/format "$%.2f" amount ) ")")])]]
|
||||
]))]]]))
|
||||
|
||||
Reference in New Issue
Block a user