(ns auto-ap.views.pages.admin.rules.table (:require [auto-ap.subs :as subs] [auto-ap.views.utils :refer [dispatch-event ->$]] [auto-ap.views.pages.admin.rules.form :as form] [auto-ap.views.components.paginator :refer [paginator]] [auto-ap.views.components.sorter :refer [sorted-column]] [re-frame.core :as re-frame])) (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" :cursor "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 "6em"}} ]]] [: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 [:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]))]]]))))