Synchronizes selected company on 1099 page to everything else.
This commit is contained in:
6
src/clj/auto_ap/ssr/auth.clj
Normal file
6
src/clj/auto_ap/ssr/auth.clj
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
(ns auto-ap.ssr.auth)
|
||||||
|
|
||||||
|
(defn logout [request]
|
||||||
|
{:status 301
|
||||||
|
:headers {"Location" "/login"}
|
||||||
|
:session {}})
|
||||||
@@ -87,7 +87,6 @@
|
|||||||
[?p :payment/vendor ?v]]
|
[?p :payment/vendor ?v]]
|
||||||
(d/db conn))
|
(d/db conn))
|
||||||
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(d/q '[:find
|
(d/q '[:find
|
||||||
(pull ?c [:client/code :db/id])
|
(pull ?c [:client/code :db/id])
|
||||||
|
|||||||
@@ -71,29 +71,23 @@ z.input.addEventListener(\"selection\", function (event) {
|
|||||||
z.input.value = event.detail.selection.value.value;
|
z.input.value = event.detail.selection.value.value;
|
||||||
document.getElementById(\"company-search-value\").value= event.detail.selection.value.key;
|
document.getElementById(\"company-search-value\").value= event.detail.selection.value.key;
|
||||||
document.getElementById(\"company-search-value\").dispatchEvent(new Event('change'));
|
document.getElementById(\"company-search-value\").dispatchEvent(new Event('change'));
|
||||||
|
|
||||||
});
|
});
|
||||||
"))]])))
|
"))]])))
|
||||||
|
|
||||||
#_{:hx-get
|
|
||||||
(bidi/path-for ssr-routes/only-routes
|
|
||||||
:company-dropdown-contents)
|
|
||||||
:hx-target "#company-dropdown .navbar-dropdown"
|
|
||||||
:hx-swap "outerHTML"
|
|
||||||
"_" (hiccup/raw
|
|
||||||
"on click
|
|
||||||
toggle .is-active on <#company-dropdown />
|
|
||||||
end
|
|
||||||
")
|
|
||||||
}
|
|
||||||
(defn dropdown [request]
|
(defn dropdown [request]
|
||||||
|
|
||||||
(let [client (get-in request [:session :client])]
|
(let [client (get-in request [:session :client])]
|
||||||
|
|
||||||
(navbar-dropdown
|
(navbar-dropdown
|
||||||
"company-dropdown"
|
"company-dropdown"
|
||||||
(if client
|
[:span
|
||||||
(str "Company: " (:client/name client))
|
(if client
|
||||||
"Company")
|
(str "Company: " (:client/name client))
|
||||||
|
"Company")
|
||||||
|
[:script
|
||||||
|
(hiccup/raw
|
||||||
|
"localStorage.setItem(\"last-client-id\", \""(:db/id client)"\")")]]
|
||||||
[:div {:hx-get
|
[:div {:hx-get
|
||||||
(bidi/path-for ssr-routes/only-routes
|
(bidi/path-for ssr-routes/only-routes
|
||||||
:company-dropdown-contents)
|
:company-dropdown-contents)
|
||||||
@@ -103,17 +97,7 @@ document.getElementById(\"company-search-value\").dispatchEvent(new Event('chang
|
|||||||
:style {:width "20em"
|
:style {:width "20em"
|
||||||
:height "80px"}
|
:height "80px"}
|
||||||
}
|
}
|
||||||
[:div.loader.is-loading.is-active.is-centered]]
|
[:div.loader.is-loading.is-active.is-centered]])))
|
||||||
)
|
|
||||||
#_[:div#company-dropdown.navbar-item.has-dropdown
|
|
||||||
{"_" (hiccup/raw
|
|
||||||
"on click elsewhere
|
|
||||||
remove .is-active from <#company-dropdown />
|
|
||||||
end "
|
|
||||||
)} ;; remove .is-active from <#company-dropdown />
|
|
||||||
|
|
||||||
[:div.navbar-dropdown]
|
|
||||||
]))
|
|
||||||
|
|
||||||
(defn active-client [{:keys [identity params] :as request}]
|
(defn active-client [{:keys [identity params] :as request}]
|
||||||
(clojure.pprint/pprint params)
|
(clojure.pprint/pprint params)
|
||||||
|
|||||||
@@ -3,17 +3,21 @@
|
|||||||
[auto-ap.routes.utils
|
[auto-ap.routes.utils
|
||||||
:refer [wrap-admin wrap-client-redirect-unauthenticated wrap-secure]]
|
:refer [wrap-admin wrap-client-redirect-unauthenticated wrap-secure]]
|
||||||
[auto-ap.ssr.admin :as admin]
|
[auto-ap.ssr.admin :as admin]
|
||||||
|
[auto-ap.ssr.auth :as auth]
|
||||||
[auto-ap.ssr.company.company-1099 :as company-1099]
|
[auto-ap.ssr.company.company-1099 :as company-1099]
|
||||||
[auto-ap.ssr.company-dropdown :as company-dropdown]))
|
[auto-ap.ssr.company-dropdown :as company-dropdown]))
|
||||||
|
|
||||||
;; from auto-ap.ssr-routes, because they're shared
|
;; from auto-ap.ssr-routes, because they're shared
|
||||||
(def key->handler {:admin-history (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history)))
|
|
||||||
:admin-history-search (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history-search)))
|
|
||||||
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))
|
(def key->handler {:logout auth/logout
|
||||||
:active-client (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin company-dropdown/active-client)))
|
:admin-history (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history)))
|
||||||
:company-dropdown-contents (wrap-client-redirect-unauthenticated (wrap-secure company-dropdown/dropdown-contents))
|
:admin-history-search (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history-search)))
|
||||||
:company-1099 (wrap-client-redirect-unauthenticated (wrap-secure company-1099/page))
|
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))
|
||||||
:company-1099-vendor-table (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-table))
|
:active-client (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin company-dropdown/active-client)))
|
||||||
:company-1099-vendor-dialog (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-dialog))
|
:company-dropdown-contents (wrap-client-redirect-unauthenticated (wrap-secure company-dropdown/dropdown-contents))
|
||||||
:company-1099-vendor-save (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-save))})
|
:company-1099 (wrap-client-redirect-unauthenticated (wrap-secure company-1099/page))
|
||||||
|
:company-1099-vendor-table (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-table))
|
||||||
|
:company-1099-vendor-dialog (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-dialog))
|
||||||
|
:company-1099-vendor-save (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-save))})
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
(:require
|
(:require
|
||||||
[auto-ap.client-routes :as client-routes]
|
[auto-ap.client-routes :as client-routes]
|
||||||
[auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
|
[auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]
|
||||||
|
[hiccup2.core :as hiccup]
|
||||||
|
[auto-ap.ssr-routes :as ssr-routes]))
|
||||||
|
|
||||||
(defn dropdown [{:keys [identity]}]
|
(defn dropdown [{:keys [identity]}]
|
||||||
(if identity
|
(if identity
|
||||||
@@ -17,6 +19,8 @@
|
|||||||
#_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/edit {}])} "Edit Vendor"]
|
#_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/edit {}])} "Edit Vendor"]
|
||||||
(when (= "admin" (:user/role identity))
|
(when (= "admin" (:user/role identity))
|
||||||
[:a {:class "navbar-item" :href (bidi/path-for client-routes/routes :admin)} "Administration"])
|
[:a {:class "navbar-item" :href (bidi/path-for client-routes/routes :admin)} "Administration"])
|
||||||
#_[:hr {:class "navbar-divider"}]
|
[:hr {:class "navbar-divider"}]
|
||||||
#_[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [:events/logout]))} "Logout"]])
|
[:a.navbar-item {"_" (hiccup/raw "on click call localStorage.removeItem(\"jwt\")")
|
||||||
|
:href (bidi/path-for ssr-routes/only-routes :logout)}
|
||||||
|
"Logout"]])
|
||||||
[:a.navbar-item {:href (bidi/path-for client-routes/routes :login )} "Login"]))
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :login )} "Login"]))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
(ns auto-ap.ssr.ui
|
(ns auto-ap.ssr.ui
|
||||||
(:require
|
(:require
|
||||||
[auto-ap.logging :as alog]
|
[auto-ap.client-routes :as client-routes]
|
||||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||||
[config.core :refer [env]]
|
[auto-ap.ssr.login-dropdown :as login-dropdown]
|
||||||
[hiccup2.core :as hiccup]
|
[bidi.bidi :as bidi]
|
||||||
[auto-ap.ssr.login-dropdown :as login-dropdown]))
|
[hiccup2.core :as hiccup]))
|
||||||
|
|
||||||
(defn html-page [hiccup]
|
(defn html-page [hiccup]
|
||||||
{:status 200
|
{:status 200
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
{}
|
{}
|
||||||
hiccup))})
|
hiccup))})
|
||||||
|
|
||||||
|
|
||||||
(defn base-page [request contents side-bar-contents]
|
(defn base-page [request contents side-bar-contents]
|
||||||
(html-page
|
(html-page
|
||||||
[:html.has-navbar-fixed-top
|
[:html.has-navbar-fixed-top
|
||||||
@@ -54,15 +53,15 @@
|
|||||||
[:div.navbar-start
|
[:div.navbar-start
|
||||||
[:a.navbar-item {:href "/"}
|
[:a.navbar-item {:href "/"}
|
||||||
"Home" ]
|
"Home" ]
|
||||||
[:a.navbar-item {:href "/invoices"}
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :unpaid-invoices)}
|
||||||
"Invoices" ]
|
"Invoices" ]
|
||||||
[:a.navbar-item {:href "/payments"}
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :payments)}
|
||||||
"Payments" ]
|
"Payments" ]
|
||||||
[:a.navbar-item {:href "/pos/sales-orders"}
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :sales-orders)}
|
||||||
"POS" ]
|
"POS" ]
|
||||||
[:a.navbar-item {:href "/transactions"}
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :transactions)}
|
||||||
"Transactions" ]
|
"Transactions" ]
|
||||||
[:a.navbar-item {:href "/ledger"}
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :ledger)}
|
||||||
"Ledger" ]]
|
"Ledger" ]]
|
||||||
[:div.navbar-end
|
[:div.navbar-end
|
||||||
(company-dropdown/dropdown request)
|
(company-dropdown/dropdown request)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
(ns auto-ap.ssr-routes)
|
(ns auto-ap.ssr-routes)
|
||||||
|
|
||||||
(def routes {"admin" {"/history" {"" :admin-history
|
(def routes {"logout" :logout
|
||||||
|
"admin" {"/history" {"" :admin-history
|
||||||
"/" :admin-history
|
"/" :admin-history
|
||||||
#"/search/?" :admin-history-search
|
#"/search/?" :admin-history-search
|
||||||
["/" [#"\d+" :entity-id] #"/?"] :admin-history-search
|
["/" [#"\d+" :entity-id] #"/?"] :admin-history-search
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[goog.crypt.base64 :as b64]
|
[goog.crypt.base64 :as b64]
|
||||||
[re-frame.core :as re-frame]))
|
[re-frame.core :as re-frame]
|
||||||
|
[auto-ap.ssr-routes :as ssr-routes]
|
||||||
|
[cemerick.url :as url]))
|
||||||
|
|
||||||
(defn jwt->data [token]
|
(defn jwt->data [token]
|
||||||
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
||||||
@@ -114,11 +116,19 @@
|
|||||||
:is-initial-loading? false
|
:is-initial-loading? false
|
||||||
:active-route :initial-error)))
|
:active-route :initial-error)))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::swap-client
|
::swap-client
|
||||||
(fn [db [_ client]]
|
[with-user]
|
||||||
|
(fn [{:keys [db user]} [_ client]]
|
||||||
(.setItem js/localStorage "last-client-id" (:id client))
|
(.setItem js/localStorage "last-client-id" (:id client))
|
||||||
(assoc db :client (:id client))))
|
{:db (assoc db :client (:id client))
|
||||||
|
:http {:token user
|
||||||
|
:method :put
|
||||||
|
:uri (str (bidi/path-for ssr-routes/only-routes
|
||||||
|
:active-client
|
||||||
|
:request-method :put)
|
||||||
|
"?"
|
||||||
|
(url/map->query {:search-client (:id client)}))}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::set-active-route
|
::set-active-route
|
||||||
|
|||||||
Reference in New Issue
Block a user