Uses cursors for simplicity, uses common grid bottom
This commit is contained in:
@@ -248,7 +248,8 @@
|
||||
(defn client-override* [override]
|
||||
(com/data-grid-row (-> {:x-ref "p"
|
||||
:data-key "show"
|
||||
:x-data (hx/json {:show (boolean (not (:new? override)))})}
|
||||
:x-data (hx/json {:show (boolean (doto (not (fc/field-value (:new? override)))
|
||||
println))})}
|
||||
hx/alpine-mount-then-appear)
|
||||
(fc/with-field :db/id
|
||||
(com/hidden {:name (fc/field-name)
|
||||
@@ -378,19 +379,12 @@
|
||||
:id "client-override-table"}
|
||||
(fc/cursor-map
|
||||
#(client-override* %))
|
||||
(com/data-grid-row
|
||||
{:class "new-row"}
|
||||
(com/data-grid-cell {:colspan 3
|
||||
:class "bg-gray-100"}
|
||||
[:div.flex.justify-center
|
||||
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-client-override-new)
|
||||
:color :secondary
|
||||
:hx-include "#edit-form"
|
||||
:hx-vals (hiccup/raw "js:{index: countRows(\"#client-override-table\")}")
|
||||
:hx-target "#edit-form .new-row"
|
||||
:hx-swap "beforebegin"}
|
||||
"New override")])))))
|
||||
|
||||
(com/data-grid-new-row {:colspan 3
|
||||
:index (count (fc/field-value))
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-client-override-new)}
|
||||
"New override"))))
|
||||
|
||||
]
|
||||
[:div
|
||||
@@ -401,14 +395,13 @@
|
||||
"Save account")])]])]))
|
||||
|
||||
(defn new-client-override [{ {:keys [index]} :query-params}]
|
||||
(let [index (or index 0)
|
||||
account {:account/client-overrides (conj (into [] (repeat index {}))
|
||||
{:db/id (str (java.util.UUID/randomUUID))
|
||||
:new? true})}] ;; TODO schema decode is not working
|
||||
(html-response
|
||||
(fc/start-form account []
|
||||
(fc/with-cursor (get-in fc/*current* [:account/client-overrides index])
|
||||
(client-override* fc/*current*))))))
|
||||
(html-response
|
||||
(fc/start-form-with-prefix
|
||||
[:account/client-overrides (or index 0)]
|
||||
{:db/id (str (java.util.UUID/randomUUID))
|
||||
:new? true}
|
||||
[]
|
||||
(client-override* fc/*current*))))
|
||||
|
||||
(defn account-edit-dialog [request]
|
||||
(let [account (some-> request :route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]
|
||||
|
||||
@@ -543,31 +543,18 @@
|
||||
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
|
||||
|
||||
(fc/with-field :transaction-rule/accounts
|
||||
(list
|
||||
(com/data-grid {:headers [(com/data-grid-header {} "Account")
|
||||
(com/data-grid-header {:class "w-32"} "Location")
|
||||
(com/data-grid-header {:class "w-16"} "%")
|
||||
(com/data-grid-header {:class "w-16"})]
|
||||
:id "transaction-rule-account-table"}
|
||||
(fc/cursor-map #(transaction-rule-account-row* entity %))
|
||||
(com/data-grid-row
|
||||
{:class "new-row"}
|
||||
(com/data-grid-cell {:colspan 4
|
||||
:class "bg-gray-100"}
|
||||
[:div.flex.justify-center
|
||||
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-transaction-rule-new-account)
|
||||
: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\")}")
|
||||
:hx-target "#edit-form .new-row"
|
||||
:hx-swap "beforebegin"}
|
||||
"New account")])))
|
||||
(com/errors {:errors (fc/field-errors)})))
|
||||
(com/data-grid {:headers [(com/data-grid-header {} "Account")
|
||||
(com/data-grid-header {:class "w-32"} "Location")
|
||||
(com/data-grid-header {:class "w-16"} "%")
|
||||
(com/data-grid-header {:class "w-16"})]
|
||||
:id "transaction-rule-account-table"}
|
||||
(fc/cursor-map #(transaction-rule-account-row* entity %))
|
||||
(com/data-grid-new-row {:colspan 4
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-transaction-rule-new-account)
|
||||
:index (count (fc/field-value))
|
||||
:tr-params (hx/bind-alpine-vals {} {:client-id "clientId"})}
|
||||
"New account")))
|
||||
|
||||
(fc/with-field :transaction-rule/transaction-approval-status
|
||||
(com/validated-field {:label "Approval status"
|
||||
@@ -578,7 +565,6 @@
|
||||
:size :small
|
||||
:orientation :horizontal})))
|
||||
|
||||
;; TODO componentize
|
||||
]]
|
||||
[:div
|
||||
[:div#form-errors (when (:errors fc/*form-errors*)
|
||||
@@ -593,21 +579,21 @@
|
||||
;; pull out the single field to swap
|
||||
|
||||
(defn new-account [{{:keys [client-id index]} :query-params}]
|
||||
(let [index (or index 0) ;; TODO schema decode is not working
|
||||
transaction-rule {:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
|
||||
client-id)
|
||||
:transaction-rule/accounts (conj (into [] (repeat index {} ))
|
||||
{:db/id (str (java.util.UUID/randomUUID))
|
||||
:transaction-rule-account/location "Shared"
|
||||
:new? true})}]
|
||||
(html-response
|
||||
(fc/start-form transaction-rule []
|
||||
(fc/with-cursor (get-in fc/*current* [:transaction-rule/accounts index])
|
||||
(transaction-rule-account-row*
|
||||
;; TODO store a pointer to the "head " cursor for errors instead of nesting them
|
||||
;; makes it so you don't have to do this
|
||||
transaction-rule
|
||||
fc/*current*))))))
|
||||
(html-response
|
||||
(fc/start-form-with-prefix
|
||||
[:transaction-rule/accounts (or index 0)]
|
||||
{:db/id (str (java.util.UUID/randomUUID))
|
||||
:transaction-rule-account/location "Shared"
|
||||
:new? true}
|
||||
[]
|
||||
(transaction-rule-account-row*
|
||||
;; TODO store a pointer to the "head " cursor for errors instead of nesting them
|
||||
;; makes it so you don't have to do this
|
||||
|
||||
{:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
|
||||
client-id)}
|
||||
|
||||
fc/*current*))))
|
||||
|
||||
|
||||
;; TODO check to see if it should be called "Shared" or "shared" for the value
|
||||
|
||||
Reference in New Issue
Block a user