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,19 +25,19 @@
(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"
(not can-submit?) (not can-submit?)
"disabled" "disabled"
:else :else
"") "")
:class (when saving? :class (when saving?
"is-loading") "is-loading")
:value action-text} :value action-text}
] ]
:id id :id id

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,73 +14,75 @@
(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]}] ]
(let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range)) (r/create-class
:when (str/includes? (.toLowerCase t) (.toLowerCase @text))] {:reagent-render (fn [{:keys [matches on-change field text-field value class not-found-description]}]
match)) (let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range))
valid-matches (if (and not-found-description @text) :when (str/includes? (.toLowerCase t) (.toLowerCase @text))]
(concat valid-matches [[:not-found (not-found-description @text) (not-found-value @text)]]) match))
valid-matches (if (and not-found-description @text)
valid-matches)] (concat valid-matches [[:not-found (not-found-description @text) (not-found-value @text)]])
[:div.typeahead
(if @selected valid-matches)]
[:div.input {:class class [:div.typeahead
:tab-index "0" (if @selected
:on-key-up (fn [e] [:div.input {:class class
(if (= 8 (.-keyCode e)) :tab-index "0"
(do :on-key-up (fn [e]
(select [nil "" nil]) (if (= 8 (.-keyCode e))
true) (do
false))} (select [nil "" nil])
[:div.control true)
[:div.tags.has-addons false))}
[:span.tag @text] [:div.control
[:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]] [:div.tags.has-addons
[:span.tag @text]
[:input.input {:type "text" [:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]]
:class class
:field field [:input.input {:type "text"
:value @text :class class
:auto-focus auto-focus :field field
:on-blur (fn [e] :value @text
(cond @selected :auto-focus auto-focus
nil :on-blur (fn [e]
(cond @selected
nil
(#{"" nil} @text) (#{"" nil} @text)
nil nil
(seq valid-matches) (seq valid-matches)
(do (select (first valid-matches)) (do (select (first valid-matches))
true) true)
:else :else
(do (select [nil ""]) (do (select [nil ""])
true))) true)))
:on-key-up (fn [e] :on-key-up (fn [e]
(if (and (= 13 (.-keyCode e)) (if (and (= 13 (.-keyCode e))
(seq valid-matches)) (seq valid-matches))
(do (do
(select (first valid-matches)) (select (first valid-matches))
false) false)
true)) true))
:on-change (fn [e] :on-change (fn [e]
(reset! highlighted (ffirst valid-matches)) (reset! highlighted (ffirst valid-matches))
(select [nil (.. e -target -value)]))} (select [nil (.. e -target -value)]))}
]) ])
(cond (cond
(and (seq @text) (and (seq @text)
(not @selected) (not @selected)
(seq valid-matches)) (seq valid-matches))
[:div.typeahead-menu [:div.typeahead-menu
[:ul [:ul
(for [[id t :as match] valid-matches] (for [[id t :as match] valid-matches]
[:li.typeahead-suggestion {:class (if (= id @highlighted) [:li.typeahead-suggestion {:class (if (= id @highlighted)
"typeahead-highlighted") "typeahead-highlighted")
:on-mouse-down #(do (select match))} t])]] :on-mouse-down #(do (select match))} t])]]
: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"))