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] [clojure.string :as str]
[datomic.api :as dc] [datomic.api :as dc]
[hiccup2.core :as hiccup] [hiccup2.core :as hiccup]
[malli.core :as mc])) [malli.core :as mc]
[auto-ap.ssr.form-cursor :as fc]))
(defn filters [request] (defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms" [:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -213,26 +214,40 @@
;; TODO use cursor ;; TODO use cursor
;; TODO index based list not dbid ;; TODO index based list not dbid
(defn client-override* [override index] (defn client-override* [override]
[:div.flex.gap-2.mb-2.client-override [:div.flex.gap-2.mb-2.client-override
[:div.w-96 [:div.w-96
(com/hidden {:name (format "account/client-overrides[%s][db/id]" index) (fc/with-field :db/id
:value (:db/id override)}) (com/hidden {:name (fc/field-name)
(com/typeahead-2 {:name (format "account/client-overrides[%s][account-client-override/client]" index) :value (fc/field-value)}))
(fc/with-field :account-client-override/client
(com/typeahead-2 {:name (fc/field-name)
:placeholder "Search..." :placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :url (bidi/path-for ssr-routes/only-routes
:company-search) :company-search)
:id (str "account-client-override-" (:db/id override)) :value (fc/field-value)
:value [(:db/id (:account-client-override/client override)) :value-fn :db/id ;; TODO hydration something here
(:client/name (:account-client-override/client override))]})] :content-fn :client/name}))]
(fc/with-field :account-client-override/name
[:div.w-96 [:div.w-96
(com/text-input {:name (format "account/client-overrides[%s][account-client-override/name]" index) (com/text-input {:name (fc/field-name)
:class "w-full" :class "w-full"
:value (:account-client-override/name override)})] :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)]]) [: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 (com/modal
{} {}
[:form#edit-form (merge {:hx-ext "response-targets" [:form#edit-form (merge {:hx-ext "response-targets"
@@ -243,66 +258,78 @@
(com/modal-card (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.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
(fc/start-form
account form-errors
[:div.space-y-1
(when-let [id (:db/id account)] (when-let [id (:db/id account)]
(com/hidden {:name "db/id" (com/hidden {:name "db/id"
:value id})) :value id}))
(when (nil? account) (fc/with-field :account/numeric-code
(when (nil? (fc/field-value))
(com/field {:label "Numeric code"} (com/field {:label "Numeric code"}
(com/text-input {:name "account/numeric-code" (com/text-input {:name (fc/field-name)
:autofocus true :autofocus true
:class "w-32"}))) :class "w-32"}))))
(fc/with-field :account/name
(com/field {:label "Name"} (com/field {:label "Name"}
(com/text-input {:name "account/name" (com/text-input {:name (fc/field-name)
:autofocus true :autofocus true
:class "w-32" :class "w-32"
:value (:account/name account)})) :value (fc/field-value)})))
(fc/with-field :account/type
(com/field {:label "Account Type"} (com/field {:label "Account Type"}
(com/select {:name "account/type" (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:id "type" :id "type"
:value (some-> account :account/type name) :value (some-> (fc/field-value) name)
:options (ref->select-options "account-type")})) :options (ref->select-options "account-type")})))
(fc/with-field :account/location
(com/field {:label "Location"} (com/field {:label "Location"}
(com/text-input {:name "account/location" (com/text-input {:name (fc/field-name)
:class "w-16" :class "w-16"
:value (:account/location account)})) :value (fc/field-value)})))
(fc/with-field :account/invoice-allowance
(com/field {:label "Invoice Allowance"} (com/field {:label "Invoice Allowance"}
(com/select {:name "account/invoice-allowance" (com/select {:name (fc/field-name)
:value (some-> account :account/invoice-allowance name) :value (some-> (fc/field-value) name)
:class "w-36" :class "w-36"
:options (ref->select-options "allowance")})) :options (ref->select-options "allowance")})))
(fc/with-field :account/vendor-allowance
(com/field {:label "Vendor Allowance"} (com/field {:label "Vendor Allowance"}
(com/select {:name "account/vendor-allowance" (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:value (some-> account :account/vendor-allowance name) :value (some-> (fc/field-value) name)
:options (ref->select-options "allowance")})) :options (ref->select-options "allowance")})))
(fc/with-field :account/applicability
(com/field {:label "Applicability"} (com/field {:label "Applicability"}
(com/select {:name "account/applicability" (com/select {:name (fc/field-name)
:class "w-36" :class "w-36"
:value (some-> account :account/applicability name) :value (some-> (fc/field-value) name)
:options (ref->select-options "account-applicability")})) :options (ref->select-options "account-applicability")})))
(fc/with-field :account/client-overrides
(com/field {:label "Client Overrides" :id "client-overrides"} (com/field {:label "Client Overrides" :id "client-overrides"}
(for [[override index] (map vector (:account/client-overrides account) (range))] (when (fc/field-value)
(client-override* override index))) (doall
(for [override fc/*current*]
(fc/with-cursor override
(client-override* override)))))))
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes (com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-account-client-override-new) :admin-account-client-override-new)
:hx-vals (hiccup/raw "js:{index: document.getElementById('client-overrides').children.length - 1}") :hx-vals (hiccup/raw "js:{index: document.getElementById('client-overrides').children.length - 1}")
:hx-target "#client-overrides" :hx-target "#client-overrides"
:hx-swap "beforeend"} :hx-swap "beforeend"}
"New override") "New override")
[:div#form-errors [:span.error-content]] [:div#form-errors [:span.error-content]]])
]
(com/validated-save-button {:errors []} ;; TODO (com/validated-save-button {:errors []} ;; TODO
"Save account"))]])) "Save account"))]]))
(defn new-client-override [{ {:keys [index]} :query-params}] (defn new-client-override [{ {:keys [index]} :query-params}]
(html-response (html-response
(client-override* {:db/id (str (java.util.UUID/randomUUID))} (client-override* {:db/id (str (java.util.UUID/randomUUID))})))
index)))
(defn account-edit-dialog [request] (defn account-edit-dialog [request]
(let [account (some-> request :route-params :db/id (#(dc/pull (dc/db conn) default-read %)))] (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" [:form#edit-form (merge {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms" :hx-swap "outerHTML swap:300ms"
:hx-target "#modal-holder" :hx-target "#modal-holder" ;; TODO sort
:hx-target-400 "#form-errors .error-content" :hx-target-400 "#form-errors .error-content"
:x-trap "true" :x-trap "true"
:class "group/form"} :class "group/form"}
@@ -414,7 +414,8 @@
(com/modal-card (com/modal-card
{} {}
[:div.flex [:div.p-2 "Transaction Rule"]] [: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)) :x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client entity))
(:transaction-rule/client entity))})} (:transaction-rule/client entity))})}
@@ -561,6 +562,7 @@
:color :secondary :color :secondary
:hx-include "#edit-form" :hx-include "#edit-form"
:hx-ext "rename-params" :hx-ext "rename-params"
;; TODO
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id" :hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"}) "index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}") :hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")