a lot of progress towards unification.

This commit is contained in:
Bryce Covert
2019-02-16 18:10:14 -08:00
parent 12eb4bdd41
commit 193a46e12c
7 changed files with 243 additions and 195 deletions

View File

@@ -85,6 +85,7 @@
:uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]} :uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]}
:provided {:dependencies [[org.clojure/clojurescript "1.10.238"] :provided {:dependencies [[org.clojure/clojurescript "1.10.238"]
[reagent "0.7.0" ] [reagent "0.7.0" ]
[cljsjs/react-transition-group "2.4.0-0"]
[re-frame "0.10.2"] [re-frame "0.10.2"]
[com.andrewmcveigh/cljs-time "0.5.2"]]}} [com.andrewmcveigh/cljs-time "0.5.2"]]}}

View File

@@ -602,7 +602,11 @@
([id q v] ([id q v]
(println "executing graphql query" id q v) (println "executing graphql query" id q v)
(try (try
(time (simplify (execute schema q v {:id id}))) (let [result (time (simplify (execute schema q v {:id id})))]
(when (seq (:errors result))
(throw (ex-info "GraphQL error" {:result result})))
result)
(catch Exception e (catch Exception e
(if-let [v (:validation-error (ex-data e))] (if-let [v (:validation-error (ex-data e))]
(println "validation error" v) (println "validation error" v)

View File

@@ -14,7 +14,7 @@
:in ['$ '?code] :in ['$ '?code]
:where ['[?id :client/code ?code]]} :where ['[?id :client/code ?code]]}
:args [(d/db (d/connect uri)) code]})) :args [(d/db (d/connect uri)) code]}))
(throw (ex-info "Client is not unique" {:validation-error "Client is not unique"})))) (throw (ex-info "Client is not unique" {:validation-error (str "Client code '" code "' is not unique.")}))))
(defn edit-client [context {:keys [edit_client new_bank_accounts] :as args} value] (defn edit-client [context {:keys [edit_client new_bank_accounts] :as args} value]
(assert-admin (:id context)) (assert-admin (:id context))

View File

@@ -21,7 +21,15 @@
:body (pr-str (ql/query (:identity r) (query-params "query") variables )) :body (pr-str (ql/query (:identity r) (query-params "query") variables ))
:headers {"Content-Type" "application/edn"}}) :headers {"Content-Type" "application/edn"}})
(catch Exception e (catch Exception e
(if-let [result (:result (ex-data e))]
{:status 400 {:status 400
:body (pr-str {:data (merge {:message (.getMessage e)} (ex-data e))}) :body (pr-str result)
:headers {"Content-Type" "application/edn"}})))) :headers {"Content-Type" "application/edn"}}
(if-let [message (:validation-error (ex-data e) )]
{:status 400
:body (pr-str {:errors [(merge {:message message} (ex-data e))]})
:headers {"Content-Type" "application/edn"}}
{:status 500
:body (pr-str {:errors [(merge {:message (.getMessage e)} (ex-data e))]})
:headers {"Content-Type" "application/edn"}}))))))
wrap-secure)) wrap-secure))

View File

@@ -148,7 +148,7 @@
(when on-error (when on-error
(->> response (->> response
:body :body
:data :errors
(dates->date-times) (dates->date-times)
(conj on-error) (conj on-error)
(re-frame/dispatch))) (re-frame/dispatch)))

View File

