reverted.

This commit is contained in:
2021-05-27 08:25:58 -07:00
parent c7055d7a70
commit 33b45373c2
34 changed files with 443 additions and 2504 deletions

2157
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,6 @@
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"downshift": "^6.1.3",
"dropzone": "^4.3.0", "dropzone": "^4.3.0",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"react": "^17.0.1", "react": "^17.0.1",

View File

@@ -86,9 +86,7 @@
;; needed for java 11 ;; needed for java 11
[javax.xml.bind/jaxb-api "2.4.0-b180830.0359"] [javax.xml.bind/jaxb-api "2.4.0-b180830.0359"]]
[coderafting/memsearch "0.1.0"]]
:managed-dependencies [;; explicit dependencies to get to latest versions for above :managed-dependencies [;; explicit dependencies to get to latest versions for above
[com.fasterxml.jackson.core/jackson-core "2.12.0"] [com.fasterxml.jackson.core/jackson-core "2.12.0"]
[com.fasterxml.jackson.core/jackson-databind "2.12.0"] [com.fasterxml.jackson.core/jackson-databind "2.12.0"]

View File

@@ -130,6 +130,7 @@
(re-frame/enrich (re-frame/enrich
(fn [db event] (fn [db event]
(loading db form)))) (loading db form))))
(defn triggers-stop [form] (defn triggers-stop [form]
(re-frame/enrich (re-frame/enrich
(fn [db event] (fn [db event]

View File

@@ -2,8 +2,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[clojure.string :as str] [clojure.string :as str]
[goog.crypt.base64 :as base64] [goog.crypt.base64 :as base64]))
[memsearch.core :as ms]))
(re-frame/reg-sub (re-frame/reg-sub
::client ::client
@@ -61,17 +60,6 @@
[] []
accounts))) accounts)))
(re-frame/reg-sub
::accounts-index
:<- [::accounts]
(fn [accounts]
(ms/text-index (map (fn [v] {:id (:id v)
:content (str (:numeric-code v) " " (:name v))})
accounts)
{:maintain-actual? true})))
(re-frame/reg-sub (re-frame/reg-sub
::account ::account
@@ -213,15 +201,6 @@
(filter #(not (:hidden %)) all-vendors)))) (filter #(not (:hidden %)) all-vendors))))
(re-frame/reg-sub
::searchable-vendors-index
:<- [::searchable-vendors]
(fn [searchable-vendors]
(ms/text-index (map (fn [v] {:id (:id v)
:content (:name v)})
searchable-vendors)
{:maintain-actual? true})))
(re-frame/reg-sub (re-frame/reg-sub
::all-vendors ::all-vendors
(fn [db] (fn [db]

View File

@@ -2,6 +2,7 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field ->$]] [auto-ap.views.utils :refer [bind-field ->$]]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))

View File

@@ -2,6 +2,7 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]] [auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t] [cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.invoices.common :refer [invoice-read]] [auto-ap.views.pages.invoices.common :refer [invoice-read]]
[auto-ap.views.utils :refer [dispatch-event with-user]] [auto-ap.views.utils :refer [dispatch-event with-user]]
[clojure.string :as str] [clojure.string :as str]
@@ -124,10 +124,10 @@
[:tr [:tr
[:td.expandable [:div.control [:td.expandable [:div.control
(raw-field (raw-field
[typeahead-v3 {:entities chooseable-expense-accounts [typeahead-entity {:matches chooseable-expense-accounts
:type "typeahead-v3" :type "typeahead-entity"
:entity->text (fn [x] (str (:numeric-code x) " - " (:name x))) :match->text (fn [x] (str (:numeric-code x) " - " (:name x)))
:field [:expense-accounts id :account]}])]] :field [:expense-accounts id :account]}])]]
(when multi-location? (when multi-location?
[:td [:td

View File

@@ -1,7 +1,7 @@
(ns auto-ap.views.components.expense-accounts-field (ns auto-ap.views.components.expense-accounts-field
(:require [auto-ap.forms :as forms] (:require [auto-ap.forms :as forms]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
[auto-ap.views.components.money-field :refer [money-field]] [auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.utils :refer [bind-field dispatch-event ->$]] [auto-ap.views.utils :refer [bind-field dispatch-event ->$]]
[goog.string :as gstring] [goog.string :as gstring]
@@ -162,14 +162,14 @@
[:div.control.is-fullwidth [:div.control.is-fullwidth
[bind-field [bind-field
^{:key (:id client)} ^{:key (:id client)}
[typeahead-v3 {:entities chooseable-expense-accounts [typeahead-entity {:matches chooseable-expense-accounts
:entity->text (fn [x ] :match->text (fn [x ]
(str (:numeric-code x) " - " (:name x))) (str (:numeric-code x) " - " (:name x)))
:disabled disabled :disabled disabled
:type "typeahead-v3" :type "typeahead-entity"
:field [index :account] :field [index :account]
:event [::expense-account-changed event expense-accounts max-value] :event [::expense-account-changed event expense-accounts max-value]
:subscription expense-accounts}]]]] :subscription expense-accounts}]]]]
[:div.column.is-narrow [:div.column.is-narrow
[:p.help "Location"] [:p.help "Location"]
[:div.control [:div.control

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.switch-field :refer [switch-field]] [auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change]] [auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
@@ -59,12 +59,12 @@
[:div [:div
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))]) :match->text :name
:entity->text :name :type "typeahead-entity"
:type "typeahead-v3" :value @(re-frame/subscribe [::data-page/filter data-page :vendor])
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]] :include-keys [:name :id]}]]
[:p.menu-label "Date Range"] [:p.menu-label "Date Range"]
[:div [:div
[date-range-filter [date-range-filter

View File

@@ -2,6 +2,7 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]] [auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t] [cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))

View File

@@ -3,106 +3,238 @@
[reagent.ratom :as ra] [reagent.ratom :as ra]
[clojure.string :as str] [clojure.string :as str]
[clojure.set :as set] [clojure.set :as set]
[memsearch.core :as ms] #_[memsearch.core :as ms]
[downshift :as ds :refer [useCombobox]] [downshift :as ds :refer [useCombobox]]
[react])) [react]))
(defn typeahead-v3-internal [{:keys [class style disabled entities entity->text entities-by-id entity-index on-change disabled value name auto-focus] :or {disabled false} :as i}]
(println "hello")
(let [[items set-items] (react/useState (map clj->js entities))
state-reducer (fn [state actions-and-changes]
(cond
(= (.-type actions-and-changes) (.-InputChange (.-stateChangeTypes useCombobox)))
(doto (.-changes actions-and-changes) (aset
"selectedItem"
nil))
(and (= (.-type actions-and-changes) (.-InputBlur (.-stateChangeTypes useCombobox)))
(not (.-selectedItem state)))
(doto (.-changes actions-and-changes) (aset
"inputValue"
nil))
:else (defn get-valid-matches [matches not-found-description not-found-value text]
(.-changes actions-and-changes))) (let [valid-matches (take 15 (for [[[id t :as match] i] (map vector matches (range))
[getLabelProps getMenuProps getComboboxProps getToggleButtonProps getInputProps getItemProps isOpen highlightedIndex selectItem selectedItem setInputValue] :when (str/includes? (or (some-> t .toLowerCase) "") (or (some-> text .toLowerCase) ""))]
(as-> (useCombobox (clj->js {:items items match))
:defaultHighlightedIndex 0 valid-matches (if (and not-found-description text)
:defaultSelectedItem value (concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]])
:onInputValueChange (fn [input] valid-matches)]
(if entities-by-id valid-matches))
(->> (ms/text-search (.-inputValue input) entity-index)
(sort-by (fn [[k v]]
(- (:score v))))
(map (fn [[x]]
(entities-by-id x)
))
(take 5)
clj->js
set-items)
(set-items (map clj->js (take 5 (filter (fn [x] (str/includes? (or (some-> (entity->text x) .toLowerCase) "") (defn typeahead [{:keys [matches on-change field text-field value class not-found-description
(or (some-> (.-inputValue input) .toLowerCase) ""))) disabled not-found-value auto-focus]}]
entities)))))) (let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
:stateReducer state-reducer highlighted (r/atom nil)
:onSelectedItemChange (fn [z] selected (r/atom (first (first (filter #(= (first %) value) matches))))
(when on-change ]
(on-change (js->clj (.-selectedItem z) :keywordize-keys true))))})) $ (r/create-class
[(.-getLabelProps $) {:reagent-render (fn [{:keys [matches on-change disabled field text-field value class not-found-description]}]
(.-getMenuProps $) (let [ select (fn [[id text-description text-value]]
(.-getComboboxProps $) (reset! selected id)
(.-getToggleButtonProps $) (reset! text text-description)
(.-getInputProps $) (when on-change
(.-getItemProps $) (if (= :not-found id)
(.-isOpen $) (on-change nil text-description text-value)
(.-highlightedIndex $) (on-change id text-description (or text-value text-description)))))
(.-selectItem $) text @text
(.-selectedItem $) valid-matches (get-valid-matches matches not-found-description not-found-value text)]
(.-setInputValue $)])] [:div.typeahead
[:<> (if disabled
[:div.typeahead (assoc (js->clj (getComboboxProps))
:style style) ^{:key (str "typeahead" text) } [:input.input {:disabled "disabled" :value text} ]
(if selectedItem
^{:key "typeahead"} [:div.input (assoc (js->clj (getInputProps #js {:disabled (if disabled (if @selected
"disabled" ^{:key "typeahead"} [:div.input {:class class
"")})) :tab-index "0"
:on-key-up (fn [e] :on-key-up (fn [e]
(when (= 8 (.-keyCode e)) (if (= 8 (.-keyCode e))
(selectItem nil) (do
(setInputValue nil) (select [nil "" nil])
(when on-change true)
(on-change nil)))) false))}
:class class [:div.control
:tab-index "0") [:div.tags.has-addons
[:div.control [:span.tag text]
[:div.tags.has-addons [:a.tag.is-delete {:on-click (fn []
[:span.tag (entity->text (js->clj selectedItem :keywordize-keys true))] (select [nil "" nil]))}]]]]
(when name ^{:key "typeahead"}
[:input {:type "hidden" :name name :value (:id (js->clj selectedItem :keywordize-keys true))}]) [:input.input {:type "text"
(when-not disabled :class class
[:a.tag.is-delete {:on-click (fn []
(setInputValue nil) :value text
(selectItem nil) :auto-focus auto-focus
(when on-change :on-blur (fn [e]
(on-change nil)))}])]]] (cond @selected
^{:key "typeahead"} [:input.input (js->clj nil
(getInputProps #js {:disabled (if disabled
"disabled" (#{"" nil} text)
"") nil
:autoFocus (if auto-focus
"autoFocus" @highlighted
"")}))]) (do (select @highlighted)
[:div {:class (if (and isOpen (seq items)) "typeahead-menu")} true)
[:ul (js->clj (getMenuProps))
(if (and isOpen (seq items)) :else
(for [[index item] (map vector (range) (js->clj items :keywordize-keys true))] (do (select [nil ""])
^{:key item} true)))
[:li.typeahead-suggestion (assoc (js->clj (getItemProps #js {:item item :index index})) :on-key-down (fn [e]
:class (if (= index highlightedIndex) (condp = (.-keyCode e)
"typeahead-highlighted")) ; up
(entity->text item)]))]]]])) 38 (do
(when-let [new-match (->> valid-matches
(take-while #(not= % @highlighted))
(last))]
(reset! highlighted new-match))
true)
;; dwon
40 (do
(when-let [new-match (->> valid-matches
(drop-while #(not= % @highlighted))
(drop 1)
(first))]
(reset! highlighted new-match))
true)
13 (do (.preventDefault e)
(when @highlighted
(select @highlighted)
false))
true))
:on-change (fn [e]
(let [new-matches (get-valid-matches matches not-found-description not-found-value (.. e -target -value))]
(reset! highlighted (first new-matches)))
(select [nil (.. e -target -value)]))}]))
(cond
(and (seq text)
(not @selected)
(seq valid-matches))
(let [[h] @highlighted]
[:div.typeahead-menu
[:ul
(for [[id t :as match] valid-matches]
^{:key id} [:li.typeahead-suggestion {:class (if (= id h)
"typeahead-highlighted")
:on-mouse-down #(do (select match))} t])]])
:else
nil)]))})))
(defn get-valid-entity-matches [matches not-found-description not-found-value text match->text]
(let [valid-matches (->> (for [[match i] (map vector matches (range))
:let [t (match->text match)
match-index (str/index-of (or (some-> t .toLowerCase) "") (or (some-> text .toLowerCase) ""))]
:when match-index]
[match match-index ])
(sort-by second)
(map first)
(take 10))
valid-matches (if (and not-found-description text)
(concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]])
valid-matches)]
valid-matches))
(defn typeahead-entity [{:keys [matches on-change field value class not-found-description
disabled not-found-value auto-focus name include-keys]}]
(let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
highlighted (r/atom nil)
]
(r/create-class
{:reagent-render (fn [{:keys [matches on-change disabled match->text field value class not-found-description include-keys style]}]
(let [select (fn [entity]
(when on-change
(if (= :not-found entity)
(on-change nil)
(on-change (cond-> entity
(and include-keys entity) (select-keys include-keys))))))
text-atom text
text (or (when value (match->text value)) @text)
valid-matches (get-valid-entity-matches matches not-found-description not-found-value text match->text)]
[:div.typeahead {:style style}
(if disabled
^{:key (str "typeahead" text) } [:input.input {:disabled "disabled" :value text} ]
(if value
^{:key "typeahead"} [:div.input {:class class
:tab-index "0"
:on-key-up (fn [e]
(if (= 8 (.-keyCode e))
(do
(select nil)
(reset! text-atom nil)
true)
false))}
[:div.control
[:div.tags.has-addons
[:span.tag text]
(when name
[:input {:type "hidden" :name name :value (:id @highlighted)}])
[:a.tag.is-delete {:on-click (fn []
(select nil)
(reset! text-atom nil)
(reset! highlighted nil))}]]]]
^{:key "typeahead"} [:input.input {:type "text"
:class class
:value text
:auto-focus auto-focus
:on-blur (fn [e]
(cond value
nil
(#{"" nil} text)
nil
@highlighted
(do (select @highlighted)
true)
:else
(do (select nil)
(reset! highlighted nil)
(reset! text-atom nil)
true)))
:on-key-down (fn [e]
(condp = (.-keyCode e)
; up
38 (do
(when-let [new-match (->> valid-matches
(take-while #(not= % @highlighted))
(last))]
(reset! highlighted new-match))
true)
;; dwon
40 (do
(when-let [new-match (->> valid-matches
(drop-while #(not= % @highlighted))
(drop 1)
(first))]
(reset! highlighted new-match))
true)
13 (do (.preventDefault e)
(when @highlighted
(select @highlighted)
false))
true))
:on-change (fn [e]
(let [new-matches (get-valid-entity-matches matches not-found-description not-found-value (.. e -target -value) match->text)]
(reset! highlighted (first new-matches)))
(reset! text-atom (.. e -target -value)))}]))
(cond
(and (seq text)
(not value)
(seq valid-matches))
(let [h @highlighted]
[:div.typeahead-menu
[:ul
(for [entity valid-matches]
(let [t (match->text entity)]
^{:key entity} [:li.typeahead-suggestion {:class (if (= entity h)
"typeahead-highlighted")
:on-mouse-over (fn [] (reset! highlighted entity))
:on-mouse-down #(do (select entity))} t]))]])
:else
nil)]))})))
(defn typeahead-v3 [{:keys [class disabled entities entity->text entities-by-id entity-index on-change value ] :as props}]
(println typeahead-v3-internal)
[:div
[:f> typeahead-v3-internal props]])

View File

@@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user with-is-admin? active-when account->match-text]] [auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user with-is-admin? active-when account->match-text]]
[auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]] [auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]]
[auto-ap.events :as events] [auto-ap.events :as events]
[clj-fuzzy.metrics :refer [jaccard jaro-winkler]] [clj-fuzzy.metrics :refer [jaccard jaro-winkler]]
@@ -154,12 +154,12 @@
[:div.columns [:div.columns
[:div.column [:div.column
[bind-field [bind-field
[typeahead-v3 {:entities clients [typeahead-entity {:matches clients
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:field [override-key i] :field [override-key i]
:event change-event :event change-event
:subscription data}]]] :subscription data}]]]
[:div.column.is-1 [:div.column.is-1
[:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]]))]))) [:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]]))])))
@@ -186,12 +186,12 @@
[:div.columns [:div.columns
[:div.column [:div.column
[bind-field [bind-field
[typeahead-v3 {:entities clients [typeahead-entity {:matches clients
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:field [override-key i :client] :field [override-key i :client]
:event change-event :event change-event
:subscription data}]]] :subscription data}]]]
[:div.column [:div.column
[bind-field [bind-field
(template (template
@@ -215,12 +215,12 @@
[:div.columns [:div.columns
[:div.column [:div.column
[bind-field [bind-field
[typeahead-v3 {:entities clients [typeahead-entity {:matches clients
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:field [override-key i :client] :field [override-key i :client]
:event change-event :event change-event
:subscription data}]]] :subscription data}]]]
[:div.column [:div.column
[bind-field [bind-field
(template (template
@@ -306,12 +306,12 @@
:override-key :account-overrides} :override-key :account-overrides}
(fn [field client] (fn [field client]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/accounts client]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/accounts client])
:entity->text account->match-text :match->text account->match-text
:field field :field field
:type "typeahead-v3" :type "typeahead-entity"
:event change-event :event change-event
:subscription data}])] :subscription data}])]
[:h2.subtitle "Address"] [:h2.subtitle "Address"]
[address-field {:field [:address] [address-field {:field [:address]

View File

@@ -2,6 +2,18 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice] [auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field]])) [auto-ap.views.utils :refer [bind-field]]))
(defn vendor-filter [{:keys [value on-change-event vendors]}]
[:div.field
[:div.control
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) vendors)
:type "typeahead"
:auto-focus true
:field [:vendor-id]
:text-field [:vendor-name]
:event on-change-event
:spec (s/nilable ::invoice/vendor-id)
:subscription value}]]]])

