Virtual pagination for accounts page
This commit is contained in:
@@ -3,44 +3,69 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.utils :refer [replace-by]]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[auto-ap.views.utils :refer [dispatch-event action-cell-width]]
|
||||
[auto-ap.views.components.layouts
|
||||
:refer
|
||||
[appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.accounts.form :as account-form]
|
||||
[re-frame.core :as re-frame]))
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.components.buttons :as buttons]))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::edit-completed
|
||||
(fn [db [_ edit-account]]
|
||||
(-> db
|
||||
(update :accounts replace-by :id edit-account))))
|
||||
(update :accounts replace-by :id (assoc edit-account :class "live-added")))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::params-changed
|
||||
(fn [db [_ p]]
|
||||
(assoc db ::params p)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db ::params)))
|
||||
|
||||
(defn accounts-table [{:keys [accounts]}]
|
||||
[:div
|
||||
(for [[account-set accounts] (group-by :account-set accounts)]
|
||||
^{:key (or account-set "blank")}
|
||||
[:div
|
||||
[:h2.title.is-4 account-set]
|
||||
[:table.table.compact.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Code"]
|
||||
[:th "Name"]
|
||||
[:th "Type"]
|
||||
[:th "Location"]
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
(for [{:keys [id numeric-code name type location] :as account} (sort-by :numeric-code accounts)]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td numeric-code]
|
||||
[:td name]
|
||||
[:td type]
|
||||
[:td location]
|
||||
[:td [:a.button {:on-click (dispatch-event [::account-form/editing
|
||||
account
|
||||
[::edit-completed]])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])])
|
||||
(let [status @(re-frame/subscribe [::status/single ::page])
|
||||
opc (fn [p]
|
||||
(re-frame/dispatch [::params-changed p]))
|
||||
params @(re-frame/subscribe [::params])]
|
||||
|
||||
[:div
|
||||
(for [[account-set full-accounts] (group-by :account-set accounts)
|
||||
:let [full-accounts (sort-by :numeric-code full-accounts)
|
||||
accounts (grid/virtual-paginate (:start params 0) full-accounts )]]
|
||||
^{:key (or account-set "blank")}
|
||||
[:div
|
||||
[:h2.title.is-4 account-set]
|
||||
[grid/grid {:status status
|
||||
:on-params-change opc
|
||||
:params params
|
||||
:column-count 5}
|
||||
[grid/controls (grid/virtual-paginate-controls (:start params) full-accounts)]
|
||||
[grid/table {:fullwidth true}
|
||||
[grid/header
|
||||
[grid/row {}
|
||||
[grid/header-cell {} "Code"]
|
||||
[grid/header-cell {} "Name"]
|
||||
[grid/header-cell {} "Type"]
|
||||
[grid/header-cell {} "Location"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 1)}} ]]]
|
||||
[grid/body
|
||||
(for [{:keys [id numeric-code name type location class] :as account} accounts]
|
||||
^{:key id}
|
||||
[grid/row {:class (:class account)}
|
||||
[grid/cell {} numeric-code]
|
||||
[grid/cell {} name]
|
||||
[grid/cell {} type]
|
||||
[grid/cell {} location]
|
||||
[grid/cell {}
|
||||
[buttons/fa-icon {:event [::account-form/editing account [::edit-completed]]
|
||||
:icon "fa-pencil"}]]])]]]])]))
|
||||
|
||||
(defn admin-accounts-content []
|
||||
[:div
|
||||
|
||||
Reference in New Issue
Block a user