@@ -1,5 +1,7 @@
(ns auto-ap.views.components.layouts (ns auto-ap.views.components.layouts
(:require (:require
[cljsjs.react-transition-group]
[reagent.core :as reagent]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
@@ -8,7 +10,8 @@
[auto-ap.views.utils :refer [active-when active-when= login-url dispatch-event]] [auto-ap.views.utils :refer [active-when active-when= login-url dispatch-event]]
[auto-ap.views.components.vendor-dialog :refer [vendor-dialog]])) [auto-ap.views.components.vendor-dialog :refer [vendor-dialog]]))
(def css-transition-group
(reagent/adapt-react-class js/ReactTransitionGroup.CSSTransition))
(defn login-dropdown [] (defn login-dropdown []
(let [user (re-frame/subscribe [::subs/user]) (let [user (re-frame/subscribe [::subs/user])
menu (re-frame/subscribe [::subs/menu])] menu (re-frame/subscribe [::subs/menu])]
@@ -82,7 +85,16 @@
[:a {:class "icon", :href "https://github.com/dansup/bulma-templates"} [:a {:class "icon", :href "https://github.com/dansup/bulma-templates"}
[:i {:class "fa fa-github"}]]]]]]) [:i {:class "fa fa-github"}]]]]]])
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}] (defn appearing-side-bar [{:keys [visible?]} & children ]
(let [final-state (reagent/atom visible?)]
(fn [{:keys [visible?]} & children]
[css-transition-group {:in visible? :class-names {:exitDone "bounce animated" :exit "fadeOutRight animated" :enter "fadeInRight animated"} :timeout 300 :onEnter (fn [] (reset! final-state true )) :onExited (fn [] (reset! final-state false))}
(if (or @final-state visible?)
[:div.aside
[:div.sub-main children]]
[:div])])))
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar right-side-bar-visible?]}]
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
client @(re-frame/subscribe [::subs/client])] client @(re-frame/subscribe [::subs/client])]
[:div [:div
@@ -94,10 +106,7 @@
[:div {:class "column messages hero is-fullheight", :id "message-feed"} [:div {:class "column messages hero is-fullheight", :id "message-feed"}
^{:key (str "active-page-" (:name client))} ^{:key (str "active-page-" (:name client))}
[:div.inbox-messages main]] [:div.inbox-messages main]]
(when right-side-bar [appearing-side-bar {:visible? right-side-bar-visible?} right-side-bar]]
[:aside.fadeInRight.animated {:class "column aside is-narrow menu hero is-fullheight" :style {:animation-duration "0.75s"}}
[:div.sub-main
right-side-bar]])]
[footer] [footer]
bottom bottom
[:div#dz-hidden]])) [:div#dz-hidden]]))

View File

@@ -2,6 +2,7 @@
(:require-macros [cljs.core.async.macros :refer [go]] (:require-macros [cljs.core.async.macros :refer [go]]
[clojure.string :as str]) [clojure.string :as str])
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as str] [clojure.string :as str]
@@ -17,6 +18,15 @@
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
[bidi.bidi :as bidi])) [bidi.bidi :as bidi]))
(re-frame/reg-sub
::loading-class
(fn [db [_ x]]
(if (get-in db [::loading x])
"is-loading"
"")))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::new ::new
(fn [{:keys [db]} [_ client-id]] (fn [{:keys [db]} [_ client-id]]
@@ -35,7 +45,9 @@
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [edited-client (-> (:client @(re-frame/subscribe [::subs/admin])) (let [edited-client (-> (:client @(re-frame/subscribe [::subs/admin]))
(dissoc :location))] (dissoc :location))]
{:db (assoc-in db [:admin :client :saving?] true) {:db (-> db
(assoc-in [::loading ::save-client] true)
(assoc-in [:admin :client :error] nil))
:graphql :graphql
{:token (-> db :user) {:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation :query-obj {:venia/operation {:operation/type :mutation
@@ -56,7 +68,10 @@
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [new-client (-> (:new-client @(re-frame/subscribe [::subs/admin])) (let [new-client (-> (:new-client @(re-frame/subscribe [::subs/admin]))
(dissoc :location))] (dissoc :location))]
{:db (assoc-in db [:admin :client :saving?] true) (if (s/valid? ::entity/client new-client)
{:db (-> db (assoc-in [::loading ::save-client] true)
(assoc-in [:admin :client :error] nil))
:graphql :graphql
{:token (-> db :user) {:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation :query-obj {:venia/operation {:operation/type :mutation
@@ -66,12 +81,14 @@
;; TODO - hard code fields we want ;; TODO - hard code fields we want
(-> new-client (-> new-client
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts new-client))))) (update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts new-client)))))
(dissoc :new-account)
(dissoc :new-bank-accounts)) (dissoc :new-bank-accounts))
} }
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]] [:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]
]}]} ]}]}
:on-success [::save-complete] :on-success [::save-complete]
:on-error [::save-error]}}))) :on-error [::save-error]}}
{:db db}))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save-complete ::save-complete
@@ -81,6 +98,7 @@
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit] {:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
:db (-> db :db (-> db
(assoc-in [:admin :adding-client?] false) (assoc-in [:admin :adding-client?] false)
(assoc-in [::loading ::save-client] nil)
(update :admin dissoc :new-client) (update :admin dissoc :new-client)
@@ -89,10 +107,10 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::save-error ::save-error
(fn [db [_ client]] (fn [db [_ result]]
(-> db (-> db
(assoc-in [:admin :client :saving?] false) (assoc-in [::loading ::save-client] false)
(assoc-in [:admin :client :error] true)))) (assoc-in [:admin :client :error] (:message (first result))))))
(re-frame/reg-event-db (re-frame/reg-event-db
::change ::change
@@ -352,7 +370,8 @@
(defn new-client-form [] (defn new-client-form []
(let [new-client (:new-client @(re-frame/subscribe [::subs/admin]))] (let [new-client (:new-client @(re-frame/subscribe [::subs/admin]))
error (:error (:client @(re-frame/subscribe [::subs/admin])))]
[:div [:div
[:form [:form
[:section.section {:style {:padding-bottom "0.75em" :padding-top "0.75em"}} [:section.section {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
@@ -495,7 +514,7 @@
] ]
[:div.field [:div.field
[:div.control [:div.control
(println (s/explain-data ::entity/bank-account (:new-account new-client))) #_(println (s/explain-data ::entity/bank-account (:new-account new-client)))
[:button.button.is-primary {:disabled (if (and (doto (s/valid? ::entity/bank-account (:new-account new-client)) println) [:button.button.is-primary {:disabled (if (and (doto (s/valid? ::entity/bank-account (:new-account new-client)) println)
(not ((set (map :code (:new-bank-accounts new-client))) (not ((set (map :code (:new-bank-accounts new-client)))
(str (:code new-client) "-" (-> new-client :new-account :code))))) (str (:code new-client) "-" (-> new-client :new-account :code)))))
@@ -516,15 +535,22 @@
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]] ^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]]
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}]) #_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
(println (s/explain-data ::entity/client new-client)) #_(println (s/explain-data ::entity/client new-client))
(when error
[:div.notification.is-warning.animated.fadeInUp
error]
)
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client) [:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client)
"" ""
"disabled") "disabled")
:on-click (dispatch-event [::save-new-client])} "Save"]]])) :on-click (dispatch-event [::save-new-client])
:class (str @(re-frame/subscribe [::loading-class ::save-client]) (when error " animated shake"))} "Save"]]]))
(defn admin-clients-page [] (defn admin-clients-page []
(let [{:keys [adding-client?]} @(re-frame/subscribe [::subs/admin])] (let [{:keys [adding-client?]} @(re-frame/subscribe [::subs/admin])]
[side-bar-layout {:side-bar [admin-side-bar {}] [side-bar-layout {:side-bar [admin-side-bar {}]
:main [admin-clients-content] :main [admin-clients-content]
:right-side-bar (when adding-client? :right-side-bar-visible? adding-client?
[new-client-form])}])) :right-side-bar [new-client-form]}]))