View File

@@ -3,7 +3,7 @@
[auto-ap.forms :as forms] [auto-ap.forms :as forms]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.layouts :refer [side-bar]] [auto-ap.views.components.layouts :refer [side-bar]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.utils :refer [dispatch-event multi-field]] [auto-ap.views.utils :refer [dispatch-event multi-field]]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as str] [clojure.string :as str]
@@ -138,11 +138,11 @@
(field "Customizations" (field "Customizations"
[multi-field {:type "multi-field" [multi-field {:type "multi-field"
:field [:client-overrides] :field [:client-overrides]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) :template [[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:style {:width "20em"} :style {:width "20em"}
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead"
:field [:client]}] :field [:client]}]
[:input.input {:type "text" [:input.input {:type "text"
:style {:width "20em"} :style {:width "20em"}
:placeholder "Bubblegum" :placeholder "Bubblegum"

View File

@@ -2,7 +2,8 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]])) [auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]))
(re-frame/reg-sub (re-frame/reg-sub

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.layouts :refer [side-bar]] [auto-ap.views.components.layouts :refer [side-bar]]
[auto-ap.views.utils [auto-ap.views.utils
:refer :refer
@@ -377,10 +377,10 @@
:type "text" :type "text"
:field [:bank-accounts sort-order :yodlee-account-id]}]] :field [:bank-accounts sort-order :yodlee-account-id]}]]
[field "Yodlee Account (new)" [field "Yodlee Account (new)"
[typeahead-v3 {:entities @(re-frame/subscribe [::yodlee-accounts (:id new-client)]) [typeahead-entity {:matches @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:entity->text (fn [m] (str (:name m) " - " (:number m))) :match->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead-v3" :type "typeahead"
:field [:bank-accounts sort-order :yodlee-account]}]]]) :field [:bank-accounts sort-order :yodlee-account]}]]])
(when (#{:credit ":credit"} type ) (when (#{:credit ":credit"} type )
[:div [:div
@@ -405,10 +405,10 @@
:type "text" :type "text"
:field [:bank-accounts sort-order :yodlee-account-id]}]] :field [:bank-accounts sort-order :yodlee-account-id]}]]
[field "Yodlee Account (new)" [field "Yodlee Account (new)"
[typeahead-v3 {:entities @(re-frame/subscribe [::yodlee-accounts (:id new-client)]) [typeahead-entity {:matches @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:entity->text (fn [m] (str (:name m) " - " (:number m))) :match->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead-v3" :type "typeahead"
:field [:bank-accounts sort-order :yodlee-account]}]]]) :field [:bank-accounts sort-order :yodlee-account]}]]])
[:div.field [:div.field
[:label.label "Locations"] [:label.label "Locations"]
[:div.control [:div.control

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]] [auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field dispatch-event]] [auto-ap.views.utils :refer [bind-field dispatch-event]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -77,7 +77,7 @@
:venia/queries (map (fn [v ] :venia/queries (map (fn [v ]
{:query/data [:upsert-vendor {:query/data [:upsert-vendor
{:vendor {:name v :default-account-id (-> db ::expense-accounts (get v) :default-account-id :id)}} {:vendor {:name v :default-account-id (-> db ::expense-accounts (get v) :default-account-id)}}
[:id :name]]}) [:id :name]]})
(get-in db [::excel-import :create-vendors]))} (get-in db [::excel-import :create-vendors]))}
@@ -138,12 +138,11 @@
[:p.control [:p.control
[bind-field [bind-field
[typeahead-v3 {:entities chooseable-expense-accounts [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts)
:entity->text (fn [x ] (str (:numeric-code x) " - " (:name x))) :type "typeahead"
:type "typeahead-v3" :field [v :default-account-id]
:field [v :default-account-id] :event change-event
:event change-event :subscription data}]]]])])]
:subscription data}]]]])])]
[:div [:div
[:button.button.is-pulled-right [:button.button.is-pulled-right
{:on-click (dispatch-event [::create-vendors]) {:on-click (dispatch-event [::create-vendors])

View File

@@ -8,7 +8,7 @@
[auto-ap.views.components.dropdown :refer [drop-down]] [auto-ap.views.components.dropdown :refer [drop-down]]
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]] [auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
[auto-ap.views.components.layouts :as layouts] [auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.admin.rules.common :refer [default-read]] [auto-ap.views.pages.admin.rules.common :refer [default-read]]
[auto-ap.views.pages.admin.rules.results-modal :as results-modal] [auto-ap.views.pages.admin.rules.results-modal :as results-modal]
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]] [auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
@@ -180,8 +180,7 @@
[[:accounts] (expense-accounts-field/default-account (:accounts data) [[:accounts] (expense-accounts-field/default-account (:accounts data)
@(re-frame/subscribe [::subs/vendor-default-account (:vendor data) value]) @(re-frame/subscribe [::subs/vendor-default-account (:vendor data) value])
(:total data) (:total data)
[]) [])]
[:bank-account] nil]
:else :else
[])))) []))))
@@ -246,29 +245,25 @@
(field "Client" (field "Client"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:auto-focus true :auto-focus true
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:field [:client] :field [:client]
:spec ::entity/client}]) :spec ::entity/client}])
(field "Bank account"
(with-meta [typeahead-entity {:matches @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
(field "Bank account" :match->text :name
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)]) :type "typeahead-entity"
:entity->text :name :field [:bank-account]
:type "typeahead-v3" :spec ::entity/bank-account}])
:field [:bank-account]
:spec ::entity/bank-account}])
;; TODO this forces unmounting when client changes, since it is an "uncontorlled" input
{:key (str "client-" (:id (:client data)))})
(field "Yodlee Merchant" (field "Yodlee Merchant"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/yodlee-merchants]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/yodlee-merchants])
:entity->text #(str (:name %) " - " (:yodlee-id %)) :match->text #(str (:name %) " - " (:yodlee-id %))
:type "typeahead-v3" :type "typeahead-entity"
:field [:yodlee-merchant]}]) :field [:yodlee-merchant]}])
(field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ] (field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ]
[:input.input {:type "text" [:input.input {:type "text"
@@ -320,12 +315,11 @@
[:h2.title.is-4 "Outcomes"] [:h2.title.is-4 "Outcomes"]
(field "Assign Vendor" (field "Assign Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/all-vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :match->text :name
:entity->text :name :type "typeahead-entity"
:type "typeahead-v3" :field [:vendor]
:field [:vendor] :spec ::entity/vendor}])
:spec ::entity/vendor}])
(field nil (field nil
[expense-accounts-field {:type "expense-accounts" [expense-accounts-field {:type "expense-accounts"

View File

@@ -2,7 +2,7 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page])) [auto-ap.views.pages.data-page :as data-page]))
@@ -10,10 +10,10 @@
[:div [:div
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))]) :match->text :name
:entity->text :name :include-keys [:name :id]
:type "typeahead-v3" :type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]]) :value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]])

