missing files.
This commit is contained in:
73
src/cljs/auto_ap/views/pages/admin/import_batches.cljs
Normal file
73
src/cljs/auto_ap/views/pages/admin/import_batches.cljs
Normal file
@@ -0,0 +1,73 @@
|
||||
(ns auto-ap.views.pages.admin.import-batches
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.import-batches.table :as table]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.utils :refer [replace-by merge-by]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.effects.forward :as forward]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[clojure.set :as set]
|
||||
[auto-ap.views.components.buttons :as buttons]))
|
||||
|
||||
|
||||
(def default-read [:user-name :date :source :status :id :imported :suppressed :extant])
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single [::data-page/page ::page]}
|
||||
:query-obj {:venia/queries [{:query/data [:import_batch_page
|
||||
{:filters {:sort (:sort params)
|
||||
:start (:start params 0)
|
||||
:per-page (:per-page params)}}
|
||||
[[:data default-read]
|
||||
:total
|
||||
:start
|
||||
:end]]
|
||||
:query/alias :result}]}
|
||||
:on-success (fn [result]
|
||||
[::data-page/received ::page
|
||||
(set/rename-keys (:result result)
|
||||
{:import-batches :data})])}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]}]
|
||||
{::track/register {:id ::params
|
||||
:subscription [::data-page/params ::page]
|
||||
:event-fn (fn [params]
|
||||
[::params-change params])}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]}]
|
||||
{:dispatch [::data-page/dispose ::page]
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
;; VIEWS
|
||||
(def import-batch-content
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [user @(re-frame/subscribe [::subs/user])]
|
||||
[:div
|
||||
[:h1.title "Import Batches"]
|
||||
(when (= "admin" (:user/role user))
|
||||
[table/table {:id :import-batches
|
||||
:data-page ::page}])]))
|
||||
{:component-did-mount (dispatch-event [::mounted ])
|
||||
:component-will-unmount #(re-frame/dispatch-sync [::unmounted])}))
|
||||
|
||||
(defn import-batches-page []
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
:main [import-batch-content]}])
|
||||
|
||||
87
src/cljs/auto_ap/views/pages/admin/import_batches/table.cljs
Normal file
87
src/cljs/auto_ap/views/pages/admin/import_batches/table.cljs
Normal file
@@ -0,0 +1,87 @@
|
||||
(ns auto-ap.views.pages.admin.import-batches.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.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event action-cell-width]]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[bidi.bidi :as bidi]
|
||||
[auto-ap.routes :as routes]
|
||||
[cemerick.url :as url]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::specific-table-params
|
||||
(fn [db]
|
||||
(::table-params db)))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::unmounted
|
||||
(fn [db]
|
||||
(status/reset-multi db ::run)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::table-params
|
||||
:<- [::specific-table-params]
|
||||
:<- [::subs/query-params]
|
||||
(fn [[specific-table-params query-params]]
|
||||
(merge (select-keys query-params #{:start :sort}) specific-table-params )))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)}))
|
||||
|
||||
(defn table* [{:keys [id data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 6}
|
||||
[grid/controls data]
|
||||
[grid/table {:fullwidth true }
|
||||
[grid/header
|
||||
[grid/row {}
|
||||
[grid/sortable-header-cell {:sort-key "date"
|
||||
:sort-name "Date"}
|
||||
"Date"]
|
||||
|
||||
[grid/sortable-header-cell {:sort-key "source"
|
||||
:sort-name "Source"}
|
||||
"Source"]
|
||||
|
||||
[grid/sortable-header-cell {:sort-key "status"
|
||||
:sort-name "Status"}
|
||||
"Status"]
|
||||
|
||||
[grid/sortable-header-cell {:sort-key "user"
|
||||
:sort-name "User"}
|
||||
"User"]
|
||||
[grid/header-cell {:style {:width "7em"}} "Imported"]
|
||||
[grid/header-cell {:style {:width "7em"}} "Preexisting"]
|
||||
[grid/header-cell {:style {:width "7em"}} "Suppressed"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 3)}}]]]
|
||||
[grid/body
|
||||
(for [{:keys [date source status user-name id imported extant suppressed] :as r} (:data data)]
|
||||
^{:key id}
|
||||
[grid/row {:class (:class r) :id id}
|
||||
[grid/cell {} (date->str date)]
|
||||
[grid/cell {} source]
|
||||
[grid/cell {} status]
|
||||
[grid/cell {} user-name]
|
||||
[grid/cell {} imported]
|
||||
[grid/cell {} extant]
|
||||
[grid/cell {} suppressed]
|
||||
[grid/button-cell {}
|
||||
[buttons/fa-icon {:href (str (bidi/path-for routes/routes :transactions)
|
||||
"?"
|
||||
(url/map->query {:import-batch-id id}))
|
||||
:icon "fa-external-link"}]]
|
||||
])]]]))
|
||||
|
||||
(defn table [params]
|
||||
(r/create-class {:component-will-unmount (dispatch-event [::unmounted])
|
||||
:reagent-render (fn [params]
|
||||
[table* params])}))
|
||||
Reference in New Issue
Block a user