opened yodlee up.
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
(ns auto-ap.views.pages.admin.yodlee2
|
||||
(:require
|
||||
[auto-ap.effects.forward :as forward]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.yodlee2.table :as table]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::authentication
|
||||
(fn [db]
|
||||
(-> db ::authentication)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
:<- [::table/params]
|
||||
(fn [table-params]
|
||||
table-params))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::yodlee-provider-accounts
|
||||
(fn [db]
|
||||
(::yodlee-provider-accounts db)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
(fn [_ [_ params]]
|
||||
{:set-uri-params params}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::page
|
||||
:<- [::params]
|
||||
:<- [::yodlee-provider-accounts]
|
||||
(fn [[params all-yodlee-provider-accounts]]
|
||||
(assoc (grid/virtual-paginate-controls (:start params ) (:per-page params) (:yodlee-provider-accounts all-yodlee-provider-accounts) )
|
||||
:data (grid/virtual-paginate (:start params) (:per-page params) (:yodlee-provider-accounts all-yodlee-provider-accounts)))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::data-requested
|
||||
(fn [{:keys [db]} _]
|
||||
{:graphql {:token (:user db)
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[[:yodlee-provider-accounts [:id :last-updated :status :detailed-status
|
||||
[:client [:id]]
|
||||
[:accounts [:id :name :number :available-balance]]]]
|
||||
:count]]]}
|
||||
:on-success [::received]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::data-requested]
|
||||
::forward/register {:id ::yodlee-account-refreshed
|
||||
:events #{::table/refreshed ::table/provider-account-deleted}
|
||||
:event-fn (fn [[_ query-result]]
|
||||
[::data-requested])}
|
||||
:db (dissoc db ::authentication)}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{::forward/dispose {:id ::yodlee-account-refreshed}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::authenticate-with-yodlee
|
||||
(fn [{:keys [db]} [_ client]]
|
||||
{:http {:token (:user db)
|
||||
:method :get
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/fastlink?client=" client)
|
||||
:owns-state {:single ::authenticating}
|
||||
:on-success [::authenticated]
|
||||
:on-error [::save-error]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::authenticated
|
||||
(fn [{:keys [db]} [_ authentication]]
|
||||
{:db (-> db
|
||||
(assoc-in [::authentication] authentication))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ d]]
|
||||
(assoc-in db [::yodlee-provider-accounts] (:yodlee-provider-account-page d))))
|
||||
|
||||
|
||||
(defn yodlee-provider-accounts-table []
|
||||
[table/table {:page @(re-frame/subscribe [::page])
|
||||
:status @(re-frame/subscribe [::status/single ::page])}])
|
||||
|
||||
|
||||
(defn yodlee-link-button []
|
||||
[:div
|
||||
(let [authentication @(re-frame/subscribe [::authentication])
|
||||
status @(re-frame/subscribe [::status/single ::authenticating])
|
||||
client-code (:code @(re-frame/subscribe [::subs/client]))]
|
||||
(cond (and authentication client-code)
|
||||
[:div
|
||||
"Authentication successful!"
|
||||
[:div#fa-spot]
|
||||
[:button.button.is-primary {:on-click (fn []
|
||||
(.open (.-fastlink js/window)
|
||||
#js {"fastLinkURL" (:url authentication)
|
||||
"accessToken" (:token authentication)
|
||||
"params" #js { "configName" "Aggregation"}}
|
||||
|
||||
"fa-spot")
|
||||
)}
|
||||
[:span [:span.icon [:i.fa.fa-external-link]] " Go to yodlee"]]]
|
||||
|
||||
client-code
|
||||
[:button.button.is-primary {:disabled (status/disabled-for status)
|
||||
:class (status/class-for status)
|
||||
:on-click (dispatch-event [::authenticate-with-yodlee client-code])}
|
||||
"Authenticate with Yodlee (" client-code ")"]
|
||||
|
||||
:else
|
||||
nil))])
|
||||
|
||||
(defn admin-yodlee-provider-accounts-content []
|
||||
[:div
|
||||
[:h1.title "Yodlee Provider Accounts"]
|
||||
[yodlee-provider-accounts-table]
|
||||
[yodlee-link-button]])
|
||||
|
||||
|
||||
(defn admin-yodle-provider-accounts-page []
|
||||
(reagent/create-class
|
||||
{:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:reagent-render (fn []
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
:main [admin-yodlee-provider-accounts-content]}])}))
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
(ns auto-ap.views.pages.admin.yodlee2.form
|
||||
(:require
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(def form
|
||||
(r/create-class {
|
||||
:component-did-mount (fn [this]
|
||||
(let [{:keys [authentication provider-account-id]} (r/props this)]
|
||||
(try
|
||||
(println (js/parseInt provider-account-id) (:url authentication) (:token authentication))
|
||||
(.open (.-fastlink js/window)
|
||||
#js {"fastLinkURL" (:url authentication)
|
||||
"accessToken" (:token authentication)
|
||||
"params" #js {"configName" "Aggregation"
|
||||
"providerAccountId" (js/parseInt provider-account-id)
|
||||
"flow" "edit"}}
|
||||
"fa-modal-spot")
|
||||
(catch js/Error e
|
||||
(println e)))))
|
||||
|
||||
:reagent-render (fn [_]
|
||||
[:div#fa-modal-spot])}))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::reauthenticate-start
|
||||
(fn [_ [_ provider-account-id authentication]]
|
||||
{:dispatch [::modal/modal-requested {:title (str "Reauthenticate " provider-account-id)
|
||||
:body [form {:provider-account-id provider-account-id
|
||||
:authentication authentication}]
|
||||
:cancel? false}]}))
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
(ns auto-ap.views.pages.admin.yodlee2.table
|
||||
(:require [auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.pages.admin.yodlee2.form :as form]
|
||||
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.forms :as forms]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::refreshed
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ provider-account ]]
|
||||
;; this is tracked in yodlee main, for refreshing
|
||||
{}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::request-refresh
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ provider-account client-id ]]
|
||||
{:http {:token user
|
||||
:method :post
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/provider-accounts/refresh/")
|
||||
:owns-state {:multi ::refresh
|
||||
:which provider-account}
|
||||
:body {:client-id client-id
|
||||
:provider-account-id provider-account}
|
||||
:on-success [::refreshed provider-account]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::provider-account-deleted
|
||||
(fn [{:keys [db]} [_ i result]]
|
||||
{:dispatch [::modal/modal-closed ]}))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::request-login-form
|
||||
[with-user ]
|
||||
(fn [{:keys [user]} [_ provider-account client-id]]
|
||||
{:http {:token user
|
||||
:method :get
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/fastlink?client-id=" client-id)
|
||||
:owns-state {:multi ::request-login-form
|
||||
:which (:id provider-account)}
|
||||
:on-success [::form/reauthenticate-start provider-account]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-provider-account
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ provider-account-id ]]
|
||||
(comment :on-error [::forms/save-error [::delete-provider-account provider-account-id] ])
|
||||
{:http {:token user
|
||||
:method :post
|
||||
:owns-state {:single ::delete-provider-account}
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/provider-accounts/delete/" )
|
||||
:body {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||
:provider-account-id provider-account-id}
|
||||
:on-success [::provider-account-deleted provider-account-id]
|
||||
}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-requested
|
||||
[with-user]
|
||||
(fn [{:keys [user db]} [_ account-id]]
|
||||
{:dispatch
|
||||
[::modal/modal-requested {:title "Delete Provider account "
|
||||
:body [:div "Are you sure you want to delete provider account " account-id "?"]
|
||||
:confirm {:value "Delete provider account"
|
||||
:status-from [::status/single ::delete-provider-account]
|
||||
:class "is-danger"
|
||||
:on-click (dispatch-event [::delete-provider-account account-id])
|
||||
:close-event [::status/completed ::delete-provider-account]}
|
||||
:cancel? true}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
(fn [{:keys [db]} [_ p]]
|
||||
{:db (assoc db ::params p)}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db ::params)))
|
||||
|
||||
(defn table [{:keys [status page]}]
|
||||
(let [params @(re-frame/subscribe [::params])
|
||||
statuses @(re-frame/subscribe [::status/multi ::refresh])
|
||||
login-statuses @(re-frame/subscribe [::status/multi ::request-login-form])]
|
||||
[grid/grid {:status status
|
||||
:on-params-change (fn [p]
|
||||
(re-frame/dispatch [::params-changed p]))
|
||||
:params params
|
||||
:column-count 4}
|
||||
[grid/controls page]
|
||||
[grid/table {:fullwidth true}
|
||||
[grid/header
|
||||
[grid/row {}
|
||||
[grid/header-cell {:style {:width "18em"}} "Provider Account"]
|
||||
[grid/header-cell {:style {:width "20em"}} "Status"]
|
||||
[grid/header-cell {:style {:width "20em"}} "Detailed Status"]
|
||||
[grid/header-cell {:style {:width "12em"}} "Last Updated"]
|
||||
[grid/header-cell {} "Accounts"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 3)}} ]]]
|
||||
[grid/body
|
||||
(for [{:keys [id name accounts status detailed-status last-updated clients] :as c} (:data page)]
|
||||
^{:key (str name "-" id )}
|
||||
[grid/row {:class (:class c) :id id}
|
||||
[grid/cell {} id]
|
||||
[grid/cell {} status]
|
||||
[grid/cell {} detailed-status]
|
||||
[grid/cell {} (date->str last-updated)]
|
||||
[grid/cell {}
|
||||
[:ul
|
||||
(for [a accounts]
|
||||
^{:key (:id a)}
|
||||
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
|
||||
[grid/cell {}
|
||||
[:div.buttons
|
||||
[buttons/fa-icon {:event
|
||||
[::request-login-form (:id c) (:id (:client c))]
|
||||
:class (status/class-for (get login-statuses (:id c)))
|
||||
:icon "fa-pencil"}]
|
||||
[buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))]
|
||||
:class (status/class-for (get statuses (:id c)))
|
||||
:icon "fa-refresh"}]
|
||||
[buttons/fa-icon {:event [::delete-requested (:id c)]
|
||||
:icon "fa-times"}]]]])]]]))
|
||||
Reference in New Issue
Block a user