View File

@@ -17,6 +17,8 @@
[auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event bind-field horizontal-field action-cell-width]] [auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event bind-field horizontal-field action-cell-width]]
[auto-ap.views.pages.admin.vendors.table :as table] [auto-ap.views.pages.admin.vendors.table :as table]
[auto-ap.views.pages.admin.vendors.merge-dialog :as merge-dialog] [auto-ap.views.pages.admin.vendors.merge-dialog :as merge-dialog]
[auto-ap.views.components.typeahead :refer [typeahead]]
[cljs.reader :as edn] [cljs.reader :as edn]
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]

View File

@@ -3,7 +3,7 @@
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.utils :refer [dispatch-event]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -28,22 +28,20 @@
(form-inline {} (form-inline {}
[:<> [:<>
(field "Form Vendor (will be deleted)" (field "Form Vendor (will be deleted)"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :type "typeahead-entity"
:type "typeahead-v3" :auto-focus true
:auto-focus true :match->text (fn [x]
:entity->text (fn [x] (str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") ) :field [:from]}])
:field [:from]}])
(field "To Vendor" (field "To Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :type "typeahead-entity"
:type "typeahead-v3" :match->text (fn [x]
:entity->text (fn [x] (str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") ) :field [:to]}])])))
:field [:to]}])])))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::show ::show

View File

@@ -2,7 +2,8 @@
(:require (:require
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]])) [auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]))
(re-frame/reg-sub (re-frame/reg-sub
::specific-filters ::specific-filters

View File

@@ -3,20 +3,16 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.grid :as grid] [auto-ap.views.components.grid :as grid]
[auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.utils [auto-ap.views.utils
:refer :refer
[->$ date->str days-until dispatch-event local-now standard]] [->$ date->str days-until dispatch-event local-now standard]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[cljs-time.coerce :as coerce] [cljs-time.coerce :as coerce]
[cljs-time.core :as t] [cljs-time.core :as t]
[clojure.string :as str]
[pushy.core :as pushy] [pushy.core :as pushy]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[recharts] [recharts]
[downshift :as ds :refer [useCombobox]] [reagent.core :as r]))
[reagent.core :as r]
[react]))
(def pie-chart (r/adapt-react-class recharts/PieChart)) (def pie-chart (r/adapt-react-class recharts/PieChart))
(def pie (r/adapt-react-class recharts/Pie)) (def pie (r/adapt-react-class recharts/Pie))
@@ -300,16 +296,9 @@
(defn home-content [] (defn home-content []
(let [client-id (-> @(re-frame/subscribe [::subs/client]) :id) (let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)
vendors-by-id @(re-frame/subscribe [::subs/vendors-by-id])
vendors-index @(re-frame/subscribe [::subs/searchable-vendors-index])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id])
accounts-index @(re-frame/subscribe [::subs/accounts-index])
chart-options @(re-frame/subscribe [::chart-options])] chart-options @(re-frame/subscribe [::chart-options])]
^{:key client-id} ^{:key client-id}
[side-bar-layout {:side-bar [:div [side-bar-layout {:side-bar [:div]
]
:main [:div [:h1.title "Home"] :main [:div [:h1.title "Home"]
[:h1.title.is-4 "Top expense categories"] [:h1.title.is-4 "Top expense categories"]
(let [expense-categories @(re-frame/subscribe [::top-expense-categories])] (let [expense-categories @(re-frame/subscribe [::top-expense-categories])]

View File

@@ -10,7 +10,7 @@
[auto-ap.views.utils :refer [dispatch-event bind-field with-user]] [auto-ap.views.utils :refer [dispatch-event bind-field with-user]]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.entities.vendors :as vendor] [auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table] [auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[cljs.reader :as edn] [cljs.reader :as edn]
[clojure.string :as str] [clojure.string :as str]
@@ -60,14 +60,13 @@
[:p.control [:p.control
[:a.button.is-static "Force vendor"]] [:a.button.is-static "Force vendor"]]
[:div.control {:style {:width "400px"}} [:div.control {:style {:width "400px"}}
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :match->text :name
:entity->text :name :name "vendor"
:name "vendor" :type "typeahead"
:type "typeahead-v3" :on-change (fn [v]
:on-change (fn [v] (reset! vendor v))
(reset! vendor v)) :value @vendor}]]
:value @vendor}]]
] ]
[:div.tile.notification [:div.tile.notification
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}} [:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}

View File

@@ -16,7 +16,7 @@
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.components.money-field :refer [money-field]] [auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.switch-field :refer [switch-field]] [auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.invoices.common :refer [invoice-read]] [auto-ap.views.pages.invoices.common :refer [invoice-read]]
[auto-ap.views.utils [auto-ap.views.utils
:refer :refer
@@ -348,22 +348,22 @@
(when-not @(re-frame/subscribe [::subs/client]) (when-not @(re-frame/subscribe [::subs/client])
(field [:span "Client" (field [:span "Client"
[:span.has-text-danger " *"]] [:span.has-text-danger " *"]]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead"
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true) :auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
:field [:client] :field [:client]
:disabled exists? :disabled exists?
:spec ::invoice/client}])) :spec ::invoice/client}]))
(field [:span "Vendor" (field [:span "Vendor"
[:span.has-text-danger " *"]] [:span.has-text-danger " *"]]
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :match->text :name
:entity->text :name :type "typeahead"
:type "typeahead-v3" :disabled exists?
:disabled exists? :auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false) :field [:vendor]}])
:field [:vendor]}])
(field [:span "Date" (field [:span "Date"
[:span.has-text-danger " *"]] [:span.has-text-danger " *"]]

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]] [auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-value-change]] [auto-ap.views.utils :refer [active-when dispatch-value-change]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
@@ -13,8 +13,7 @@
(defn ledger-side-bar [{:keys [data-page]}] (defn ledger-side-bar [{:keys [data-page]}]
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user]) user @(re-frame/subscribe [::subs/user])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id]) accounts @(re-frame/subscribe [::subs/accounts])]
accounts-index @(re-frame/subscribe [::subs/accounts-index])]
[:div [:div
[:ul.menu-list [:ul.menu-list
[:li.menu-item [:li.menu-item
@@ -57,21 +56,21 @@
[:p.menu-label "Financial Account"] [:p.menu-label "Financial Account"]
[:div [:div
[typeahead-v3 {:entities-by-id accounts-by-id [typeahead-entity {:matches accounts
:entity-index accounts-index :match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:entity->text (fn [x ] (str (:numeric-code x) " - " (:name x))) :include-keys [:name :id :numeric-code]
:type "typeahead-v3" :type "typeahead-entity"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account (some-> % (select-keys [:name :id :numeric-code]))]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account %])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]] :value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))]) :include-keys [:name :id]
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]] :value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]

