Merge branch 'master' of bitbucket.org:brycecovertoperations/integreat

This commit is contained in:
Bryce Covert
2020-05-04 12:01:13 -07:00
6 changed files with 116 additions and 91 deletions

View File

@@ -2,6 +2,7 @@
(:require [auto-ap.events :as events]
[auto-ap.forms :as forms]
[auto-ap.subs :as subs]
[vimsical.re-frame.cofx.inject :as inject]
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
[auto-ap.routes :as routes]
@@ -15,7 +16,7 @@
[auto-ap.utils :refer [replace-by]]
[auto-ap.views.pages.transactions.manual :as manual]
[auto-ap.views.utils :refer [bind-field date->str dispatch-event nf active-when]]
[auto-ap.views.utils :refer [bind-field date->str dispatch-event nf active-when with-user]]
[goog.string :as gstring]
[re-frame.core :as re-frame]
[reagent.core :as reagent]))
@@ -26,52 +27,62 @@
(fn [db]
(-> db ::ledger-page)))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(fn [[last-params client filter-params table-params]]
(println "HERE?")
(let [params (cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= params last-params)
(re-frame/dispatch [::params-change]))
params)))
(re-frame/reg-event-fx
::params-change
(fn [cofx [_]]
(let [new-params @(re-frame/subscribe [::params])]
(when (not= (::last-params (:db cofx)) new-params)
{:db (-> (:db cofx)
(assoc-in [::last-params] new-params)
(assoc-in [:status :loading] true))
:graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:ledger-page
new-params
[[:journal-entries [:id
:source
:amount
:note
:cleared-against
[:vendor
[:name :id]]
[:client
[:name :id]]
[:line-items
[:id :debit :credit :location
[:account [:id]]]]
:date]]
:total
:start
:end]]]}
:on-success [::received]}}))))
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [user ::params db]} [_]]
(println "execute")
{:db (-> db
(assoc-in [::last-params] params)
(assoc-in [:status :loading] true))
:graphql {:token user
:query-obj {:venia/queries [[:ledger-page
params
[[:journal-entries [:id
:source
:amount
:note
:cleared-against
[:vendor
[:name :id]]
[:client
[:name :id]]
[:line-items
[:id :debit :credit :location
[:account [:id]]]]
:date]]
:total
:start
:end]]]}
:on-success [::received]}}))
(re-frame/reg-event-fx
::unmounted
(fn [{:keys [db]} _]
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::ledger-page)}))
(re-frame/reg-event-db
::received
(fn [db [_ data]]
@@ -85,21 +96,19 @@
[:div
[:h1.title "Ledger"]
[table/table {:id :ledger
:params (re-frame/subscribe [::params])
:ledger-page (re-frame/subscribe [::ledger-page])
:status (re-frame/subscribe [::subs/status])
:on-params-change (fn [params]
(re-frame/dispatch [::params-change params]))}]
:status (re-frame/subscribe [::subs/status])}]
[manual/modal {:import-completed [::manual-import-completed ]}]]))
(defn ledger-page []
(reagent/create-class
{:display-name "ledger-page"
:component-did-mount #(re-frame/dispatch [::params-change {}])
:component-will-unmount #(re-frame/dispatch [::unmounted])
:reagent-render
(fn []
[side-bar-layout
{:side-bar [ledger-side-bar]
:main [ledger-content]}])}))
(let [params @(re-frame/subscribe [::params])]
[side-bar-layout
{:side-bar [ledger-side-bar]
:main [ledger-content]}]))}))

View File

@@ -35,8 +35,7 @@
[which val] (if (= 3 (count params))
[(into [a] b) c]
[[a] b])]
{:dispatch [:auto-ap.views.pages.ledger/params-change]
:db (assoc-in db (into [::filters] which) val)})))
{:db (assoc-in db (into [::filters] which) val)})))
(defn ledger-side-bar []
(let [ap @(re-frame/subscribe [::subs/active-page])

View File

@@ -16,8 +16,7 @@
::params-changed
[(re-frame/path [::table-params])]
(fn [{table-params :db} [_ params :as z]]
{:db (merge table-params params)
:dispatch [:auto-ap.views.pages.ledger/params-change]}))
{:db (merge table-params params)}))
(defn table [{:keys [id ledger-page status vendors check-boxes checked on-check-changed expense-event]}]
(fn [{:keys [id ledger-page status vendors checked status?]

View File

@@ -28,17 +28,25 @@
(fn [db]
(-> db ::payment-page)))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(re-frame/dispatch [::params-change])
(cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(fn [[last-params client filter-params table-params]]
(let [params (cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= last-params params)
(re-frame/dispatch [::params-change]))
params)))
(re-frame/reg-event-fx
::params-change
@@ -104,11 +112,9 @@
:status (re-frame/subscribe [::subs/status])
:void-event [::void-check]}]]))
(defn payments-page []
(reagent/create-class
{:display-name "payments-page"
:component-did-mount #(re-frame/dispatch [::params-change {}])
:component-will-unmount #(re-frame/dispatch [::unmounted])
:reagent-render
(fn []

View File

@@ -48,34 +48,41 @@
(fn [db]
(-> db ::transaction-page)))
(re-frame/reg-sub
::last-params
(fn [db]
(::last-params db)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(re-frame/dispatch [::params-change])
(cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(fn [[last-params client filter-params table-params]]
(let [params (cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= last-params params)
(re-frame/dispatch [::params-change]))
params)))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [user db ] ::keys [params]} _]
(when (not= (::last-params db) params)
{:db (-> db
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token user
:query-obj {:venia/queries [[:transaction_page
params
[[:transactions transaction-read]
:total
:start
:end]]]}
:on-success [::received]}})))
{:db (-> db
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token user
:query-obj {:venia/queries [[:transaction_page
params
[[:transactions transaction-read]
:total
:start
:end]]]}
:on-success [::received]}}))
(re-frame/reg-event-fx
::unapprove-all
@@ -148,7 +155,6 @@
(defn transactions-page [{:keys [approval-status]}]
(reagent/create-class
{:display-name "transaction-page"
:component-did-mount #(re-frame/dispatch [::params-change {}])
:component-will-unmount #(re-frame/dispatch [::unmounted])
:reagent-render
(fn []

View File

@@ -65,17 +65,26 @@
(fn [db]
(-> db ::check-results)))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(re-frame/dispatch [::params-change])
(cond-> {:import-status "imported"}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(fn [[last-params client filter-params table-params]]
(let [params (cond-> {:import-status "imported"}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= params last-params)
(println "DISPATCHING" params last-params)
(re-frame/dispatch [::params-change]))
params)))
(re-frame/reg-event-db
::invoice-updated
@@ -84,20 +93,19 @@
[::invoice-page :invoices]
replace-by :id (assoc invoice :class "live-added"))))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{::keys [params] :as cofx} _]
(when (not= params (::last-params (:db cofx)))
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (table/query params )
:on-success [::received]
:on-error [::events/page-failed]}})))
(println "params" params)
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (table/query params )
:on-success [::received]
:on-error [::events/page-failed]}}))
(re-frame/reg-event-fx
::unmounted
@@ -622,13 +630,11 @@
:checked checked
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]]))
(defn unpaid-invoices-page [params]
(r/create-class
{:display-name "invoices-page"
:component-did-mount #(re-frame/dispatch [::params-change])
:component-will-unmount #(re-frame/dispatch [::unmounted])
:reagent-render
(fn []