actually talks to db
This commit is contained in:
@@ -3,4 +3,5 @@
|
||||
(def default-db
|
||||
{:company {:name "Campbell brewery"}
|
||||
:invoices #{}
|
||||
:unpaid-invoices #{}
|
||||
})
|
||||
|
||||
@@ -19,3 +19,8 @@
|
||||
::imported-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(update-in db [:invoices] into new-invoices)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(update-in db [:unpaid-invoices] into new-invoices)))
|
||||
|
||||
@@ -15,3 +15,8 @@
|
||||
::invoices
|
||||
(fn [db]
|
||||
(:invoices db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::unpaid-invoices
|
||||
(fn [db]
|
||||
(:unpaid-invoices db)))
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
(ns auto-ap.views
|
||||
(: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 :as events]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
[bidi.bidi :as bidi]
|
||||
[cljs-http.client :as http]
|
||||
[cljs.core.async :refer [<!]]))
|
||||
|
||||
(defn active-when= [active-page candidate]
|
||||
(when (= active-page candidate) " active"))
|
||||
@@ -12,22 +17,25 @@
|
||||
(def dropzone
|
||||
(with-meta
|
||||
(fn []
|
||||
[:form {:action "/pdf-upload" :class ".dropzone"}
|
||||
[:div {:class "card"}
|
||||
[:div {:class "card-header"}
|
||||
[:span {:class "card-header-title"} "Upload Invoices"]]
|
||||
[:div {:class "card-content"}
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-cloud-download"}]]
|
||||
"Drop invoice pdfs here"
|
||||
[:input {:type "file", :name "file", :style {:display "none"}}]]]])
|
||||
[:form {:action "/pdf-upload"}
|
||||
[:div.tile.notification
|
||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||
[:span
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-cloud-download"}]]
|
||||
|
||||
"Drop any invoices you want to process here"]]]])
|
||||
{:component-did-mount (fn [this]
|
||||
(js/Dropzone. (reagent/dom-node this)
|
||||
(clj->js {:init (fn []
|
||||
(.on (js-this) "success" (fn [_ files]
|
||||
(re-frame/dispatch [::events/imported-invoices (js->clj (.parse js/JSON files))])
|
||||
)))
|
||||
:url "/pdf-upload"})))}))
|
||||
:paramName "file"
|
||||
:url "/pdf-upload"
|
||||
:previewsContainer "#dz-hidden"
|
||||
:previewTemplate "<div class='dz-hidden-preview'></div>"
|
||||
})))}))
|
||||
|
||||
(defmulti active-page identity)
|
||||
|
||||
@@ -41,16 +49,48 @@
|
||||
[:a {:href (bidi/path-for routes/routes :import-invoices)} "Import some invoices"]]]]]])
|
||||
|
||||
(defmethod active-page :unpaid-invoices []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "Unpaid invoices"]])
|
||||
[(with-meta
|
||||
(fn []
|
||||
(let [invoices (re-frame/subscribe [::subs/unpaid-invoices])]
|
||||
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "Unpaid invoices"]
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Customer"]
|
||||
[:th "Invoice #"]
|
||||
[:th "Date"]
|
||||
[:th "Amount"]]]
|
||||
[:tbody (for [{:strs [customer_identifier invoice_number date total] :as i} @invoices]
|
||||
^{:key (str customer_identifier "-" invoice_number)}
|
||||
[:tr
|
||||
[:td customer_identifier]
|
||||
[:td invoice_number]
|
||||
[:td date]
|
||||
[:td total]])]]]))
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(->> (<! (http/get "/api/invoices"))
|
||||
:body
|
||||
(.parse js/JSON )
|
||||
(js->clj)
|
||||
(conj [::events/received-invoices])
|
||||
(re-frame/dispatch))))})])
|
||||
|
||||
(defmethod active-page :paid-invoices []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "Paid invoices"]])
|
||||
|
||||
(defmethod active-page :invoices []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "All invoices"]])
|
||||
[(with-meta
|
||||
(fn []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "All invoices"]])
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(re-frame/dispatch [::events/received-invoices (<! (http/get "/api/invoices"))]))
|
||||
)})])
|
||||
|
||||
(defmethod active-page :import-invoices []
|
||||
(let [invoices (re-frame/subscribe [::subs/invoices])]
|
||||
@@ -147,50 +187,6 @@
|
||||
[:a {:href "https://github.com/"} "Integreat"]"."]
|
||||
[:p
|
||||
[:a {:class "icon", :href "https://github.com/dansup/bulma-templates"}
|
||||
[:i {:class "fa fa-github"}]]]]]]]))
|
||||
|
||||
|
||||
|
||||
;;
|
||||
;; <nav class="navbar has-shadow">
|
||||
;; <div class="container">
|
||||
;; <div class="navbar-brand">
|
||||
;; <a class="navbar-item" href="../">
|
||||
;; <h1>Auto-ap</h1>
|
||||
;; </a>
|
||||
;;
|
||||
;; <div class="navbar-burger burger" data-target="navMenu">
|
||||
;; <span></span>
|
||||
;; <span></span>
|
||||
;; <span></span>
|
||||
;; </div>
|
||||
;; </div>
|
||||
;;
|
||||
;; <div id="navMenu" class="navbar-menu">
|
||||
;; <div class="navbar-end">
|
||||
;; <div class="navbar-item has-dropdown is-active">
|
||||
;; <a class="navbar-link login">
|
||||
;; Login
|
||||
;; </a>
|
||||
;;
|
||||
;; <div class="navbar-dropdown" style="display:none">
|
||||
;; <a class="navbar-item">
|
||||
;; Dashboard
|
||||
;; </a>
|
||||
;; <a class="navbar-item">
|
||||
;; Profile
|
||||
;; </a>
|
||||
;; <a class="navbar-item">
|
||||
;; Settings
|
||||
;; </a>
|
||||
;; <hr class="navbar-divider">
|
||||
;; <div class="navbar-item">
|
||||
;; Logout
|
||||
;; </div>
|
||||
;; </div>
|
||||
;; </div>
|
||||
;; </div>
|
||||
;; </div>
|
||||
;; </div>
|
||||
;; </nav>
|
||||
[:i {:class "fa fa-github"}]]]]]]
|
||||
[:div#dz-hidden]]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user