View File

@@ -9,6 +9,7 @@
[auto-ap.views.components.sorter :refer [sorted-column]] [auto-ap.views.components.sorter :refer [sorted-column]]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.components.paginator :refer [paginator]] [auto-ap.views.components.paginator :refer [paginator]]
[auto-ap.views.components.sort-by-list :refer [sort-by-list]] [auto-ap.views.components.sort-by-list :refer [sort-by-list]]
[auto-ap.events :as events] [auto-ap.events :as events]

View File

@@ -2,7 +2,7 @@
(:require [auto-ap.subs :as subs] (:require [auto-ap.subs :as subs]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [dispatch-event dispatch-value-change]] [auto-ap.views.utils :refer [dispatch-event dispatch-value-change]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -14,13 +14,12 @@
[:div [:div
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))]) :include-keys [:name :id]
:include-keys [:name :id] :match->text :name
:entity->text :name :type "typeahead-entity"
:type "typeahead-v3" :value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
[:p.menu-label "Date Range"] [:p.menu-label "Date Range"]
[:div [:div

View File

@@ -8,7 +8,7 @@
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]] [auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
[auto-ap.views.components.layouts :as layouts] [auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.money-field :refer [money-field]] [auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]] [auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
[cljs-time.core :as c] [cljs-time.core :as c]
@@ -42,11 +42,11 @@
(when-not @(re-frame/subscribe [::subs/client]) (when-not @(re-frame/subscribe [::subs/client])
(field [:span "Client" (field [:span "Client"
[:span.has-text-danger " *"]] [:span.has-text-danger " *"]]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead"
:field [:client] :field [:client]
:disabled true}])) :disabled true}]))
(field "Date" (field "Date"

View File

@@ -2,9 +2,11 @@
(:require [auto-ap.routes :as routes] (:require [auto-ap.routes :as routes]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]] [auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.vendor-filter :refer [vendor-filter]]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]] [auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.views.pages.data-page :as data-page])) [auto-ap.views.pages.data-page :as data-page]))

