From b5ab8603151067f0c922f62e1af1b761e38c8eda Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 10 Aug 2018 22:52:53 -0700 Subject: [PATCH] more viewing from UI. --- src/clj/auto_ap/datomic/clients.clj | 1 + src/clj/auto_ap/datomic/vendors.clj | 16 ++++++++++ src/clj/auto_ap/graphql.clj | 29 +++++++++---------- src/cljs/auto_ap/events.cljs | 4 +-- .../views/components/vendor_dialog.cljs | 12 ++++---- .../auto_ap/views/pages/admin/vendors.cljs | 1 - 6 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 src/clj/auto_ap/datomic/vendors.clj diff --git a/src/clj/auto_ap/datomic/clients.clj b/src/clj/auto_ap/datomic/clients.clj index c1479d29..54662d65 100644 --- a/src/clj/auto_ap/datomic/clients.clj +++ b/src/clj/auto_ap/datomic/clients.clj @@ -3,6 +3,7 @@ [auto-ap.datomic :refer [uri]])) (defn get-all [] + (->> (d/q '[:find (pull ?e [*]) :where [?e :client/name]] (d/db (d/connect uri))) diff --git a/src/clj/auto_ap/datomic/vendors.clj b/src/clj/auto_ap/datomic/vendors.clj new file mode 100644 index 00000000..900a2c71 --- /dev/null +++ b/src/clj/auto_ap/datomic/vendors.clj @@ -0,0 +1,16 @@ +(ns auto-ap.datomic.vendors + (:require [datomic.api :as d] + [auto-ap.datomic :refer [uri]])) + +(defn get-all [] + + (->> (d/q '[:find (pull ?e [*]) + :where [?e :vendor/name]] + (d/db (d/connect uri))) + (map first) + #_(map (fn [c] + (update c :client/bank-accounts + (fn [bas] + (map (fn [ba] + (update ba :bank-account/type :db/ident )) + bas))))))) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 180c1cfd..769abba8 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -12,6 +12,7 @@ [auto-ap.db.vendors :as vendors] [auto-ap.db.companies :as companies] [auto-ap.datomic.clients :as d-clients] + [auto-ap.datomic.vendors :as d-vendors] [auto-ap.db.users :as users] [auto-ap.db.checks :as checks] [auto-ap.routes.checks :as rchecks] @@ -40,6 +41,11 @@ :address {:type :address} :locations {:type '(list String)} :bank_accounts {:type '(list :bank_account)}}} + :contact + {:fields {:id {:type 'String} + :name {:type 'String} + :email {:type 'String} + :phone {:type 'String}}} :bank_account {:fields {:id {:type 'String} @@ -56,20 +62,14 @@ :state {:type 'String} :zip {:type 'String}}} :vendor - {:fields {:id {:type 'Int} + {:fields {:id {:type 'String} :name {:type 'String} :code {:type 'String} :print_as {:type 'String} - :primary_contact {:type 'String} + :primary_contact {:type :contact} + :secondary_contact {:type :contact} :address {:type :address} - :primary_email {:type 'String} - :primary_phone {:type 'String} - - :secondary_contact {:type 'String} - :secondary_email {:type 'String} - :secondary_phone {:type 'String} - :default_expense_account {:type 'Int} :invoice_reminder_schedule {:type 'String}}} @@ -453,10 +453,9 @@ (defn get-company [context args value] (println "GETTING COMPANY" (:id context)) - (doto (->graphql - (filter #(can-see-company? (:id context) %) - (d-clients/get-all))) - println)) + (->graphql + (filter #(can-see-company? (:id context) %) + (d-clients/get-all)))) (defn join-companies [users] (let [companies (by :id (companies/get-all))] @@ -478,7 +477,7 @@ (defn get-vendor [context args value] (->graphql - (vendors/get-all))) + (d-vendors/get-all))) (defn print-checks [context args value] @@ -555,4 +554,4 @@ (query id q nil )) ([id q v] (println "executing graphql query" id q v) - (simplify (execute schema q v {:id id})))) + (time (simplify (execute schema q v {:id id}))))) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index f14a2e72..017c9bc6 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -40,7 +40,7 @@ [:id :name :locations [:bank-accounts [:id :number :check-number :name :type] ] [:address [:street1 :street2 :city :state :zip]]]] [:vendor - [:id :name :default-expense-account :primary-contact :primary-email :primary-phone :secondary-contact :secondary-email :secondary-phone :print-as :invoice-reminder-schedule :code]]]} + [:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]} :on-success [::received-initial]}})))) @@ -56,7 +56,7 @@ :query-obj {:venia/queries [[:company [:id :name [:bank-accounts [:id :number :check-number :name :type]]]] [:vendor - [:id :name :default-expense-account]]]} + [:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]} :on-success [::received-initial]} :db (assoc db :user (assoc user :token token))})) diff --git a/src/cljs/auto_ap/views/components/vendor_dialog.cljs b/src/cljs/auto_ap/views/components/vendor_dialog.cljs index fea46601..4f945896 100644 --- a/src/cljs/auto_ap/views/components/vendor_dialog.cljs +++ b/src/cljs/auto_ap/views/components/vendor_dialog.cljs @@ -80,7 +80,7 @@ [:div.control.has-icons-left [bind-field [:input.input.is-expanded {:type "text" - :field :primary-contact + :field [:primary-contact :name] :spec ::entity/primary-contact :event change-event :subscription vendor}]] @@ -92,7 +92,7 @@ [:i.fa.fa-envelope]] [bind-field [:input.input {:type "email" - :field :primary-email + :field [:primary-contact :email] :spec ::entity/primary-email :event change-event :subscription vendor}]]] @@ -100,7 +100,7 @@ [:div.control.has-icons-left [bind-field [:input.input {:type "phone" - :field :primary-phone + :field [:primary-contact :phone] :spec ::entity/primary-phone :event change-event :subscription vendor}]] @@ -112,7 +112,7 @@ [:div.control.has-icons-left [bind-field [:input.input.is-expanded {:type "text" - :field :secondary-contact + :field [:secondary-contact :name] :spec ::entity/secondary-contact :event change-event :subscription vendor}]] @@ -123,14 +123,14 @@ [:i.fa.fa-envelope]] [bind-field [:input.input {:type "email" - :field :secondary-email + :field [:secondary-contact :email] :spec ::entity/secondary-email :event change-event :subscription vendor}]]] [:div.control.has-icons-left [bind-field [:input.input {:type "phone" - :field :secondary-phone + :field [:secondary-contact :phone] :spec ::entity/secondary-phone :event change-event :subscription vendor}]] diff --git a/src/cljs/auto_ap/views/pages/admin/vendors.cljs b/src/cljs/auto_ap/views/pages/admin/vendors.cljs index d152090d..7e9b4e90 100644 --- a/src/cljs/auto_ap/views/pages/admin/vendors.cljs +++ b/src/cljs/auto_ap/views/pages/admin/vendors.cljs @@ -55,7 +55,6 @@ (vec (concat [dom keys] rest)))) - #_(defn edit-dialog [] (let [editing-vendor (:vendor @(re-frame/subscribe [::subs/admin])) companies-by-id @(re-frame/subscribe [::subs/companies-by-id])]