diff --git a/src/clj/auto_ap/parse/csv.clj b/src/clj/auto_ap/parse/csv.clj index 6c1adc36..b1c8529b 100644 --- a/src/clj/auto_ap/parse/csv.clj +++ b/src/clj/auto_ap/parse/csv.clj @@ -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 diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 74427f5b..328e4b7b 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -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) diff --git a/src/cljs/auto_ap/effects.cljs b/src/cljs/auto_ap/effects.cljs index 86f38a61..a9ac0c88 100644 --- a/src/cljs/auto_ap/effects.cljs +++ b/src/cljs/auto_ap/effects.cljs @@ -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 diff --git a/src/cljs/auto_ap/status.cljs b/src/cljs/auto_ap/status.cljs index 05243e42..74c37f49 100644 --- a/src/cljs/auto_ap/status.cljs +++ b/src/cljs/auto_ap/status.cljs @@ -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}))) diff --git a/src/cljs/auto_ap/views/components/grid.cljs b/src/cljs/auto_ap/views/components/grid.cljs index 8f233061..afe810d6 100644 --- a/src/cljs/auto_ap/views/components/grid.cljs +++ b/src/cljs/auto_ap/views/components/grid.cljs @@ -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))] diff --git a/src/cljs/auto_ap/views/pages/admin/rules.cljs b/src/cljs/auto_ap/views/pages/admin/rules.cljs index 8d934add..e935c0eb 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules.cljs @@ -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]))}] diff --git a/src/cljs/auto_ap/views/pages/admin/rules/table.cljs b/src/cljs/auto_ap/views/pages/admin/rules/table.cljs index a880d8c3..697bf334 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules/table.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules/table.cljs @@ -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])}))