View File

@@ -9,7 +9,7 @@
:refer :refer
[expense-accounts-field]] [expense-accounts-field]]
[auto-ap.views.components.layouts :as layouts] [auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.transactions.common :refer [transaction-read]] [auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils [auto-ap.views.utils
:refer :refer
@@ -406,14 +406,13 @@
[tab {:title "Details" :key :details} [tab {:title "Details" :key :details}
[:div [:div
(field "Vendor" (field "Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :match->text :name
:entity->text :name :type "typeahead-entity"
:type "typeahead-v3" :auto-focus true
:auto-focus true :field [:vendor]
:field [:vendor] :disabled (or (boolean (:payment data))
:disabled (or (boolean (:payment data)) should-disable-for-client?)}])
should-disable-for-client?)}])
(field nil (field nil
[expense-accounts-field [expense-accounts-field
{:type "expense-accounts" {:type "expense-accounts"
@@ -438,10 +437,10 @@
:disabled should-disable-for-client?}]) :disabled should-disable-for-client?}])
(field "Forecasted-transaction" (field "Forecasted-transaction"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))])
:entity->text :identifier :match->text :identifier
:type "typeahead-v3" :type "typeahead-entity"
:field [:forecast-match]}]) :field [:forecast-match]}])
(error-notification) (error-notification)
(when-not should-disable-for-client? (when-not should-disable-for-client?
(submit-button "Save"))]]]]))]) (submit-button "Save"))]]]]))])

