Adding reminders view
This commit is contained in:
2
migrator/migrations/1523064177-DOWN-add-reminders.sql
Normal file
2
migrator/migrations/1523064177-DOWN-add-reminders.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- 1523064177 DOWN add-reminders
|
||||||
|
drop table reminders;
|
||||||
8
migrator/migrations/1523064177-UP-add-reminders.sql
Normal file
8
migrator/migrations/1523064177-UP-add-reminders.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- 1523064177 UP add-reminders
|
||||||
|
CREATE TABLE reminders
|
||||||
|
(
|
||||||
|
id serial primary key,
|
||||||
|
vendor_id integer,
|
||||||
|
scheduled date,
|
||||||
|
sent date
|
||||||
|
);
|
||||||
8
src/clj/auto_ap/db/reminders.clj
Normal file
8
src/clj/auto_ap/db/reminders.clj
Normal 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))
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
(ns auto-ap.routes.reminders
|
(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.vendors :as vendors]
|
||||||
|
[auto-ap.db.reminders :as reminders]
|
||||||
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||||
[amazonica.aws.simpleemail :as ses]
|
[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.")}})))
|
: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
|
{:status 200
|
||||||
:body "{}"
|
: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)))
|
||||||
|
|||||||
20
src/cljs/auto_ap/events/admin/reminders.cljs
Normal file
20
src/cljs/auto_ap/events/admin/reminders.cljs
Normal 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)))
|
||||||
|
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"login/" :login
|
"login/" :login
|
||||||
"admin/" {"" :admin
|
"admin/" {"" :admin
|
||||||
"companies" :admin-companies
|
"companies" :admin-companies
|
||||||
|
"reminders" :admin-reminders
|
||||||
"vendors" :admin-vendors}
|
"vendors" :admin-vendors}
|
||||||
"invoices/" {"" :invoices
|
"invoices/" {"" :invoices
|
||||||
"import" :import-invoices
|
"import" :import-invoices
|
||||||
|
|||||||
@@ -24,6 +24,11 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(:user db)))
|
(:user db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::reminders
|
||||||
|
(fn [db]
|
||||||
|
(:reminders db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::vendors
|
::vendors
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
:admin :admin-left-panel
|
:admin :admin-left-panel
|
||||||
:admin-companies :admin-left-panel
|
:admin-companies :admin-left-panel
|
||||||
:admin-vendors :admin-left-panel
|
:admin-vendors :admin-left-panel
|
||||||
|
:admin-reminders :admin-left-panel
|
||||||
:new-invoice :blank} page))
|
:new-invoice :blank} page))
|
||||||
|
|
||||||
(defn login-dropdown []
|
(defn login-dropdown []
|
||||||
@@ -83,7 +84,15 @@
|
|||||||
[:i {:class "fa fa-envelope-o"}]]
|
[:i {:class "fa fa-envelope-o"}]]
|
||||||
[:span {:class "name"} "Users"]]]
|
[: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.left-nav
|
||||||
[:div {:class "compose has-text-centered"}
|
[:div {:class "compose has-text-centered"}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
[auto-ap.views.pages.admin :refer [admin-page]]
|
[auto-ap.views.pages.admin :refer [admin-page]]
|
||||||
[auto-ap.views.pages.admin.companies :refer [admin-companies-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.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.unpaid-invoices :refer [unpaid-invoices-page]]
|
||||||
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
|
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
|
||||||
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
||||||
@@ -38,6 +39,9 @@
|
|||||||
(defmethod active-page :admin-vendors []
|
(defmethod active-page :admin-vendors []
|
||||||
[admin-vendors-page])
|
[admin-vendors-page])
|
||||||
|
|
||||||
|
(defmethod active-page :admin-reminders []
|
||||||
|
[admin-reminders-page])
|
||||||
|
|
||||||
|
|
||||||
(defmethod active-page :unpaid-invoices []
|
(defmethod active-page :unpaid-invoices []
|
||||||
[unpaid-invoices-page])
|
[unpaid-invoices-page])
|
||||||
|
|||||||
39
src/cljs/auto_ap/views/pages/admin/reminders.cljs
Normal file
39
src/cljs/auto_ap/views/pages/admin/reminders.cljs
Normal 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]))})])
|
||||||
Reference in New Issue
Block a user