From c44a36c81575773ceebbf0616bdd12b9f7da41de Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 14 Apr 2019 08:32:24 -0700 Subject: [PATCH] Can edit locations now. --- resources/public/css/main.css | 8 ++++++ .../datomic/migrate/add_general_ledger.clj | 2 +- src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/graphql/accounts.clj | 25 +++++++++++-------- src/cljc/auto_ap/entities/account.cljc | 10 ++++---- src/cljc/auto_ap/entities/shared.cljc | 2 ++ .../auto_ap/views/pages/admin/accounts.cljs | 4 ++- .../views/pages/admin/accounts/form.cljs | 18 +++++++++++-- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/resources/public/css/main.css b/resources/public/css/main.css index dcf4709b..25346710 100644 --- a/resources/public/css/main.css +++ b/resources/public/css/main.css @@ -441,3 +441,11 @@ nav.navbar .navbar-item.is-active { .dropdown.is-fullwidth .dropdown-trigger * { width: 100%; } + + + + +.known-field.location { + width: 5em; + +} diff --git a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj index 4230f88d..e22c16b4 100644 --- a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj +++ b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj @@ -166,7 +166,7 @@ (mapv #(vector %)))] z)) -#_(test-run (bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri))) +#_(test-run (bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri))) #_(test-run (bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri))) #_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))] diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index cfe59bde..e876c4e7 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -423,6 +423,7 @@ {:fields {:id {:type :id} :type {:type :account_type} :numeric_code {:type 'Int} + :location {:type 'String} :account_set {:type 'String} :name {:type 'String}}}} diff --git a/src/clj/auto_ap/graphql/accounts.clj b/src/clj/auto_ap/graphql/accounts.clj index e9340cec..25d71901 100644 --- a/src/clj/auto_ap/graphql/accounts.clj +++ b/src/clj/auto_ap/graphql/accounts.clj @@ -8,7 +8,7 @@ (->graphql (d-accounts/get-accounts (<-graphql args)))) (defn upsert-account [context args value] - (let [{{:keys [id numeric-code account-set name type]} :account} (<-graphql args)] + (let [{{:keys [id numeric-code location account-set name type]} :account} (<-graphql args)] (when-not id (when (seq (d/query {:query {:find ['?e] :in '[$ ?account-set ?numeric-code] @@ -19,17 +19,20 @@ (throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code) {} )))) - (let [ + (let [original (if id (d/entity (d/db (d/connect uri)) id)) result @(d/transact (d/connect uri) - [(remove-nils - {:db/id (or id "new-account") - :account/name name - :account/type (keyword "account-type" (clojure.core/name type)) - :account/account-set account-set - :account/numeric-code (if-not id - numeric-code) - :account/code (if-not id - (str numeric-code))})])] + (cond-> + [(remove-nils + {:db/id (or id "new-account") + :account/name name + :account/type (keyword "account-type" (clojure.core/name type)) + :account/account-set account-set + :account/location location + :account/numeric-code (if-not id + numeric-code) + :account/code (if-not id + (str numeric-code))})] + (and (not location) (:account/location original)) (conj [:db/retract (or id "new-account") :account/location (:account/location original)])))] (->graphql (if id (:account args) diff --git a/src/cljc/auto_ap/entities/account.cljc b/src/cljc/auto_ap/entities/account.cljc index 866ffa28..a28aeb18 100644 --- a/src/cljc/auto_ap/entities/account.cljc +++ b/src/cljc/auto_ap/entities/account.cljc @@ -3,14 +3,14 @@ [clojure.string :as str] [auto-ap.entities.shared :as shared])) -(def numeric-regex #"^[0-9]+$") - (s/def ::account-set string?) -(s/def ::numeric-code (s/or :numericstring? (s/and string? - #(re-matches numeric-regex %)) +(s/def ::numeric-code (s/or :numeric-string? (s/and string? + #(re-matches shared/numeric-regex %)) :numeric? int?)) (s/def ::name string?) +(s/def ::location (s/nilable (s/and string? + #(re-matches shared/only-upper-case %)))) (s/def ::type #{:dividend :expense :asset :liability :equities :revenue}) -(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type])) +(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type ::location])) diff --git a/src/cljc/auto_ap/entities/shared.cljc b/src/cljc/auto_ap/entities/shared.cljc index b2363b46..8f5ea165 100644 --- a/src/cljc/auto_ap/entities/shared.cljc +++ b/src/cljc/auto_ap/entities/shared.cljc @@ -4,6 +4,8 @@ (def date-regex #"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}") (def money-regex #"\-?[0-9]+(\.[0-9]{1,2})?$") +(def numeric-regex #"^[0-9]+$") +(def only-upper-case #"^[A-Z]+$") (s/def ::identifier (s/nilable string?)) (s/def ::date (s/and string? #(re-matches date-regex %))) diff --git a/src/cljs/auto_ap/views/pages/admin/accounts.cljs b/src/cljs/auto_ap/views/pages/admin/accounts.cljs index f690500c..17771398 100644 --- a/src/cljs/auto_ap/views/pages/admin/accounts.cljs +++ b/src/cljs/auto_ap/views/pages/admin/accounts.cljs @@ -28,14 +28,16 @@ [:th "Code"] [:th "Name"] [:th "Type"] + [:th "Location"] [:th {:style {:width "5em"}}]]] [:tbody - (for [{:keys [id numeric-code name type] :as account} (sort-by :numeric-code accounts)] + (for [{:keys [id numeric-code name type location] :as account} (sort-by :numeric-code accounts)] ^{:key id} [:tr [:td numeric-code] [:td name] [:td type] + [:td location] [:td [:a.button {:on-click (dispatch-event [::account-form/editing account])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])]) (defn admin-accounts-content [] diff --git a/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs b/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs index 73ebe875..ec8205fc 100644 --- a/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/accounts/form.cljs @@ -16,9 +16,12 @@ (re-frame/reg-sub ::account-request :<- [::forms/form ::form] - (fn [{{:keys [id type numeric-code name account-set]} :data}] + (fn [{{:keys [id location type numeric-code name account-set]} :data}] {:id id :type (keyword type) + :location (if (clojure.string/blank? location) + nil + location) :numeric-code numeric-code :name name :account-set account-set})) @@ -47,7 +50,7 @@ :operation/name "UpsertAccount"} :venia/queries [{:query/data [:upsert-account {:account @(re-frame/subscribe [::account-request])} - [:id :type :name :account-set :numeric-code]]}]} + [:id :type :name :account-set :numeric-code :location]]}]} :on-success [::edited edit-completed] :on-error [::forms/save-error ::form]}})))) @@ -112,6 +115,17 @@ (map (fn [l] [:option {:value (name l)} (str/capitalize (name l))]) types)]]]]] + + [:div.field + [:p.help "Location"] + [:div.control + [bind-field + [:input.input.known-field.location {:type "text" + :field :location + :spec ::entity/location + :event change-event + :subscription account}]]]] + (when error [:div.notification.is-warning.animated.fadeInUp error])