other pages
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.ui :refer [base-page]]
|
||||
[auto-ap.ssr.grid-page-helper :as helper]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.yodlee.core2 :as yodlee]
|
||||
@@ -15,89 +16,6 @@
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]))
|
||||
|
||||
(defn row* [{:keys [flash? yodlee-provider-account identity delete-after-settle?]}]
|
||||
(com/data-grid-row
|
||||
{:class (when flash?
|
||||
"live-added")
|
||||
"_" (hiccup/raw (when delete-after-settle?" on htmx:afterSettle wait 400ms then remove me"))}
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
(:yodlee-provider-account/id yodlee-provider-account))
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
(when-let [status (:yodlee-provider-account/status yodlee-provider-account)]
|
||||
(com/pill {:color (if (not= status "SUCCESS")
|
||||
:yellow
|
||||
:primary) }
|
||||
status)))
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
(when-let [status (:yodlee-provider-account/detailed-status yodlee-provider-account)]
|
||||
status)
|
||||
)
|
||||
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
(atime/unparse-local (:yodlee-provider-account/last-updated yodlee-provider-account)
|
||||
atime/normal-date))
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
[:ul
|
||||
(for [a (:yodlee-provider-account/accounts yodlee-provider-account)]
|
||||
[:li (:yodlee-account/name a) " - " (:yodlee-account/number a) #_[:div.tag (->$ (:available-balance a))]])])
|
||||
(com/data-grid-right-stack-cell
|
||||
{}
|
||||
(when (is-admin? identity)
|
||||
[:form
|
||||
[:input {:type :hidden :name "id" :value (:db/id yodlee-provider-account)}]
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-refresh)
|
||||
:hx-target "closest tr"}
|
||||
svg/refresh)])
|
||||
#_(when (is-admin? identity)
|
||||
[:form
|
||||
[:input {:type :hidden :name "id" :value (:db/id report)}]
|
||||
(com/icon-button {:hx-delete (str (bidi/path-for ssr-routes/only-routes
|
||||
:company-reports-delete
|
||||
:request-method :delete))
|
||||
:hx-target "closest tr"}
|
||||
svg/trash)]))))
|
||||
|
||||
(defn table* [{:keys [identity start per-page client flash-id]}]
|
||||
(let [start (or start 0)
|
||||
per-page (or per-page 30)
|
||||
[yodlee-provider-accounts total] (yodlee2/get-graphql {:id identity
|
||||
:start start
|
||||
:per-page per-page
|
||||
:client-id (:db/id client)
|
||||
:sort nil})]
|
||||
[:div
|
||||
(com/data-grid-card {:id "yodlee-table"
|
||||
:title "Yodlee Accounts"
|
||||
:entity-name "Yodlee accounts"
|
||||
:route :company-yodlee-table
|
||||
:start start
|
||||
:per-page per-page
|
||||
:total total
|
||||
:action-buttons [(com/button {:color :primary
|
||||
:on-click "openFastlink()"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-fastlink-dialog)
|
||||
:hx-target "#modal-holder"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
"Link new account")]
|
||||
:rows (for [yodlee-provider-account yodlee-provider-accounts]
|
||||
(row* {:yodlee-provider-account yodlee-provider-account
|
||||
:flash? (= flash-id
|
||||
(:db/id yodlee-provider-account))
|
||||
:identity identity}))
|
||||
:headers [(com/data-grid-header {} "Provider Account")
|
||||
(com/data-grid-header {} "Status")
|
||||
(com/data-grid-header {} "Detailed Status")
|
||||
(com/data-grid-header {} "Last Updated")
|
||||
(com/data-grid-header {:class "hidden md:table-cell"} "Accounts")
|
||||
(com/data-grid-header {})]})]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:yodlee-provider-account/last-updated
|
||||
:yodlee-provider-account/status
|
||||
@@ -106,14 +24,7 @@
|
||||
{:yodlee-provider-account/accounts [:yodlee-account/name :yodlee-account/number]
|
||||
:yodlee-provider-account/client [:client/code]}])
|
||||
|
||||
(defn refresh-provider-account [{:keys [form-params identity]}]
|
||||
(let [provider-account (dc/pull (dc/db conn) default-read (some-> (get form-params "id") not-empty Long/parseLong))]
|
||||
(yodlee/refresh-provider-account (:client/code (:yodlee-provider-account/client provider-account))
|
||||
(:yodlee-provider-account/id provider-account))
|
||||
(html-response
|
||||
(row* {:yodlee-provider-account provider-account
|
||||
:flash? true
|
||||
:identity identity}))))
|
||||
|
||||
|
||||
(defn fastlink-dialog [{:keys [session]}]
|
||||
(html-response
|
||||
@@ -136,33 +47,77 @@ fastlink.open({fastLinkURL: '%s',
|
||||
]
|
||||
[:div]))))
|
||||
|
||||
(def grid-page {:id "yodlee-table"
|
||||
:nav (com/company-aside-nav)
|
||||
:id-fn :db/id
|
||||
:fetch-page (fn [user args]
|
||||
(yodlee2/get-graphql (assoc args :id user)))
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
|
||||
(defn table [{:keys [query-params hx-query-params identity session] :as request}]
|
||||
(html-response (table* {:client (:client (:session request))
|
||||
:start (some-> (or (get query-params "start") (get hx-query-params "start")) not-empty (Long/parseLong ))
|
||||
:per-page (some-> (or (get query-params "per-page") (get hx-query-params "per-page")) not-empty (Long/parseLong ))
|
||||
:identity identity
|
||||
:session session})
|
||||
:headers {"hx-push-url" (str "?start=" (get (:query-params request) "start"))}))
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee)}
|
||||
"Yodlee"]]
|
||||
:title "Yodlee Accounts"
|
||||
:entity-name "Yodlee accounts"
|
||||
:route :company-yodlee-table
|
||||
:action-buttons (fn [user]
|
||||
[(com/button {:color :primary
|
||||
:on-click "openFastlink()"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-fastlink-dialog)
|
||||
:hx-target "#modal-holder"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
"Link new account")])
|
||||
:row-buttons (fn [user e]
|
||||
[(when (is-admin? user)
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-refresh)
|
||||
:hx-target "closest tr"}
|
||||
svg/refresh))])
|
||||
:headers [{:key "provider-account"
|
||||
:name "Provider Account"
|
||||
:sort-key "provider-account"
|
||||
:render :yodlee-provider-account/id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:yodlee-provider-account/status %)]
|
||||
(com/pill {:color (if (not= status "SUCCESS")
|
||||
:yellow
|
||||
:primary) }
|
||||
status))}
|
||||
{:key "detailed-status"
|
||||
:name "Detailed Status"
|
||||
:sort-key "detailed-status"
|
||||
:render #(when-let [status (:yodlee-provider-account/detailed-status %)]
|
||||
status)}
|
||||
|
||||
(defn page [{:keys [identity matched-route query-params :hx-query-params session] :as request}]
|
||||
(base-page
|
||||
request
|
||||
(com/page {:nav (com/company-aside-nav)
|
||||
:active-client (:client (:session request))
|
||||
:identity (:identity request)}
|
||||
(com/breadcrumbs {}
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
{:key "last-updated"
|
||||
:name "Last Updated"
|
||||
:sort-key "last-updated"
|
||||
:render #(atime/unparse-local (:yodlee-provider-account/last-updated %)
|
||||
atime/normal-date)}
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
:render (fn [e]
|
||||
[:ul
|
||||
(for [a (:yodlee-provider-account/accounts e)]
|
||||
[:li (:yodlee-account/name a) " - " (:yodlee-account/number a)])])}]})
|
||||
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee)}
|
||||
"Yodlee"]
|
||||
)
|
||||
(table* {:client (:client session)
|
||||
:start (some-> (or (get query-params "start") (get hx-query-params "start")) not-empty (Long/parseLong ))
|
||||
:per-page (some-> (or (get query-params "per-page") (get hx-query-params "per-page")) not-empty (Long/parseLong ))
|
||||
:identity identity
|
||||
:session session}))
|
||||
nil))
|
||||
(def page (partial helper/page grid-page))
|
||||
(def table (partial helper/table grid-page))
|
||||
|
||||
;; TODO delete-after-settle
|
||||
(defn refresh-provider-account [{:keys [form-params identity]}]
|
||||
(let [provider-account (dc/pull (dc/db conn) default-read (some-> (get form-params "id") not-empty Long/parseLong))]
|
||||
(yodlee/refresh-provider-account (:client/code (:yodlee-provider-account/client provider-account))
|
||||
(:yodlee-provider-account/id provider-account))
|
||||
(html-response
|
||||
(helper/row*
|
||||
grid-page
|
||||
identity
|
||||
provider-account
|
||||
{:flash? true}))))
|
||||
|
||||
Reference in New Issue
Block a user