View File

@@ -7,7 +7,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.switch-field :refer [switch-field]] [auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change ->$ account->match-text]] [auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change ->$ account->match-text]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
@@ -17,8 +17,7 @@
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user]) user @(re-frame/subscribe [::subs/user])
accounts @(re-frame/subscribe [::subs/accounts-by-id]) accounts @(re-frame/subscribe [::subs/accounts])
account-index @(re-frame/subscribe [::subs/accounts-index])
] ]
[:div [:div
[:div [:p.menu-label "Type"] [:div [:p.menu-label "Type"]
@@ -65,20 +64,20 @@
[:p.menu-label "Financial Account"] [:p.menu-label "Financial Account"]
[:div [:div
[typeahead-v3 {:entities-by-id accounts [typeahead-entity {:matches accounts
:entity-index account-index :match->text account->match-text
:entity->text account->match-text :include-keys [:name :id :numeric-code]
:type "typeahead-v3" :type "typeahead-entity"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account (some-> % (select-keys [:name :id :numeric-code]))]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account %])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]] :value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[:p.menu-label "Vendor"] [:p.menu-label "Vendor"]
[:div [:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id]) [typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index]) :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))]) :include-keys [:name :id]
:entity->text :name :match->text :name
:type "typeahead-v3" :type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]] :value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]

View File

@@ -100,9 +100,6 @@
e e
(date->str (time/from-default-time-zone (c/from-date e)) standard)))))) (date->str (time/from-default-time-zone (c/from-date e)) standard))))))
;; TODO inline on-changes causes each field to be rerendered each time. When we fix this
;; let's make sure that we find away not to trigger a re-render for every component any time any form field
;; changes
(defmulti do-bind (fn [a {:keys [type] :as x}] (defmulti do-bind (fn [a {:keys [type] :as x}]
type)) type))
@@ -280,21 +277,6 @@
keys (dissoc keys :field :subscription :event :spec)] keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest)))) (into [dom keys] (with-keys rest))))
(defmethod do-bind "typeahead-v3" [dom {:keys [field event text-event subscription class spec match->text] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)
keys (assoc keys
:on-change (fn [selected]
(re-frame/dispatch (conj (conj event field) selected))
#_(when text-field
(re-frame/dispatch (conj (conj (or text-event event) text-field) text-value))))
:value (get-in subscription field)
:class (str class
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "date" [dom {:keys [field event subscription class spec] :as keys} & rest] (defmethod do-bind "date" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field) (let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event) event (if (keyword? event) [event] event)