Another improvement
This commit is contained in:
@@ -12,8 +12,9 @@
|
|||||||
(def money (m/schema [float? {:error/message "Invalid money"}]))
|
(def money (m/schema [float? {:error/message "Invalid money"}]))
|
||||||
(def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"]))
|
(def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"]))
|
||||||
(def code-string (m/schema [:re #"[A-Z0-9\-]+"]))
|
(def code-string (m/schema [:re #"[A-Z0-9\-]+"]))
|
||||||
(def keyword (m/schema [:fn (fn [d]
|
|
||||||
(keyword? d))]))
|
(def positive-integer (m/schema [:int {:min 1}]))
|
||||||
|
(def integer-code (m/schema [:int {:min 10000 :max 99999}]))
|
||||||
|
|
||||||
(def expense-account (m/schema [:map
|
(def expense-account (m/schema [:map
|
||||||
[:id :string]
|
[:id :string]
|
||||||
|
|||||||
@@ -22,14 +22,26 @@
|
|||||||
]
|
]
|
||||||
(r/children (r/current-component))))
|
(r/children (r/current-component))))
|
||||||
|
|
||||||
(defn select-field [{:keys [options allow-nil? class] :as props}]
|
(defn select-field [{:keys [options allow-nil? class on-change keywordize?] :as props}]
|
||||||
[:div.select {:class class}
|
[:div.select {:class class}
|
||||||
[:select (-> props
|
[:select (-> props
|
||||||
(dissoc :allow-nil? :class :options)
|
(dissoc :allow-nil? :class :options)
|
||||||
(update :value (fn [v]
|
(update :value (fn [v]
|
||||||
(if (str/blank? v)
|
(cond (str/blank? v)
|
||||||
""
|
""
|
||||||
v))))
|
|
||||||
|
keywordize?
|
||||||
|
(name v)
|
||||||
|
|
||||||
|
:else
|
||||||
|
v)))
|
||||||
|
(assoc :on-change
|
||||||
|
(fn [e]
|
||||||
|
(println "VALUE IS" (keyword (.. e -target -value)))
|
||||||
|
(if keywordize?
|
||||||
|
(on-change (keyword (.. e -target -value)))
|
||||||
|
(on-change e))))
|
||||||
|
(dissoc :keywordize?))
|
||||||
[:<>
|
[:<>
|
||||||
(when allow-nil?
|
(when allow-nil?
|
||||||
[:option {:value nil}])
|
[:option {:value nil}])
|
||||||
|
|||||||
@@ -73,8 +73,7 @@
|
|||||||
[buttons/new-button {:name "Account"
|
[buttons/new-button {:name "Account"
|
||||||
:class "is-primary"
|
:class "is-primary"
|
||||||
:event [::account-form/editing
|
:event [::account-form/editing
|
||||||
{:type :asset
|
{:account-set "default"}]}]]
|
||||||
:account-set "default"}]}]]
|
|
||||||
[table/accounts-table {:data-page ::page}]])
|
[table/accounts-table {:data-page ::page}]])
|
||||||
|
|
||||||
(defn admin-accounts-page []
|
(defn admin-accounts-page []
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[auto-ap.forms.builder :as form-builder]
|
[auto-ap.forms.builder :as form-builder]
|
||||||
[vimsical.re-frame.cofx.inject :as inject]))
|
[vimsical.re-frame.cofx.inject :as inject]
|
||||||
|
[auto-ap.views.components :as com]
|
||||||
|
[malli.core :as m]
|
||||||
|
[auto-ap.schema :as schema]))
|
||||||
|
|
||||||
(def types [:dividend :expense :asset :liability :equity :revenue])
|
(def types [:dividend :expense :asset :liability :equity :revenue])
|
||||||
(def applicabilities [:global :optional :customized])
|
(def applicabilities [:global :optional :customized])
|
||||||
@@ -35,11 +38,7 @@
|
|||||||
(:name client-override))})
|
(:name client-override))})
|
||||||
client-overrides)}))
|
client-overrides)}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::can-submit
|
|
||||||
:<- [::request]
|
|
||||||
(fn [request]
|
|
||||||
(s/valid? ::entity/account request)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::editing
|
::editing
|
||||||
@@ -58,7 +57,6 @@
|
|||||||
::saving
|
::saving
|
||||||
[with-user (re-frame/inject-cofx ::inject/sub [::request]) ]
|
[with-user (re-frame/inject-cofx ::inject/sub [::request]) ]
|
||||||
(fn [{:keys [user] ::keys [request]} _]
|
(fn [{:keys [user] ::keys [request]} _]
|
||||||
(when @(re-frame/subscribe [::can-submit])
|
|
||||||
(let [_ @(re-frame/subscribe [::forms/form ::form])]
|
(let [_ @(re-frame/subscribe [::forms/form ::form])]
|
||||||
{:graphql
|
{:graphql
|
||||||
{:owns-state {:single ::form}
|
{:owns-state {:single ::form}
|
||||||
@@ -69,81 +67,81 @@
|
|||||||
{:account request}
|
{:account request}
|
||||||
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
|
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
|
||||||
:on-success [::edited]
|
:on-success [::edited]
|
||||||
:on-error [::forms/save-error ::form]}}))))
|
:on-error [::forms/save-error ::form]}})))
|
||||||
|
|
||||||
|
(def account-customization-schema
|
||||||
|
(m/schema
|
||||||
|
[:map [:client schema/reference]
|
||||||
|
[:name schema/not-empty-string]]))
|
||||||
|
|
||||||
|
(def account-schema
|
||||||
|
(m/schema
|
||||||
|
[:map
|
||||||
|
[:numeric-code schema/integer-code]
|
||||||
|
[:name schema/not-empty-string]
|
||||||
|
[:type [:enum :dividend :expense :asset :liability :equity :revenue]]
|
||||||
|
[:location {:optional true} [:maybe :string]]
|
||||||
|
[:applicability [:enum :global :optional :customized]]
|
||||||
|
[:client-overrides {:optional true}
|
||||||
|
[:maybe [:sequential account-customization-schema]]]]))
|
||||||
|
|
||||||
(defn form [_]
|
(defn form [_]
|
||||||
(let [{account :data } @(re-frame/subscribe [::forms/form ::form])]
|
(let [{account :data } @(re-frame/subscribe [::forms/form ::form])]
|
||||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
||||||
[form-builder/builder {:can-submit [::can-submit]
|
[form-builder/builder {:change-event [::forms/change ::form]
|
||||||
:change-event [::forms/change ::form]
|
|
||||||
:submit-event [::saving]
|
:submit-event [::saving]
|
||||||
:id ::form}
|
:id ::form
|
||||||
|
:schema account-schema}
|
||||||
[form-builder/section {:title (if (:id account)
|
[form-builder/section {:title (if (:id account)
|
||||||
"Edit account"
|
"Edit account"
|
||||||
"Add account")}
|
"Add account")}
|
||||||
[form-builder/field
|
[form-builder/field-v2 {:field :numeric-code}
|
||||||
"Account Set"
|
|
||||||
[:input.input {:type "text"
|
|
||||||
:field :account-set
|
|
||||||
:disabled (boolean (:id account))
|
|
||||||
:spec ::entity/account-set}]]
|
|
||||||
|
|
||||||
[form-builder/field
|
|
||||||
"Code"
|
"Code"
|
||||||
[:input.input {:type "text"
|
[com/number-input
|
||||||
:field :numeric-code
|
{:disabled (boolean (:id account))
|
||||||
:disabled (boolean (:id account))
|
:auto-focus (not (boolean (:id account)))
|
||||||
:spec ::entity/numeric-code}]]
|
:style {:width "9em"}}]]
|
||||||
|
|
||||||
[form-builder/field
|
[form-builder/field-v2 {:field :name}
|
||||||
"Name"
|
"Name"
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:field :name
|
:auto-focus (boolean (:id account))}]]
|
||||||
:spec ::entity/name}]]
|
|
||||||
|
|
||||||
[form-builder/vertical-control
|
[form-builder/field-v2 {:field :type}
|
||||||
"Account Type"
|
"Account Type"
|
||||||
[:div.select
|
[com/select-field {:options (map (fn [l]
|
||||||
[form-builder/raw-field
|
[l (str/capitalize (name l))])
|
||||||
[:select {:type "select"
|
types)
|
||||||
:field :type
|
:allow-nil? true
|
||||||
:spec (set types)}
|
:keywordize? true}]]
|
||||||
(map (fn [l]
|
|
||||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]
|
|
||||||
|
|
||||||
|
|
||||||
[form-builder/field
|
[form-builder/field-v2 {:field :location}
|
||||||
"Location"
|
"Location"
|
||||||
[:input.input.known-field.location {:type "text"
|
[:input.input.known-field.location {:type "text"}]]
|
||||||
:field :location
|
|
||||||
:spec ::entity/location}]]
|
|
||||||
|
|
||||||
[form-builder/section {:title "Client"}
|
[form-builder/section {:title "Client"}
|
||||||
[:h2.subtitle "Client"]
|
[:h2.subtitle "Client"]
|
||||||
[form-builder/vertical-control
|
[form-builder/field-v2 {:field :applicability}
|
||||||
"Applicability"
|
"Applicability"
|
||||||
[:div.select
|
[com/select-field {:options (map (fn [l]
|
||||||
[form-builder/raw-field
|
[l
|
||||||
[:select {:type "select"
|
(str/capitalize (name l))])
|
||||||
:field :applicability
|
applicabilities)
|
||||||
:spec (set applicabilities)}
|
:allow-nil? true
|
||||||
(map (fn [l]
|
:keywordize? true}]]
|
||||||
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)]]]]
|
[form-builder/field-v2 {:field :client-overrides}
|
||||||
[form-builder/field
|
|
||||||
"Customizations"
|
"Customizations"
|
||||||
[multi-field {:type "multi-field"
|
[com/multi-field-v2 {:template [[form-builder/raw-field-v2 {:field :client}
|
||||||
:field [:client-overrides]
|
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
|
||||||
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
|
|
||||||
:style {:width "13em"}
|
:style {:width "13em"}
|
||||||
:entity->text :name
|
:entity->text :name}]]
|
||||||
:type "typeahead-v3"
|
[form-builder/raw-field-v2 {:field :name}
|
||||||
:field [:client]}]
|
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:style {:width "15em"}
|
:style {:width "15em"}
|
||||||
:placeholder "Bubblegum"
|
:placeholder "Bubblegum"}]]]
|
||||||
:field [:name]}]
|
:key-fn :id
|
||||||
]}]]]
|
:schema [:sequential account-customization-schema]}]]]
|
||||||
[form-builder/error-notification]
|
[form-builder/error-notification]
|
||||||
|
|
||||||
[form-builder/submit-button "Save"]]]]))
|
[form-builder/submit-button "Save"]]]]))
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
(def login-url
|
(def login-url
|
||||||
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
||||||
redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
|
redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
|
||||||
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))
|
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&max_auth_age=0&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))
|
||||||
|
|
||||||
(defn dispatch-value-change [event]
|
(defn dispatch-value-change [event]
|
||||||
(fn [e]
|
(fn [e]
|
||||||
|
|||||||
Reference in New Issue
Block a user