From 982d5ade5887478ce532fbd96f258fc886f0e3f0 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 6 Apr 2018 18:29:48 -0700 Subject: [PATCH] Adding reminders view --- .../1523064177-DOWN-add-reminders.sql | 2 + .../1523064177-UP-add-reminders.sql | 8 ++++ src/clj/auto_ap/db/reminders.clj | 8 ++++ src/clj/auto_ap/routes/reminders.clj | 12 +++++- src/cljs/auto_ap/events/admin/reminders.cljs | 20 ++++++++++ src/cljs/auto_ap/routes.cljs | 1 + src/cljs/auto_ap/subs.cljs | 5 +++ src/cljs/auto_ap/views/main.cljs | 11 +++++- src/cljs/auto_ap/views/pages.cljs | 4 ++ .../auto_ap/views/pages/admin/reminders.cljs | 39 +++++++++++++++++++ 10 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 migrator/migrations/1523064177-DOWN-add-reminders.sql create mode 100644 migrator/migrations/1523064177-UP-add-reminders.sql create mode 100644 src/clj/auto_ap/db/reminders.clj create mode 100644 src/cljs/auto_ap/events/admin/reminders.cljs create mode 100644 src/cljs/auto_ap/views/pages/admin/reminders.cljs diff --git a/migrator/migrations/1523064177-DOWN-add-reminders.sql b/migrator/migrations/1523064177-DOWN-add-reminders.sql new file mode 100644 index 00000000..9bc6c87e --- /dev/null +++ b/migrator/migrations/1523064177-DOWN-add-reminders.sql @@ -0,0 +1,2 @@ +-- 1523064177 DOWN add-reminders +drop table reminders; diff --git a/migrator/migrations/1523064177-UP-add-reminders.sql b/migrator/migrations/1523064177-UP-add-reminders.sql new file mode 100644 index 00000000..bda22ced --- /dev/null +++ b/migrator/migrations/1523064177-UP-add-reminders.sql @@ -0,0 +1,8 @@ +-- 1523064177 UP add-reminders +CREATE TABLE reminders + ( + id serial primary key, + vendor_id integer, + scheduled date, + sent date + ); diff --git a/src/clj/auto_ap/db/reminders.clj b/src/clj/auto_ap/db/reminders.clj new file mode 100644 index 00000000..f1d3e04f --- /dev/null +++ b/src/clj/auto_ap/db/reminders.clj @@ -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)) diff --git a/src/clj/auto_ap/routes/reminders.clj b/src/clj/auto_ap/routes/reminders.clj index 365edf80..2f803fce 100644 --- a/src/clj/auto_ap/routes/reminders.clj +++ b/src/clj/auto_ap/routes/reminders.clj @@ -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))) diff --git a/src/cljs/auto_ap/events/admin/reminders.cljs b/src/cljs/auto_ap/events/admin/reminders.cljs new file mode 100644 index 00000000..097f08de --- /dev/null +++ b/src/cljs/auto_ap/events/admin/reminders.cljs @@ -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))) + + diff --git a/src/cljs/auto_ap/routes.cljs b/src/cljs/auto_ap/routes.cljs index 50b73442..5d5962d7 100644 --- a/src/cljs/auto_ap/routes.cljs +++ b/src/cljs/auto_ap/routes.cljs @@ -5,6 +5,7 @@ "login/" :login "admin/" {"" :admin "companies" :admin-companies + "reminders" :admin-reminders "vendors" :admin-vendors} "invoices/" {"" :invoices "import" :import-invoices diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 268628d5..c5bcb869 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -24,6 +24,11 @@ (fn [db] (:user db))) +(re-frame/reg-sub + ::reminders + (fn [db] + (:reminders db))) + (re-frame/reg-sub ::vendors (fn [db] diff --git a/src/cljs/auto_ap/views/main.cljs b/src/cljs/auto_ap/views/main.cljs index 25fe061c..65426cbb 100644 --- a/src/cljs/auto_ap/views/main.cljs +++ b/src/cljs/auto_ap/views/main.cljs @@ -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"} diff --git a/src/cljs/auto_ap/views/pages.cljs b/src/cljs/auto_ap/views/pages.cljs index a2ad8c66..ed56d056 100644 --- a/src/cljs/auto_ap/views/pages.cljs +++ b/src/cljs/auto_ap/views/pages.cljs @@ -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]) diff --git a/src/cljs/auto_ap/views/pages/admin/reminders.cljs b/src/cljs/auto_ap/views/pages/admin/reminders.cljs new file mode 100644 index 00000000..48ec386c --- /dev/null +++ b/src/cljs/auto_ap/views/pages/admin/reminders.cljs @@ -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]))})])