progress for accounts

This commit is contained in:
Bryce
2023-10-22 21:32:36 -07:00
parent bd1d603eb6
commit 76760b7bcf
2 changed files with 112 additions and 83 deletions

View File

@@ -34,7 +34,8 @@
[clojure.string :as str]
[datomic.api :as dc]
[hiccup2.core :as hiccup]
[malli.core :as mc]))
[malli.core :as mc]
[auto-ap.ssr.form-cursor :as fc]))
(defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -213,96 +214,122 @@
;; TODO use cursor
;; TODO index based list not dbid
(defn client-override* [override index]
(defn client-override* [override]
[:div.flex.gap-2.mb-2.client-override
[:div.w-96
(com/hidden {:name (format "account/client-overrides[%s][db/id]" index)
:value (:db/id override)})
(com/typeahead-2 {:name (format "account/client-overrides[%s][account-client-override/client]" index)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:company-search)
:id (str "account-client-override-" (:db/id override))
:value [(:db/id (:account-client-override/client override))
(:client/name (:account-client-override/client override))]})]
[:div.w-96
(com/text-input {:name (format "account/client-overrides[%s][account-client-override/name]" index)
:class "w-full"
:value (:account-client-override/name override)})]
[:div (com/a-icon-button {"_" (hiccup/raw "on click halt the event then transition the closest <.client-override />'s opacity to 0 then remove closest <.client-override />") } svg/x)]])
(fc/with-field :db/id
(com/hidden {:name (fc/field-name)
:value (fc/field-value)}))
(fc/with-field :account-client-override/client
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes
:company-search)
:value (fc/field-value)
:value-fn :db/id ;; TODO hydration something here
:content-fn :client/name}))]
(fc/with-field :account-client-override/name
[:div.w-96
(com/text-input {:name (fc/field-name)
:class "w-full"
:value (fc/field-value)})])
[:div (com/a-icon-button {"_" (hiccup/raw "on click halt the event then transition the closest <.client-override />'s opacity to 0 then remove closest <.client-override />")} svg/x)]])
;; TODO each form:
;; elimante typeahead1
;; work with new dialog
;; use cursor
;; ensure all dialogs are opened the same way
;; form level validation
;; form level validation
;; componentize
;; ensure all dependency oriented stuff works the same way
;; make sure that "new row index" stuff works ok
(defn dialog* [& {:keys [ account form-params]}]
(defn dialog* [& {:keys [account form-params form-errors]}]
(com/modal
{}
[:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target-400 "#form-errors .error-content"}
form-params)
[:fieldset {:class "hx-disable"}
(com/modal-card
{}
[:div.flex [:div.p-2 "Account"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600 (:account/numeric-code account) " - " (:account/name account)]]
[:div.space-y-6
(when-let [id (:db/id account)]
(com/hidden {:name "db/id"
:value id}))
(when (nil? account)
(com/field {:label "Numeric code"}
(com/text-input {:name "account/numeric-code"
:autofocus true
:class "w-32"})))
(com/field {:label "Name"}
(com/text-input {:name "account/name"
:autofocus true
:class "w-32"
:value (:account/name account)}))
(com/field {:label "Account Type"}
(com/select {:name "account/type"
:class "w-36"
:id "type"
:value (some-> account :account/type name)
:options (ref->select-options "account-type")}))
(com/field {:label "Location"}
(com/text-input {:name "account/location"
:class "w-16"
:value (:account/location account)}))
{}
[:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target-400 "#form-errors .error-content"}
form-params)
[:fieldset {:class "hx-disable"}
(com/modal-card
{}
[:div.flex [:div.p-2 "Account"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600 (:account/numeric-code account) " - " (:account/name account)]]
(com/field {:label "Invoice Allowance"}
(com/select {:name "account/invoice-allowance"
:value (some-> account :account/invoice-allowance name)
:class "w-36"
:options (ref->select-options "allowance")}))
(com/field {:label "Vendor Allowance"}
(com/select {:name "account/vendor-allowance"
:class "w-36"
:value (some-> account :account/vendor-allowance name)
:options (ref->select-options "allowance")}))
(com/field {:label "Applicability"}
(com/select {:name "account/applicability"
:class "w-36"
:value (some-> account :account/applicability name)
:options (ref->select-options "account-applicability")}))
(fc/start-form
account form-errors
[:div.space-y-1
(when-let [id (:db/id account)]
(com/hidden {:name "db/id"
:value id}))
(com/field {:label "Client Overrides" :id "client-overrides"}
(for [[override index] (map vector (:account/client-overrides account) (range))]
(client-override* override index)))
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-account-client-override-new)
:hx-vals (hiccup/raw "js:{index: document.getElementById('client-overrides').children.length - 1}")
:hx-target "#client-overrides"
:hx-swap "beforeend"}
"New override")
[:div#form-errors [:span.error-content]]
]
(com/validated-save-button {:errors []} ;; TODO
"Save account"))]]))
(fc/with-field :account/numeric-code
(when (nil? (fc/field-value))
(com/field {:label "Numeric code"}
(com/text-input {:name (fc/field-name)
:autofocus true
:class "w-32"}))))
(fc/with-field :account/name
(com/field {:label "Name"}
(com/text-input {:name (fc/field-name)
:autofocus true
:class "w-32"
:value (fc/field-value)})))
(fc/with-field :account/type
(com/field {:label "Account Type"}
(com/select {:name (fc/field-name)
:class "w-36"
:id "type"
:value (some-> (fc/field-value) name)
:options (ref->select-options "account-type")})))
(fc/with-field :account/location
(com/field {:label "Location"}
(com/text-input {:name (fc/field-name)
:class "w-16"
:value (fc/field-value)})))
(fc/with-field :account/invoice-allowance
(com/field {:label "Invoice Allowance"}
(com/select {:name (fc/field-name)
:value (some-> (fc/field-value) name)
:class "w-36"
:options (ref->select-options "allowance")})))
(fc/with-field :account/vendor-allowance
(com/field {:label "Vendor Allowance"}
(com/select {:name (fc/field-name)
:class "w-36"
:value (some-> (fc/field-value) name)
:options (ref->select-options "allowance")})))
(fc/with-field :account/applicability
(com/field {:label "Applicability"}
(com/select {:name (fc/field-name)
:class "w-36"
:value (some-> (fc/field-value) name)
:options (ref->select-options "account-applicability")})))
(fc/with-field :account/client-overrides
(com/field {:label "Client Overrides" :id "client-overrides"}
(when (fc/field-value)
(doall
(for [override fc/*current*]
(fc/with-cursor override
(client-override* override)))))))
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-account-client-override-new)
:hx-vals (hiccup/raw "js:{index: document.getElementById('client-overrides').children.length - 1}")
:hx-target "#client-overrides"
:hx-swap "beforeend"}
"New override")
[:div#form-errors [:span.error-content]]])
(com/validated-save-button {:errors []} ;; TODO
"Save account"))]]))
(defn new-client-override [{ {:keys [index]} :query-params}]
(html-response
(client-override* {:db/id (str (java.util.UUID/randomUUID))}
index)))
(client-override* {:db/id (str (java.util.UUID/randomUUID))})))
(defn account-edit-dialog [request]
(let [account (some-> request :route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]

View File

@@ -406,7 +406,7 @@
[:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target "#modal-holder"
:hx-target "#modal-holder" ;; TODO sort
:hx-target-400 "#form-errors .error-content"
:x-trap "true"
:class "group/form"}
@@ -414,7 +414,8 @@
(com/modal-card
{}
[:div.flex [:div.p-2 "Transaction Rule"]]
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target"
[:fieldset {:class "hx-disable"
:hx-disinherit "hx-target" ;; TODO why disinherit
:x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client entity))
(:transaction-rule/client entity))})}
@@ -561,6 +562,7 @@
:color :secondary
:hx-include "#edit-form"
:hx-ext "rename-params"
;; TODO
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")