changes.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
[:footer.modal-card-foot
|
||||
foot])]])
|
||||
|
||||
(defn action-modal [{:keys [title action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
|
||||
(defn action-modal [{:keys [title warning action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
|
||||
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id status-from])]
|
||||
(when visible?
|
||||
[:form {:id id
|
||||
@@ -41,6 +41,8 @@
|
||||
:id id
|
||||
:hide-event [::events/modal-status id {:visible? false}]}
|
||||
(when error-message
|
||||
[:div.notification.is-warning error-message])]
|
||||
[:div.notification.is-warning error-message])
|
||||
(when warning
|
||||
[:div.notification.is-info warning])]
|
||||
(into (r/children (r/current-component)))
|
||||
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))])))
|
||||
|
||||
@@ -6,14 +6,34 @@
|
||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||
|
||||
[auto-ap.expense-accounts :refer [chooseable-expense-accounts]]
|
||||
[clj-fuzzy.metrics :refer [jaccard]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.vendors :as entity]
|
||||
[auto-ap.entities.contact :as contact]
|
||||
[auto-ap.subs :as subs]))
|
||||
(defn ngrams [text len]
|
||||
(mapv #(.toLowerCase (str/join "" %))
|
||||
(partition len 1 text)))
|
||||
|
||||
(defn partial-matches-vendor? [text vendors]
|
||||
(when (> (count text) 4)
|
||||
(let [text (.toLowerCase text)]
|
||||
(->> vendors
|
||||
(map :name)
|
||||
(mapcat
|
||||
(fn [v] (mapv
|
||||
(fn [n] [v (jaccard text n )])
|
||||
(ngrams v (count text)))))
|
||||
#_(sort-by second)
|
||||
(filter #(< (second %) 0.3))
|
||||
(map first)
|
||||
first))))
|
||||
|
||||
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
|
||||
(println (s/explain ::entity/vendor vendor) )
|
||||
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])]
|
||||
|
||||
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])
|
||||
all-vendors @(re-frame/subscribe [::subs/vendors])]
|
||||
[action-modal {:id id
|
||||
:title [:span (if (:id vendor)
|
||||
(str "Edit " (or name "<vendor>"))
|
||||
@@ -21,12 +41,12 @@
|
||||
(when (:error vendor)
|
||||
[:span.icon.has-text-danger
|
||||
[:i.fa.fa-exclamation-triangle]])]
|
||||
:warning (when-let [vendor (partial-matches-vendor? (:name vendor) all-vendors)]
|
||||
(str "Are you sure you don't mean " vendor "?"))
|
||||
:action-text "Save"
|
||||
:save-event save-event
|
||||
:can-submit? (s/valid? ::entity/vendor vendor)}
|
||||
|
||||
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
|
||||
Reference in New Issue
Block a user