changes for running.

This commit is contained in:
2023-10-28 12:17:01 -07:00
parent 0f74b71cd1
commit 855c23f4ae
13 changed files with 122 additions and 68 deletions

View File

@@ -188,7 +188,12 @@
:color :primary}
"New Transaction Rule")])
:row-buttons (fn [request entity]
[(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
[
(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-execute-results
:db/id (:db/id entity)))}
svg/play)
(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-dialog
:db/id (:db/id entity)))}
svg/pencil)])
@@ -304,15 +309,18 @@
:transaction/description-original
[:transaction/date :xform clj-time.coerce/from-date]])
(defn transaction-rule-test [{:keys [form-params request-method identity] :as request
{:transaction-rule/keys [description client bank-account amount-lte amount-gte dom-lte dom-gte yodlee-merchant]} :form-params}]
(validate-transaction-rule form-params)
(let [valid-clients (extract-client-ids (:clients request)
(defn transaction-rule-test-table* [{{:transaction-rule/keys [description client bank-account amount-lte amount-gte dom-lte dom-gte yodlee-merchant]}
:entity
clients :clients
checkboxes? :checkboxes?}]
(let [valid-clients (extract-client-ids clients
client)
query (cond-> {:query {:find ['(pull ?e read)]
:in ['$ 'read]
:where []}
:args [(dc/db conn) transaction-read]}
:in ['$ 'read]
:where []}
:args [(dc/db conn) transaction-read]}
description
(merge-query {:query {:in ['?descr]
:where ['[(iol-ion.query/->pattern ?descr) ?description-regex]]}
@@ -358,52 +366,60 @@
'[(>= ?dom ?dom-gte)]]}
:args [dom-gte]})
client
(merge-query {:query {:in ['?client-id]
:where ['[?e :transaction/client ?client-id]]}
:args [client]})
true
(merge-query {:query {:where ['[?e :transaction/id]]}}))
results (->>
(query2 query)
(map first))]
(html-response
(com/stacked-modal-card
1
{}
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"] [:div.ml-4.relative (com/badge {} (count results))]]
(com/data-grid
{:headers [(com/data-grid-header {} "Client")
(com/data-grid-header {} "Bank")
(com/data-grid-header {} "Date")
(com/data-grid-header {} "Description")]}
(for [r (take 15 results)]
(com/data-grid-row
{}
(com/data-grid-cell {} (-> r :transaction/client :client/name))
(com/data-grid-cell {} (-> r :transaction/bank-account :bank-account/name))
(com/data-grid-cell {} (some-> r :transaction/date (atime/unparse-local atime/normal-date)))
(com/data-grid-cell {} (some-> r :transaction/description-original )))))
[:div.flex.justify-between
(com/button {"@click" "$dispatch('modalpop')"
:class "w-32"}
"Back")
(com/button (cond-> {:color :primary
:hx-vals (hx/json (:raw-form-params request))
:class "w-32"
}
(:db/id form-params) (assoc :hx-put (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save))
(not (:db/id form-params)) (assoc :hx-post (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save)))
"Save rule")
])
:headers (-> {}
(assoc "hx-trigger-after-settle" "modalnext")
(assoc "hx-retarget" ".modal-stack")
(assoc "hx-reswap" "beforeend")))))
[:div
[:h2.my-4.text-lg.flex "Matching transactions" [:div.ml-4.relative (com/badge {:class "text-[0.6rem]"} (let [cnt (count results)]
(if (>= cnt 99)
"99+"
cnt)))]]
(com/data-grid
{:headers [(when checkboxes?
(com/data-grid-checkbox-header {}))
(com/data-grid-header {} "Client")
(com/data-grid-header {} "Bank")
(com/data-grid-header {} "Date")
(com/data-grid-header {} "Description")]}
(for [r (take 15 results)]
(com/data-grid-row
{}
(when checkboxes?
(com/data-grid-cell {} (com/checkbox {})))
(com/data-grid-cell {} (-> r :transaction/client :client/name))
(com/data-grid-cell {} (-> r :transaction/bank-account :bank-account/name))
(com/data-grid-cell {} (some-> r :transaction/date (atime/unparse-local atime/normal-date)))
(com/data-grid-cell {} (some-> r :transaction/description-original )))))]))
(defn transaction-rule-test [{:keys [form-params request-method identity] :as request
entity :form-params}]
(validate-transaction-rule form-params)
(html-response
(com/stacked-modal-card
1
{}
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"] [:div.ml-4.relative (com/badge {} 100 #_(count results))]]
(transaction-rule-test-table* {:entity entity
:clients (:clients request)})
[:div.flex.justify-between
(com/button {"@click" "$dispatch('modalpop')"
:class "w-32"}
"Back")
(com/button (cond-> {:color :primary
:hx-vals (hx/json (:raw-form-params request))
:class "w-32"
}
(:db/id form-params) (assoc :hx-put (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save))
(not (:db/id form-params)) (assoc :hx-post (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-save)))
"Save rule")])
:headers (-> {}
(assoc "hx-trigger-after-settle" "modalnext")
(assoc "hx-retarget" ".modal-stack")
(assoc "hx-reswap" "beforeend"))))
@@ -502,18 +518,20 @@
(fc/start-form form-params form-errors
(com/modal
{:modal-class "max-w-2xl"
:hx-target "this"}
:hx-target "this"
}
(com/stacked-modal-card
0
{}
[:div.flex [:div.p-2 "Transaction Rule"]]
[:form#my-form {:hx-ext "response-targets"
:hx-target-400 "#form-errors .error-content"
:x-trap "true"
(if (:db/id entity)
:hx-put
:hx-post) (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-edit-save))}
:hx-target-400 "#form-errors .error-content"
:hx-indicator "#submit"
:x-trap "true"
(if (:db/id entity)
:hx-put
:hx-post) (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-edit-save))}
[:fieldset {:class "hx-disable"
:x-data (hx/json {:clientId (or (:db/id (:transaction-rule/client form-params))
(:transaction-rule/client form-params)
@@ -671,6 +689,7 @@
"Test rule")
(com/validated-save-button {:errors form-errors
:id "submit"
:form "my-form"} "Save rule")]]))))
@@ -732,6 +751,22 @@
{})
:form-errors form-errors})))
(defn transaction-rule-execute-results [{:keys [entity clients]}]
(modal-response
(com/modal{}
(com/stacked-modal-card
0
{}
[:div.p-2.flex.space-x-4 [:div "Transaction Rule"] [:div ">"] [:div "Results"]]
(transaction-rule-test-table* {:entity entity
:clients clients
:checkboxes? true})
[:div.flex.justify-end (com/validated-save-button {:form "my-form"} "Code transactions")]))
:headers (-> {}
(assoc "hx-trigger-after-settle" "modalnext")
(assoc "hx-retarget" ".modal-stack")
(assoc "hx-reswap" "beforeend"))))
(def key->handler
@@ -773,6 +808,10 @@
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read))))
:admin-transaction-rule-execute-results (-> transaction-rule-execute-results
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
:admin-transaction-rule-filled-account (-> transaction-dialog
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)

View File

@@ -27,6 +27,7 @@
(def stacked-modal-card dialog/stacked-modal-card-)
(def text-input inputs/text-input-)
(def checkbox inputs/checkbox-)
(def money-input inputs/money-input-)
(def int-input inputs/int-input-)
(def date-input inputs/date-input-)
@@ -58,6 +59,7 @@
(def data-grid-header data-grid/header-)
(def data-grid-sort-header data-grid/sort-header-)
(def data-grid-row data-grid/row-)
(def data-grid-checkbox-header data-grid/checkbox-header-)
(def data-grid-cell data-grid/cell-)
(def data-grid-right-stack-cell data-grid/right-stack-cell-)
(def data-grid-new-row data-grid/new-row-)

View File

@@ -120,7 +120,7 @@
(update params :class
#(cond-> %
true (str " inline-flex items-center justify-center items-center p-3 text-sm font-medium border border-gray-300 dark:border-gray-700 text-center rounded-lg ")
true (str " inline-flex items-center justify-center items-center p-3 text-sm font-medium border border-gray-300 dark:border-gray-700 text-center rounded-lg hover:scale-110")
(= :secondary (:color params)) (str " bg-blue-500 hover:bg-blue-600 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700")
(= :primary (:color params)) (str " bg-green-500 hover:bg-green-600 focus:ring-green-300 dark:bg-green-600 dark:hover:bg-green-700 ")
(= :primary-light (:color params)) (str " bg-green-200 hover:bg-green-300 focus:ring-green-200 dark:bg-green-700 dark:hover:bg-green-600 text-gray-800 dark:text-gray-200")

View File

@@ -6,7 +6,8 @@
[auto-ap.ssr.components.buttons :refer [a-button-]]
[bidi.bidi :as bidi]
[hiccup2.core :as hiccup]
[auto-ap.ssr.hx :as hx]))
[auto-ap.ssr.hx :as hx]
[auto-ap.ssr.components.inputs :as inputs]))
(defn header- [params & rest]
(into [:th.px-4.py-3 {:scope "col" :class (:class params)
@@ -30,13 +31,12 @@
(defn right-stack-cell- [params & rest]
(cell- params (into [:div.flex.flex-row-reverse.items-center.justify-between
rest]))
)
rest])))
(defn checkbox-header- [params & rest]
[:th {:scope "col", :class "p-4"}
[:div {:class "flex items-center"}
[:input {:id "checkbox-all", :type "checkbox", :class "w-4 h-4 bg-gray-100 border-gray-300 rounded text-primary-600 focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"}]
[:input {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes}]
[:label {:for "checkbox-all", :class "sr-only"} "checkbox"]]])
(defn data-grid- [{:keys [headers thead-params id]} & rest]

View File

@@ -48,7 +48,7 @@
(defn stacked-modal-card- [index params header content footer]
[:div (merge params
{:class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col"
{:class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col h-full"
:x-data (hx/json {:i index})
:x-show "index == i && hidingIndex != i"
"x-transition:enter" "transition duration-150",

View File

@@ -19,6 +19,9 @@
"group-[.has-error]:dark:border-red-500"])
(def default-checkbox-classes
"w-4 h-4 bg-gray-100 border-gray-300 rounded text-primary-600 focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600")
(defn select- [params & children]
(into
[:select (-> params
@@ -199,3 +202,7 @@
(defn hidden- [{:keys [name value]}]
[:input {:type "hidden" :value value :name name}])
(defn checkbox- [params & rest]
[:input {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))}
rest])

View File

@@ -1,4 +1,5 @@
(ns auto-ap.ssr.components.tags)
(ns auto-ap.ssr.components.tags
(:require [auto-ap.ssr.hiccup-helper :as hh]))
(defn pill- [params & children]
@@ -20,4 +21,4 @@
children))
(defn badge- [params & children]
[:div {:class "absolute inline-flex items-center justify-center w-6 h-6 text-xs font-bold text-white bg-red-300 border-3 border-white rounded-full -top-2 -right-2 dark:border-gray-900"} children])
[:div {:class (hh/add-class "absolute inline-flex items-center justify-center w-6 h-6 text-xs font-bold text-white bg-red-300 border-3 border-white rounded-full -top-2 -right-2 dark:border-gray-900" (:class params))} children])

View File

@@ -31,7 +31,7 @@
(:class header))}
((:render header) entity)))))
cells (conj cells (com/data-grid-right-stack-cell {}
(into [:form
(into [:form.flex.space-x-2
[:input {:type :hidden :name "id" :value ((:id-fn gridspec) entity)}]]
((:row-buttons gridspec) request entity))))] ;; TODO double check usage of row buttons user and identity in callers
(apply com/data-grid-row

View File

@@ -72,9 +72,7 @@
(nested-params-request request {}))
([request options]
(let [parse (:key-parser options parse-nested-keys)]
(-> request
(assoc :raw-form-params (:form-params request))
(update-in [:form-params] nest-params parse)))))
(update-in request [:form-params] nest-params parse))))
(defn wrap-nested-form-params
"Middleware to converts a flat map of parameters into a nested map.

View File

@@ -170,6 +170,11 @@
:stroke "currentColor",
:stroke-linecap "round",
:stroke-linejoin "round"}]])
(def play
[:svg {:xmlns "http://www.w3.org/2000/svg", :viewbox "-0.5 -0.5 24 24"}
[:defs]
[:title "controls-play"]
[:path {:d "M1.071416666666667 2.02975a0.9583333333333334 0.9583333333333334 0 0 1 1.3867083333333334 -0.85675l18.9405 9.47025a0.9583333333333334 0.9583333333333334 0 0 1 0 1.7135L2.458125 21.827a0.9583333333333334 0.9583333333333334 0 0 1 -1.3867083333333334 -0.85675Z", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]])
(def pencil
[:svg

View File

@@ -292,7 +292,8 @@
(fc/start-form
form-params form-errors
(com/modal
{:hx-target "this"}
{:hx-target "this"
:hx-indicator "this"}
[:form {:hx-ext "response-targets"
:hx-put (str (bidi/path-for ssr-routes/only-routes
:user-edit-save

View File

@@ -44,6 +44,7 @@
"/test" :admin-transaction-rule-test
"/new" {:get :admin-transaction-rule-new-dialog}
[[#"\d+" :db/id] "/edit"] :admin-transaction-rule-edit-dialog
[[#"\d+" :db/id] "/run"] :admin-transaction-rule-execute-results
}}
"transaction" {"/insights" {"" :transaction-insights
"/table" :transaction-insight-table