Adding reminders view

This commit is contained in:
Bryce Covert
2018-04-06 18:29:48 -07:00
parent 6e573a0a57
commit 982d5ade58
10 changed files with 107 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
-- 1523064177 DOWN add-reminders
drop table reminders;

View File

@@ -0,0 +1,8 @@
-- 1523064177 UP add-reminders
CREATE TABLE reminders
(
id serial primary key,
vendor_id integer,
scheduled date,
sent date
);

View File

@@ -0,0 +1,8 @@
(ns auto-ap.db.reminders
(:require [clojure.java.jdbc :as j]
[auto-ap.parse :as parse]
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
(defn get-all []
(doto (map db->clj (j/query (get-conn) "SELECT reminders.*, vendors.name as vendor_name FROM reminders INNER join vendors on reminders.vendor_id = vendors.id"))
println))

View File

@@ -1,6 +1,8 @@
(ns auto-ap.routes.reminders
(:require [compojure.core :refer [context GET POST defroutes]]
(:require [compojure.core :refer [context GET POST defroutes wrap-routes]]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.reminders :as reminders]
[auto-ap.routes.utils :refer [wrap-secure]]
[amazonica.aws.simpleemail :as ses]
))
@@ -18,4 +20,10 @@
:text (str "Hello " name ",\r\nThis is a reminder to send this week's invoices to us. You can just reply to this email.\r\n - Integreat.")}})))
{:status 200
:body "{}"
:headers {"Content-Type" "application/edn"}})))
:headers {"Content-Type" "application/edn"}})
(wrap-routes (GET "/" {:keys [query-params]}
{:status 200
:body (pr-str (reminders/get-all))
:headers {"Content-Type" "application/edn"}})
wrap-secure)))

View File

@@ -0,0 +1,20 @@
(ns auto-ap.events.admin.reminders
(:require [re-frame.core :as re-frame]
[auto-ap.db :as db]
[auto-ap.routes :as routes]
[auto-ap.effects :as effects]))
(re-frame/reg-event-fx
::mounted
(fn [{:keys [db]} _]
{:http {:method :get
:token (:user db)
:uri "/api/reminders"
:on-success [::received]}}))
(re-frame/reg-event-db
::received
(fn [db [_ reminders]]
(assoc db :reminders reminders)))

View File

@@ -5,6 +5,7 @@
"login/" :login
"admin/" {"" :admin
"companies" :admin-companies
"reminders" :admin-reminders
"vendors" :admin-vendors}
"invoices/" {"" :invoices
"import" :import-invoices

View File

@@ -24,6 +24,11 @@
(fn [db]
(:user db)))
(re-frame/reg-sub
::reminders
(fn [db]
(:reminders db)))
(re-frame/reg-sub
::vendors
(fn [db]

View File

@@ -18,6 +18,7 @@
:admin :admin-left-panel
:admin-companies :admin-left-panel
:admin-vendors :admin-left-panel
:admin-reminders :admin-left-panel
:new-invoice :blank} page))
(defn login-dropdown []
@@ -83,7 +84,15 @@
[:i {:class "fa fa-envelope-o"}]]
[:span {:class "name"} "Users"]]]
[:ul ]]]
[:ul ]]
[:p.menu-label "History"]
[:ul.menu-list
[:li.menu-item
[:a {:href (bidi/path-for routes/routes :admin-reminders) , :class (str "item" (active-when= ap :admin-reminders))}
[:span {:class "icon"}
[:i {:class "fa fa-star-o"}]]
[:span {:class "name"} "Reminders"]]]]]
[:div.left-nav
[:div {:class "compose has-text-centered"}

View File

@@ -9,6 +9,7 @@
[auto-ap.views.pages.admin :refer [admin-page]]
[auto-ap.views.pages.admin.companies :refer [admin-companies-page]]
[auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
[auto-ap.views.pages.admin.reminders :refer [admin-reminders-page]]
[auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
@@ -38,6 +39,9 @@
(defmethod active-page :admin-vendors []
[admin-vendors-page])
(defmethod active-page :admin-reminders []
[admin-reminders-page])
(defmethod active-page :unpaid-invoices []
[unpaid-invoices-page])

View File

@@ -0,0 +1,39 @@
(ns auto-ap.views.pages.admin.reminders
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[auto-ap.subs :as subs]
[auto-ap.events.admin.reminders :as events]
[auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]))
(defn reminders-table []
(let [reminders (or @(re-frame/subscribe [::subs/reminders]) [])]
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th "Vendor"]
[:th "Scheduled Date"]
[:th "Status"]]]
[:tbody (for [{:keys [id vendor-name scheduled sent]} reminders]
^{:key id}
[:tr
[:td vendor-name]
[:td (.toString scheduled)]
[:td (when sent
[:span [:span.icon [:i.fa.fa-check]] "Sent " (.toString sent)]) ]])]]))
(defn admin-reminders-page []
[(with-meta
(fn []
[:div {:class "inbox-messages"}
[:div.hero
[:div.hero-body
[:div.container
[:div
[:h1.title "Reminders"]
[reminders-table]]]]]])
{:component-did-mount (fn []
(re-frame/dispatch [::events/mounted]))})])