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
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[clojure.spec.alpha :as s]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.entities.account :as entity]
|
||||
[auto-ap.views.components.layouts :refer [side-bar]]
|
||||
[auto-ap.views.utils :refer [bind-field dispatch-event]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||
[re-frame.core :as re-frame]))
|
||||
@@ -86,73 +87,74 @@
|
||||
change-event [::forms/change ::form]]
|
||||
|
||||
^{:key (:id account)}
|
||||
[form {:title (if (:id account)
|
||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
||||
[form {:title (if (:id account)
|
||||
"Edit account"
|
||||
"Add account")}
|
||||
|
||||
[field "Account Set"
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/account-set}]]
|
||||
|
||||
[field "Account Set"
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/account-set}]]
|
||||
|
||||
|
||||
[field "Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}]]
|
||||
|
||||
[field "Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}]]
|
||||
|
||||
|
||||
[field "Name"
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name}]]
|
||||
[field "Name"
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name}]]
|
||||
|
||||
|
||||
[field-holder "Account Type"
|
||||
[:div.select
|
||||
[raw-field
|
||||
[:select {:type "select"
|
||||
:field :type
|
||||
:spec (set types)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]
|
||||
|
||||
|
||||
[field "Location"
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location}]]
|
||||
|
||||
[:h2.subtitle "Client"]
|
||||
[field-holder "Applicability"
|
||||
[:div.select
|
||||
[raw-field
|
||||
[:select {:type "select"
|
||||
:field :applicability
|
||||
:spec (set applicabilities)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)]]]]
|
||||
[field-holder "Customizations"
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
^{:key (count (:client-overrides account))} ;; resets after adding
|
||||
|
||||
[field-holder "Account Type"
|
||||
[:div.select
|
||||
[raw-field
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
||||
:match->text :name
|
||||
:type "typeahead"
|
||||
:field [:new-client-override :client]}]]]
|
||||
[:p.control
|
||||
[raw-field
|
||||
[:input.input {:type "text"
|
||||
:placeholder "Bubblegum"
|
||||
:field [:new-client-override :name]}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-client-override])} "Add"]]]]
|
||||
[:ul
|
||||
(for [client-override (:client-overrides account)]
|
||||
^{:key (:name client-override)}
|
||||
[:li (:name (:client client-override)) "-" (:name client-override)])]
|
||||
[error-notification]
|
||||
[:select {:type "select"
|
||||
:field :type
|
||||
:spec (set types)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]
|
||||
|
||||
[submit-button "Save"]]))
|
||||
|
||||
[field "Location"
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location}]]
|
||||
|
||||
[:h2.subtitle "Client"]
|
||||
[field-holder "Applicability"
|
||||
[:div.select
|
||||
[raw-field
|
||||
[:select {:type "select"
|
||||
:field :applicability
|
||||
:spec (set applicabilities)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)]]]]
|
||||
[field-holder "Customizations"
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
^{:key (count (:client-overrides account))} ;; resets after adding
|
||||
[raw-field
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
||||
:match->text :name
|
||||
:type "typeahead"
|
||||
:field [:new-client-override :client]}]]]
|
||||
[:p.control
|
||||
[raw-field
|
||||
[:input.input {:type "text"
|
||||
:placeholder "Bubblegum"
|
||||
:field [:new-client-override :name]}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-client-override])} "Add"]]]]
|
||||
[:ul
|
||||
(for [client-override (:client-overrides account)]
|
||||
^{:key (:name client-override)}
|
||||
[:li (:name (:client client-override)) "-" (:name client-override)])]
|
||||
[error-notification]
|
||||
|
||||
[submit-button "Save"]]]))
|
||||
|
||||
@@ -136,8 +136,7 @@
|
||||
(defn admin-rules-page []
|
||||
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::form/form])]
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}
|
||||
[:<>
|
||||
[side-bar/rule-side-bar]]]
|
||||
[side-bar/rule-side-bar]]
|
||||
:main [rules-content]
|
||||
:right-side-bar [appearing-side-bar {:visible? active?}
|
||||
[form/form {:rule-saved [::edit-completed]}]]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(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.utils :refer [dispatch-event ->$ with-user action-cell-width]]
|
||||
[auto-ap.views.pages.admin.rules.form :as form]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
@@ -133,7 +133,7 @@
|
||||
:sort-name "Note"}
|
||||
"Note"]
|
||||
|
||||
[grid/header-cell {:style {:width (str (inc (* 3 44)) "px")}}]]]
|
||||
[grid/header-cell {:style {:width (action-cell-width 3)}}]]]
|
||||
[grid/body
|
||||
(for [{:keys [client bank-account description amount-lte amount-gte note id] :as r} transaction-rules]
|
||||
^{:key id}
|
||||
|
||||
Reference in New Issue
Block a user