Can edit locations now.

This commit is contained in:
Bryce Covert
2019-04-14 08:32:24 -07:00
parent 4018d9aa8d
commit c44a36c815
8 changed files with 50 additions and 20 deletions

View File

@@ -441,3 +441,11 @@ nav.navbar .navbar-item.is-active {
.dropdown.is-fullwidth .dropdown-trigger * { .dropdown.is-fullwidth .dropdown-trigger * {
width: 100%; width: 100%;
} }
.known-field.location {
width: 5em;
}

View File

@@ -423,6 +423,7 @@
{:fields {:id {:type :id} {:fields {:id {:type :id}
:type {:type :account_type} :type {:type :account_type}
:numeric_code {:type 'Int} :numeric_code {:type 'Int}
:location {:type 'String}
:account_set {:type 'String} :account_set {:type 'String}
:name {:type 'String}}}} :name {:type 'String}}}}

View File

@@ -8,7 +8,7 @@
(->graphql (d-accounts/get-accounts (<-graphql args)))) (->graphql (d-accounts/get-accounts (<-graphql args))))
(defn upsert-account [context args value] (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-not id
(when (seq (d/query {:query {:find ['?e] (when (seq (d/query {:query {:find ['?e]
:in '[$ ?account-set ?numeric-code] :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) (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) result @(d/transact (d/connect uri)
[(remove-nils (cond->
{:db/id (or id "new-account") [(remove-nils
:account/name name {:db/id (or id "new-account")
:account/type (keyword "account-type" (clojure.core/name type)) :account/name name
:account/account-set account-set :account/type (keyword "account-type" (clojure.core/name type))
:account/numeric-code (if-not id :account/account-set account-set
numeric-code) :account/location location
:account/code (if-not id :account/numeric-code (if-not id
(str numeric-code))})])] 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 (->graphql
(if id (if id
(:account args) (:account args)

View File

@@ -3,14 +3,14 @@
[clojure.string :as str] [clojure.string :as str]
[auto-ap.entities.shared :as shared])) [auto-ap.entities.shared :as shared]))
(def numeric-regex #"^[0-9]+$")
(s/def ::account-set string?) (s/def ::account-set string?)
(s/def ::numeric-code (s/or :numericstring? (s/and string? (s/def ::numeric-code (s/or :numeric-string? (s/and string?
#(re-matches numeric-regex %)) #(re-matches shared/numeric-regex %))
:numeric? int?)) :numeric? int?))
(s/def ::name string?) (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 ::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]))

View File

@@ -4,6 +4,8 @@
(def date-regex #"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}") (def date-regex #"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")
(def money-regex #"\-?[0-9]+(\.[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 ::identifier (s/nilable string?))
(s/def ::date (s/and string? #(re-matches date-regex %))) (s/def ::date (s/and string? #(re-matches date-regex %)))

View File

@@ -28,14 +28,16 @@
[:th "Code"] [:th "Code"]
[:th "Name"] [:th "Name"]
[:th "Type"] [:th "Type"]
[:th "Location"]
[:th {:style {:width "5em"}}]]] [:th {:style {:width "5em"}}]]]
[:tbody [: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} ^{:key id}
[:tr [:tr
[:td numeric-code] [:td numeric-code]
[:td name] [:td name]
[:td type] [:td type]
[:td location]
[:td [:a.button {:on-click (dispatch-event [::account-form/editing account])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])]) [:td [:a.button {:on-click (dispatch-event [::account-form/editing account])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])])
(defn admin-accounts-content [] (defn admin-accounts-content []

View File

@@ -16,9 +16,12 @@
(re-frame/reg-sub (re-frame/reg-sub
::account-request ::account-request
:<- [::forms/form ::form] :<- [::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 {:id id
:type (keyword type) :type (keyword type)
:location (if (clojure.string/blank? location)
nil
location)
:numeric-code numeric-code :numeric-code numeric-code
:name name :name name
:account-set account-set})) :account-set account-set}))
@@ -47,7 +50,7 @@
:operation/name "UpsertAccount"} :operation/name "UpsertAccount"}
:venia/queries [{:query/data [:upsert-account :venia/queries [{:query/data [:upsert-account
{:account @(re-frame/subscribe [::account-request])} {: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-success [::edited edit-completed]
:on-error [::forms/save-error ::form]}})))) :on-error [::forms/save-error ::form]}}))))
@@ -112,6 +115,17 @@
(map (fn [l] (map (fn [l]
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]] [: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 (when error
[:div.notification.is-warning.animated.fadeInUp [:div.notification.is-warning.animated.fadeInUp
error]) error])