working on ui improvements.

This commit is contained in:
BC
2018-07-06 18:48:57 -07:00
parent bf7d0698d4
commit d87ebbbfe4
5 changed files with 108 additions and 102 deletions

View File

@@ -25,8 +25,8 @@
(let [{:keys [visible? saving?]} @(re-frame/subscribe [::subs/modal-state id])] (let [{:keys [visible? saving?]} @(re-frame/subscribe [::subs/modal-state id])]
(when visible? (when visible?
(-> [modal {:title title (-> [modal {:title title
:foot [:input.button.is-primary { :foot [:input.button.is-primary {:type "submit"
:type "submit" :tab-index "0"
:form id :form id
:disabled (cond saving? :disabled (cond saving?
"disabled" "disabled"

View File

@@ -1,5 +1,6 @@
(ns auto-ap.views.components.typeahead (ns auto-ap.views.components.typeahead
(:require [reagent.core :as r] (:require [reagent.core :as r]
[reagent.ratom :as ra]
[clojure.string :as str])) [clojure.string :as str]))
(defn typeahead [{:keys [matches on-change field text-field value class not-found-description (defn typeahead [{:keys [matches on-change field text-field value class not-found-description
@@ -13,8 +14,10 @@
(when on-change (when on-change
(if (= :not-found id) (if (= :not-found id)
(on-change nil text-description text-value) (on-change nil text-description text-value)
(on-change id text-description (or text-value text-description)))))] (on-change id text-description (or text-value text-description)))))
(fn [{:keys [matches on-change field text-field value class not-found-description]}] ]
(r/create-class
{:reagent-render (fn [{:keys [matches on-change field text-field value class not-found-description]}]
(let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range)) (let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range))
:when (str/includes? (.toLowerCase t) (.toLowerCase @text))] :when (str/includes? (.toLowerCase t) (.toLowerCase @text))]
match)) match))
@@ -82,4 +85,4 @@
:else :else
nil)])))) nil)]))})))

View File

@@ -10,10 +10,8 @@
[auto-ap.entities.vendors :as entity] [auto-ap.entities.vendors :as entity]
[auto-ap.subs :as subs])) [auto-ap.subs :as subs]))
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}] (defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
(let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])] (let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])]
[action-modal {:id id [action-modal {:id id
:title [:span (if (:id vendor) :title [:span (if (:id vendor)
(str "Edit " (or name "<vendor>")) (str "Edit " (or name "<vendor>"))
@@ -22,13 +20,17 @@
[:span.icon.has-text-danger [:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])] [:i.fa.fa-exclamation-triangle]])]
:action-text "Save" :action-text "Save"
:save-event save-event} :save-event save-event
:can-submit? (s/valid? ::entity/vendor vendor)}
(doto (s/explain ::entity/vendor vendor) println)
[horizontal-field [horizontal-field
[:label.label "Name"] [:label.label "Name"]
[:div.control [:div.control
[bind-field [bind-field
[:input.input {:type "text" [:input.input {:type "text"
:auto-focus true
:field :name :field :name
:spec ::entity/name :spec ::entity/name
:event change-event :event change-event
@@ -43,7 +45,16 @@
:spec ::entity/print-as :spec ::entity/print-as
:event change-event :event change-event
:subscription vendor}]]]] :subscription vendor}]]]]
[:h2.subtitle "Expense Accounts"]
[horizontal-field
[:label.label "Default"]
[bind-field
[typeahead {:matches (map (fn [[k v]] [k (:name v)]) chooseable-expense-accounts)
:type "typeahead"
:field [:default-expense-account]
:spec ::entity/default-expense-account
:event change-event
:subscription vendor}]]]
#_[horizontal-field #_[horizontal-field
[:label.label "Code"] [:label.label "Code"]
[:div.control [:div.control
@@ -151,16 +162,7 @@
:subscription vendor}]] :subscription vendor}]]
" Never"]]] " Never"]]]
[:h2.subtitle "Expense Accounts"]
[horizontal-field
[:label.label "Default"]
[bind-field
[typeahead {:matches (map (fn [[k v]] [k (:name v)]) chooseable-expense-accounts)
:type "typeahead"
:field [:default-expense-account]
:spec ::entity/default-expense-account
:event change-event
:subscription vendor}]]]

View File

@@ -290,7 +290,6 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::change-expense-accounts ::change-expense-accounts
(fn [{:keys [db]} [_ id]] (fn [{:keys [db]} [_ id]]
(println "HELLLO")
{:dispatch [::events/modal-status ::change-expense-accounts {:visible? true}] {:dispatch [::events/modal-status ::change-expense-accounts {:visible? true}]
:db (assoc-in db [::change-expense-accounts :invoice] (get (by :id (get-in db [::invoice-page :invoices])) id))})) :db (assoc-in db [::change-expense-accounts :invoice] (get (by :id (get-in db [::invoice-page :invoices])) id))}))
@@ -529,6 +528,16 @@
:action-text "Create" :action-text "Create"
:save-event [::create-invoice] :save-event [::create-invoice]
:can-submit? (s/valid? ::invoice/invoice data)} :can-submit? (s/valid? ::invoice/invoice data)}
(when-not @(re-frame/subscribe [::subs/company])
[horizontal-field
[:label.label "Company"]
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies]))
:type "typeahead"
:field [:company-id]
:event change-event
:spec ::invoice/company-id
:subscription data}]]])
[horizontal-field [horizontal-field
[:label.label "Vendor"] [:label.label "Vendor"]
@@ -552,16 +561,7 @@
:spec ::invoice/date :spec ::invoice/date
:subscription data}]]] :subscription data}]]]
(when-not @(re-frame/subscribe [::subs/company])
[horizontal-field
[:label.label "Company"]
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies]))
:type "typeahead"
:field [:company-id]
:event change-event
:spec ::invoice/company-id
:subscription data}]]])
[horizontal-field [horizontal-field
[:label.label "Invoice #"] [:label.label "Invoice #"]
@@ -583,7 +583,8 @@
:event change-event :event change-event
:subscription data :subscription data
:spec ::invoice/total :spec ::invoice/total
:step "0.01"}]]]]]])) :step "0.01"}]]]]]
]))

View File

@@ -30,7 +30,7 @@
(when (.-stopPropagation e) (when (.-stopPropagation e)
(.stopPropagation e) (.stopPropagation e)
(.preventDefault e)) (.preventDefault e))
(re-frame/dispatch event))) (re-frame/dispatch-sync event)))
(def pretty-long (format/formatter "MM/dd/yyyy HH:mm:ss")) (def pretty-long (format/formatter "MM/dd/yyyy HH:mm:ss"))
(def pretty (format/formatter "MM/dd/yyyy")) (def pretty (format/formatter "MM/dd/yyyy"))