graphql updates.
This commit is contained in:
@@ -34,15 +34,19 @@
|
|||||||
:company_id {:type 'Int}
|
:company_id {:type 'Int}
|
||||||
:vendor {:type :vendor
|
:vendor {:type :vendor
|
||||||
|
|
||||||
:resolve :get-vendor}
|
:resolve :get-vendor-for-invoice}
|
||||||
:company {:type :company
|
:company {:type :company
|
||||||
:resolve :get-company}}}}
|
:resolve :get-company-for-invoice}}}}
|
||||||
:queries
|
:queries
|
||||||
{:invoice {:type '(list :invoice)
|
{:invoice {:type '(list :invoice)
|
||||||
:args {:imported {:type 'Boolean}
|
:args {:imported {:type 'Boolean}
|
||||||
:company_id {:type 'Int}}
|
:company_id {:type 'Int}}
|
||||||
|
|
||||||
:resolve :get-invoice}}})
|
:resolve :get-invoice}
|
||||||
|
:company {:type '(list :company)
|
||||||
|
:resolve :get-company}
|
||||||
|
:vendor {:type '(list :vendor)
|
||||||
|
:resolve :get-vendor}}})
|
||||||
|
|
||||||
(defn by [x kf]
|
(defn by [x kf]
|
||||||
(reduce
|
(reduce
|
||||||
@@ -99,23 +103,33 @@
|
|||||||
->graphql
|
->graphql
|
||||||
(invoices/get-graphql (<-graphql args))) extra-context)))
|
(invoices/get-graphql (<-graphql args))) extra-context)))
|
||||||
|
|
||||||
(defn get-vendor [context args value]
|
(defn get-vendor-for-invoice [context args value]
|
||||||
(->graphql
|
(->graphql
|
||||||
(if-let [vendor-cache (:vendor-cache context)]
|
(if-let [vendor-cache (:vendor-cache context)]
|
||||||
(vendor-cache (:vendor_id value))
|
(vendor-cache (:vendor_id value))
|
||||||
(vendors/get-by-id (:vendor_id value)))))
|
(vendors/get-by-id (:vendor_id value)))))
|
||||||
|
|
||||||
(defn get-company [context args value]
|
(defn get-company-for-invoice [context args value]
|
||||||
(->graphql
|
(->graphql
|
||||||
(if-let [company-cache (:company-cache context)]
|
(if-let [company-cache (:company-cache context)]
|
||||||
(company-cache (:company_id value))
|
(company-cache (:company_id value))
|
||||||
(companies/get-by-id (:company_id value)))))
|
(companies/get-by-id (:company_id value)))))
|
||||||
|
|
||||||
|
(defn get-company [context args value]
|
||||||
|
(->graphql
|
||||||
|
(companies/get-all)))
|
||||||
|
|
||||||
|
(defn get-vendor [context args value]
|
||||||
|
(->graphql
|
||||||
|
(vendors/get-all)))
|
||||||
|
|
||||||
(def schema
|
(def schema
|
||||||
(-> integreat-schema
|
(-> integreat-schema
|
||||||
(attach-resolvers {:get-invoice get-invoice
|
(attach-resolvers {:get-invoice get-invoice
|
||||||
:get-vendor get-vendor
|
:get-vendor-for-invoice get-vendor-for-invoice
|
||||||
:get-company get-company})
|
:get-company-for-invoice get-company-for-invoice
|
||||||
|
:get-company get-company
|
||||||
|
:get-vendor get-vendor})
|
||||||
schema/compile))
|
schema/compile))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,11 @@
|
|||||||
{:db (assoc db/default-db
|
{:db (assoc db/default-db
|
||||||
:active-page handler
|
:active-page handler
|
||||||
:user token)
|
:user token)
|
||||||
:http {:method :get
|
:graphql {:token token
|
||||||
:token token
|
:query-obj {:venia/queries [[:company
|
||||||
:uri (str "/api/companies")
|
[:id :name]]]}
|
||||||
:on-success [::received-companies]}}))))
|
|
||||||
|
:on-success [::received-companies]}}))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::toggle-menu
|
::toggle-menu
|
||||||
@@ -32,15 +33,16 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::logged-in
|
::logged-in
|
||||||
(fn [{:keys [db]} [_ token user]]
|
(fn [{:keys [db]} [_ token user]]
|
||||||
{:http {:method :get
|
{:graphql {:token token
|
||||||
:token token
|
:query-obj {:venia/queries [[:company
|
||||||
:uri (str "/api/companies")
|
[:id :name]]]}
|
||||||
:on-success [::received-companies]}
|
|
||||||
|
:on-success [::received-companies]}
|
||||||
:db (assoc db :user (assoc user :token token))}))
|
:db (assoc db :user (assoc user :token token))}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received-companies
|
::received-companies
|
||||||
(fn [db [_ companies]]
|
(fn [db [_ {companies :company}]]
|
||||||
|
|
||||||
(assoc db :companies (reduce (fn [companies company]
|
(assoc db :companies (reduce (fn [companies company]
|
||||||
(assoc companies (:id company) company))
|
(assoc companies (:id company) company))
|
||||||
@@ -50,6 +52,7 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::swap-company
|
::swap-company
|
||||||
(fn [db [_ company]]
|
(fn [db [_ company]]
|
||||||
|
(println company)
|
||||||
(assoc db :company (:id company))))
|
(assoc db :company (:id company))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
|
|||||||
@@ -32,7 +32,8 @@
|
|||||||
[:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)]
|
[:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)]
|
||||||
[:div {:class "navbar-dropdown"}
|
[:div {:class "navbar-dropdown"}
|
||||||
[:a {:class "navbar-item"} "My profile"]
|
[:a {:class "navbar-item"} "My profile"]
|
||||||
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"]
|
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)
|
||||||
|
:on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} "Administration"]
|
||||||
[:hr {:class "navbar-divider"}]
|
[:hr {:class "navbar-divider"}]
|
||||||
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
|
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
|
||||||
[:a.navbar-item {:href login-url} "Login"])]]))
|
[:a.navbar-item {:href login-url} "Login"])]]))
|
||||||
@@ -126,15 +127,15 @@
|
|||||||
:on-click (fn [] (re-frame/dispatch [::events/toggle-menu :company]))}
|
:on-click (fn [] (re-frame/dispatch [::events/toggle-menu :company]))}
|
||||||
[:div.navbar-start
|
[:div.navbar-start
|
||||||
[:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:company :active?]) "is-active"))}
|
[:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:company :active?]) "is-active"))}
|
||||||
[:a {:class "navbar-link login"} "Company: " (if @company (::company/name @company)
|
[:a {:class "navbar-link login"} "Company: " (if @company (:name @company)
|
||||||
"All")]
|
"All")]
|
||||||
[:div {:class "navbar-dropdown"}
|
[:div {:class "navbar-dropdown"}
|
||||||
[:a {:class "navbar-item"
|
[:a {:class "navbar-item"
|
||||||
:on-click (fn [] (re-frame/dispatch [::events/swap-company nil]))
|
:on-click (fn [] (re-frame/dispatch [::events/swap-company nil]))
|
||||||
} "All"]
|
} "All"]
|
||||||
[:hr {:class "navbar-divider"}]
|
[:hr {:class "navbar-divider"}]
|
||||||
(for [{:keys [::company/name] :as company} @companies]
|
(for [{:keys [name id] :as company} @companies]
|
||||||
^{:key name }
|
^{:key id }
|
||||||
[:a {:class "navbar-item"
|
[:a {:class "navbar-item"
|
||||||
:on-click (fn [] (re-frame/dispatch [::events/swap-company company]))
|
:on-click (fn [] (re-frame/dispatch [::events/swap-company company]))
|
||||||
} name])]]]]
|
} name])]]]]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
(js/Dropzone. (reagent/dom-node this)
|
(js/Dropzone. (reagent/dom-node this)
|
||||||
(clj->js {:init (fn []
|
(clj->js {:init (fn []
|
||||||
(.on (js-this) "success" (fn [_ files]
|
(.on (js-this) "success" (fn [_ files]
|
||||||
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
(re-frame/dispatch [::events/view-pending-invoices]))))
|
||||||
:paramName "file"
|
:paramName "file"
|
||||||
:headers {"Authorization" (str "Token " @token)}
|
:headers {"Authorization" (str "Token " @token)}
|
||||||
:url (str "/api/invoices/upload"
|
:url (str "/api/invoices/upload"
|
||||||
|
|||||||
Reference in New Issue
Block a user