greatly simplifying how states are handled.
This commit is contained in:
@@ -24,7 +24,8 @@
|
||||
|
||||
:else
|
||||
nil)]
|
||||
(log/info "csv type was determined to be" csv-type)))
|
||||
(log/info "csv type was determined to be" csv-type)
|
||||
csv-type))
|
||||
|
||||
(defmulti parse-csv
|
||||
determine
|
||||
|
||||
@@ -207,6 +207,7 @@
|
||||
|
||||
(defn import-uploaded-invoice [client forced-location forced-vendor imports]
|
||||
(lc/with-context {:area "upload-invoice"}
|
||||
(log/info "Number of invoices to import is" (count imports) "sample: " (first imports))
|
||||
(let [clients (d-clients/get-all)
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier account-number total date vendor-code text full-text] :as info}]
|
||||
|
||||
@@ -481,6 +482,7 @@
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(catch Exception e
|
||||
(log/warn e)
|
||||
{:status 500
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
|
||||
@@ -162,6 +162,9 @@
|
||||
(go
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch [::status/loading-multi (:multi owns-state) (:which owns-state)]))
|
||||
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch [::status/loading (:single owns-state)]))
|
||||
(let [headers (if token
|
||||
{"Authorization" (str "Token " token)}
|
||||
{})
|
||||
@@ -195,6 +198,8 @@
|
||||
)]
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch [::status/error-multi (:multi owns-state) (:which owns-state) error]))
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch [::status/error (:single owns-state) error]))
|
||||
(when on-error
|
||||
(->> error
|
||||
(conj on-error)
|
||||
@@ -203,6 +208,8 @@
|
||||
(do
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch [::status/completed-multi (:multi owns-state) (:which owns-state)]))
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch [::status/completed (:single owns-state)]))
|
||||
(->> response
|
||||
:body
|
||||
:data
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
(fn [db [_ multi]]
|
||||
(get-in db [::status multi])))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::single
|
||||
(fn [db [_ single]]
|
||||
(get-in db [::status single])))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::loading-multi
|
||||
[(re-frame/path [::status]) ]
|
||||
@@ -66,3 +71,24 @@
|
||||
|
||||
(defn reset-multi [db multi]
|
||||
(assoc-in db [::status multi] {}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::loading
|
||||
[(re-frame/path [::status]) ]
|
||||
(fn [db [_ single]]
|
||||
(assoc db single {:state :loading
|
||||
:error nil})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::completed
|
||||
[(re-frame/path [::status]) ]
|
||||
(fn [db [_ single which]]
|
||||
(assoc db single {:state nil
|
||||
:error nil})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::error
|
||||
[(re-frame/path [::status]) ]
|
||||
(fn [db [_ single error]]
|
||||
(assoc db single {:state :error
|
||||
:error error})))
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
:enter-class "appear"
|
||||
:exit-class "disappear"}
|
||||
|
||||
(into [:div.test ]
|
||||
(into [:span.test ]
|
||||
(r/children (r/current-component)))]])
|
||||
|
||||
(defn body []
|
||||
@@ -155,26 +155,32 @@
|
||||
(fn [consume]
|
||||
(let [{:strs [column-count status]} (js->clj consume)]
|
||||
(r/as-element
|
||||
(if (:loading status)
|
||||
[:tbody
|
||||
(for [i (range 40)]
|
||||
^{:key i}
|
||||
[:tr
|
||||
(for [x (range column-count)]
|
||||
^{:key x}
|
||||
[:td #_{:col-span column-count}
|
||||
[appearing {:visible? true
|
||||
:timeout 1000
|
||||
:enter-class "appear"
|
||||
:exit-class "disappear"}
|
||||
[:div.test
|
||||
[:div.ph-item
|
||||
[:div.ph-row
|
||||
[:div.ph-col-12.big]]]]]])
|
||||
])]
|
||||
(into [:tbody]
|
||||
(cond (= :loading (:state status))
|
||||
[:tbody
|
||||
(for [i (range 40)]
|
||||
^{:key i}
|
||||
[:tr
|
||||
(for [x (range column-count)]
|
||||
^{:key x}
|
||||
[:td #_{:col-span column-count}
|
||||
[appearing {:visible? true
|
||||
:timeout 1000
|
||||
:enter-class "appear"
|
||||
:exit-class "disappear"}
|
||||
[:div.test
|
||||
[:div.ph-item
|
||||
[:div.ph-row
|
||||
[:div.ph-col-12.big]]]]]])
|
||||
])]
|
||||
(= :error (:state status))
|
||||
[:tbody [:tr [:td.has-text-centered {:col-span column-count}
|
||||
"An unexpected error has occured. "
|
||||
(-> status :error first :message)
|
||||
" Please try refreshing the page."]]]
|
||||
:else
|
||||
(into [:tbody]
|
||||
|
||||
children)))))]))
|
||||
children)))))]))
|
||||
|
||||
(defn sortable-header-cell [{:keys [style class sort-key sort-name asc]}]
|
||||
(let [children (r/children (r/current-component))]
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.utils :refer [replace-by]]
|
||||
[re-frame.core :as re-frame]))
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]))
|
||||
|
||||
;; SUBS
|
||||
|
||||
@@ -54,8 +55,7 @@
|
||||
(-> data
|
||||
:transaction-rule-page
|
||||
(update :transaction-rules (fn [rules]
|
||||
(mapv ungraphql-transaction-rule rules)))))
|
||||
(assoc-in [:status :loading] false))))
|
||||
(mapv ungraphql-transaction-rule rules))))))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::last-params
|
||||
@@ -82,9 +82,10 @@
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
|
||||
(fn [{:keys [db user] ::keys [params] :as cofx} _]
|
||||
{:db (-> db
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::last-params] params))
|
||||
|
||||
:graphql {:token user
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:transaction_rule_page
|
||||
(or params {})
|
||||
[[:transaction-rules default-read]
|
||||
@@ -117,7 +118,7 @@
|
||||
[table/table {:id :transactions
|
||||
:params (re-frame/subscribe [::params])
|
||||
:rule-page (re-frame/subscribe [::page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:status @(re-frame/subscribe [::status/single ::page])
|
||||
:on-params-change (fn [params]
|
||||
(println "CHANGING PARAMS TO" params)
|
||||
(re-frame/dispatch [::params-change params]))}]
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
states @(re-frame/subscribe [::status/multi ::run])]
|
||||
[grid/grid {:on-params-change opc
|
||||
:params @(re-frame/subscribe [::table-params])
|
||||
:status @status
|
||||
:status status
|
||||
:column-count 6}
|
||||
[grid/controls {:start start :end end :count count :total total}]
|
||||
[grid/table {:fullwidth true }
|
||||
@@ -124,5 +124,5 @@
|
||||
|
||||
(defn table [params]
|
||||
(r/create-class {:component-will-unmount (dispatch-event [::unmounted])
|
||||
:reagent-render (fn []
|
||||
:reagent-render (fn [params]
|
||||
[table* params])}))
|
||||
|
||||
Reference in New Issue
Block a user