122 lines
5.0 KiB
Clojure
122 lines
5.0 KiB
Clojure
(ns auto-ap.views.pages.admin.rules.table
|
|
(:require [auto-ap.subs :as subs]
|
|
[auto-ap.views.utils :refer [dispatch-event ->$ with-user]]
|
|
[auto-ap.views.pages.admin.rules.form :as form]
|
|
[auto-ap.views.components.paginator :refer [paginator]]
|
|
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
|
[auto-ap.views.components.sorter :refer [sorted-column]]
|
|
[re-frame.core :as re-frame]))
|
|
|
|
(re-frame/reg-event-fx
|
|
::run-clicked
|
|
[with-user]
|
|
(fn [{:keys [user db]} [_ which]]
|
|
{:graphql
|
|
{:token user
|
|
:query-obj {:venia/operation {:operation/type :query
|
|
:operation/name "RunTransactionRule"}
|
|
:venia/queries [{:query/data [:run-transaction-rule
|
|
{:transaction-rule-id (:id which)}
|
|
[:id
|
|
:date
|
|
:amount
|
|
[:client [:name]]
|
|
[:bank-account [:name]]
|
|
:description-original]]}]}
|
|
:on-success [::succeeded-run]
|
|
#_#_:on-error [:forms/save-error ::form]}}))
|
|
|
|
|
|
(re-frame/reg-event-fx
|
|
::succeeded-run
|
|
(fn [{:keys [db]} [_ result]]
|
|
{:dispatch [::results-modal/opening (:run-transaction-rule result) true]}))
|
|
|
|
(defn table [{:keys [id rule-page on-params-change params status]}]
|
|
(let [opc (fn [p]
|
|
(on-params-change (merge @params p )))]
|
|
(fn [{:keys [id rule-page on-params-change params status]}]
|
|
(let [{:keys [sort-by asc]} @params
|
|
{:keys [transaction-rules start end count total]} @rule-page
|
|
selected-client @(re-frame/subscribe [::subs/client])]
|
|
[:div
|
|
[paginator {:start start :end end :count count :total total
|
|
:on-change (fn [p ]
|
|
(on-params-change (merge @params p)))}]
|
|
[:table.table.is-fullwidth.compact
|
|
[:thead
|
|
[:tr
|
|
[sorted-column {:on-sort opc
|
|
:style {:width "25%" :cursor "pointer"}
|
|
:sort-key "client"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"Client"]
|
|
|
|
[sorted-column {:on-sort opc
|
|
:style {:width "25%" :cursor "pointer"}
|
|
:sort-key "bank-account"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"Bank Account"]
|
|
|
|
[sorted-column {:on-sort opc
|
|
:style {:width "25%" :cursor "pointer"}
|
|
:sort-key "description"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"Description"]
|
|
|
|
#_[sorted-column {:on-sort opc
|
|
:style {:width "8em" :cukjsor "pointer"}
|
|
:class "has-text-right"
|
|
:sort-key "amount-gte"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"Amount"]
|
|
[:th.has-text-right {:style {:width "12em"}} "Amount"]
|
|
#_[sorted-column {:on-sort opc
|
|
:class "has-text-right"
|
|
:style {:width "8em" :cursor "pointer"}
|
|
:sort-key "amount-lte"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"<="]
|
|
|
|
[sorted-column {:on-sort opc
|
|
:style {:width "25%" :cursor "pointer"}
|
|
:sort-key "note"
|
|
:sort-by sort-by
|
|
:asc asc}
|
|
"Note"]
|
|
[:th {:style {:width "9em"}}
|
|
]]]
|
|
[:tbody
|
|
(if (:loading @status)
|
|
[:tr
|
|
[:td {:col-span 5}
|
|
[:i.fa.fa-spin.fa-spinner]]]
|
|
(for [{:keys [client bank-account description amount-lte amount-gte note id] :as r} transaction-rules]
|
|
^{:key id}
|
|
[:tr {:class (:class r)}
|
|
[:td (:name client)]
|
|
[:td (:name bank-account)]
|
|
[:td description]
|
|
[:td.has-text-right
|
|
(cond (and amount-gte amount-lte)
|
|
(str (->$ amount-gte) " - " (->$ amount-lte))
|
|
|
|
amount-gte
|
|
(str ">=" (->$ amount-gte))
|
|
|
|
amount-lte
|
|
(str "<=" (->$ amount-lte))
|
|
|
|
:else
|
|
"")]
|
|
[:td note]
|
|
[:td
|
|
[:div.buttons
|
|
[:a.button {:on-click (dispatch-event [::run-clicked r])} [:span.icon [:i.fa.fa-play]]]
|
|
[:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]]))]]]))))
|